Debian Codegraph @

skins/Vector/tests/phpunit/unit/FeatureManagement/Requirements/DynamicConfigRequirementTest.php

raw symbols SCIP
1 <?php
2
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 *
19 * @file
20 * @since 1.35
21 */
22
23 namespace MediaWiki\Skins\Vector\Tests\Unit\FeatureManagement\Requirements;
24
25 use MediaWiki\Config\HashConfig;
26 use MediaWiki\Skins\Vector\FeatureManagement\Requirements\DynamicConfigRequirement;
27
28 /**
29 * @group Vector
30 * @group FeatureManagement
31 * @coversDefaultClass \MediaWiki\Skins\Vector\FeatureManagement\Requirements\DynamicConfigRequirement
32 */
33 class DynamicConfigRequirementTest extends \MediaWikiUnitTestCase {
34
35 public static function providesBooleanStates(): array {
36 return [ [ false ], [ true ] ];
37 }
38
39 /**
40 * @dataProvider providesBooleanStates
41 * @covers ::isMet
42 */
43 public function testItFetchesAndReturnsConfigValue( bool $configValue ) {
44 $config = new HashConfig( [
45 'Foo' => $configValue,
46 ] );
47
48 $requirement = new DynamicConfigRequirement( $config, 'Foo', 'Bar' );
49
50 $this->assertEquals( $requirement->isMet(), $configValue );
51 }
52
53 /**
54 * @covers ::isMet
55 */
56 public function testItCastsConfigValue() {
57 $config = new HashConfig( [
58 'Foo' => new \stdClass(),
59 ] );
60
61 $requirement = new DynamicConfigRequirement( $config, 'Foo', 'Bar' );
62
63 $this->assertTrue( $requirement->isMet() );
64 }
65
66 /**
67 * @covers ::getName
68 */
69 public function testItReturnsName() {
70 $requirement = new DynamicConfigRequirement(
71 new HashConfig(),
72 'Foo',
73 'Bar'
74 );
75
76 $this->assertEquals( 'Bar', $requirement->getName() );
77 }
78 }