Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.31% covered (success)
92.31%
12 / 13
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
MockEnv
92.31% covered (success)
92.31%
12 / 13
50.00% covered (danger)
50.00%
1 / 2
4.01
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
3
 bumpParserResourceUse
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace Wikimedia\Parsoid\Mocks;
5
6use Wikimedia\Parsoid\Config\Env;
7use Wikimedia\Parsoid\Config\PageContent;
8use Wikimedia\Parsoid\Config\StubMetadataCollector;
9use Wikimedia\Parsoid\Utils\Title;
10
11class MockEnv extends Env {
12    /**
13     * @param array $opts
14     *  - log: (bool) Whether the logger should log. Default false.
15     *  - wrapSections: (bool) Whether to wrap sections. Default false.
16     *  - pageConfig: (PageConfig) If given, supplies a custom PageConfig instance to use.
17     *  - siteConfig: (SiteConfig) If given, supplies a custom SiteConfig instance to use.
18     *  - dataAccess: (DataAccess) If given, supplies a custom DataAccess instance to use.
19     *  - pageContent: (PageContent|string) If given and 'pageConfig' is not, this is passed to the
20     *    MockPageConfig.
21     */
22    public function __construct( array $opts ) {
23        $siteConfig = $opts['siteConfig'] ?? new MockSiteConfig( $opts );
24        if ( isset( $opts['pageConfig'] ) ) {
25            $pageConfig = $opts['pageConfig'];
26        } else {
27            $content = $opts['pageContent'] ?? 'Some dummy source wikitext for testing.';
28            $title = Title::newFromText( $opts['title'] ?? 'TestPage', $siteConfig, $opts['pagens'] ?? null );
29            $pageContent = $content instanceof PageContent
30                ? $content
31                : new MockPageContent( [ 'main' => $content ], $title );
32            $pageConfig = new MockPageConfig( $siteConfig, $opts, $pageContent );
33        }
34        $dataAccess = $opts['dataAccess'] ?? new MockDataAccess( $siteConfig, $opts );
35        $metadata = new StubMetadataCollector( $siteConfig );
36        parent::__construct( $siteConfig, $pageConfig, $dataAccess, $metadata, $opts );
37    }
38
39    /**
40     * @suppress PhanEmptyPublicMethod
41     * @param string $resource
42     * @param int $count
43     */
44    public function bumpParserResourceUse( string $resource, int $count = 1 ): void {
45    }
46}