Debian Codegraph @

tests/phpunit/unit/includes/debug/DeprecatablePropertyArrayTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Debug\DeprecatablePropertyArray;
4
5 /**
6 * @covers \MediaWiki\Debug\DeprecatablePropertyArray
7 */
8 class DeprecatablePropertyArrayTest extends MediaWikiUnitTestCase {
9
10 private const PROP_NAME = 'test_property';
11
12 /**
13 * @dataProvider provideDeprecationWarning
14 */
15 public function testDeprecationWarning( callable $callback, string $message ) {
16 $this->expectDeprecationAndContinue( '/' . preg_quote( $message, '/' ) . '/' );
17 $callback();
18 }
19
20 public function provideDeprecationWarning() {
21 $propName = self::PROP_NAME;
22 $array = new DeprecatablePropertyArray(
23 [
24 self::PROP_NAME => 'test_value',
25 'callback' => static function () {
26 return 'callback_test_value';
27 },
28 ],
29 [
30 self::PROP_NAME => 'DEPRECATED_VERSION',
31 'callback' => 'DEPRECATED_VERSION',
32 ],
33 'TEST'
34 );
35
36 yield 'get' => [
37 function () use ( $array ) {
38 $this->assertSame( 'test_value', $array[ self::PROP_NAME ] );
39 },
40 "TEST get '{$propName}'"
41 ];
42 yield 'get, callback' => [
43 function () use ( $array ) {
44 $this->assertSame( 'callback_test_value', $array[ 'callback' ] );
45 },
46 "TEST get 'callback'"
47 ];
48 yield 'exists' => [
49 function () use ( $array ) {
50 $this->assertTrue( isset( $array[ self::PROP_NAME ] ) );
51 },
52 "TEST exists '{$propName}'"
53 ];
54 yield 'unset' => [
55 static function () use ( $array ) {
56 unset( $array[ self::PROP_NAME ] );
57 },
58 "TEST unset '{$propName}'"
59 ];
60 }
61
62 public function testNonDeprecated() {
63 $array = new DeprecatablePropertyArray( [], [], __METHOD__ );
64 $this->assertFalse( isset( $array[self::PROP_NAME] ) );
65 $array[self::PROP_NAME] = 'test_value';
66 $this->assertTrue( isset( $array[self::PROP_NAME] ) );
67 $this->assertSame( 'test_value', $array[self::PROP_NAME] );
68 unset( $array[self::PROP_NAME] );
69 $this->assertFalse( isset( $array[self::PROP_NAME] ) );
70 }
71
72 public function testNonDeprecatedNumerical() {
73 $array = new DeprecatablePropertyArray( [], [], __METHOD__ );
74 $this->assertFalse( isset( $array[0] ) );
75 $array[] = 'test_value';
76 $this->assertTrue( isset( $array[0] ) );
77 $this->assertSame( 'test_value', $array[0] );
78 unset( $array[0] );
79 $this->assertFalse( isset( $array[0] ) );
80 }
81 }