Debian Codegraph @

vendor/wikimedia/parsoid/src/Mocks/MockEnv.php

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