‪TYPO3CMS  ‪main
PublicPropertyDeprecationTraitTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪PublicPropertyDeprecationTraitTest extends UnitTestCase
26 {
31  protected ‪$fixture;
32 
39  protected function ‪setUp(): void
40  {
41  parent::setUp();
42  $this->fixture = new class () {
44  private $deprecatedPublicProperties = [
45  'taggedProperty' => 'taggedProperty is deprecated',
46  'unsetTaggedProperty' => 'unsetTaggedProperty is deprecated',
47  ];
48 
49  public $publicProperty = 'publicProperty';
50 
51  public $unsetPublicProperty;
52 
56  protected $taggedProperty = 'taggedProperty';
57 
61  protected $unsetTaggedProperty;
62 
63  protected $untaggedProperty = 'untaggedProperty';
64  };
65  }
66 
70  public static function ‪issetDataProvider(): array
71  {
72  return [
73  'public property' => [true, 'publicProperty'],
74  'unset public property' => [false, 'unsetPublicProperty'],
75  'tagged property' => [true, 'taggedProperty'],
76  'unset tagged property' => [false, 'unsetTaggedProperty'],
77  'untagged property' => [false, 'untaggedProperty'],
78  'unknown property' => [false, 'unknownProperty'],
79  ];
80  }
81 
82  #[DataProvider('issetDataProvider')]
83  #[Test]
84  public function ‪issetWorksAsExpected(bool $expected, string $property): void
85  {
86  self::assertSame($expected, isset($this->fixture->$property));
87  }
88 
89  #[Test]
90  public function ‪unknownPropertyCanBeHandledAsUsual(): void
91  {
92  // Uses __isset()
93  self::assertFalse(isset($this->fixture->unknownProperty));
94  // Uses __set()
95  $this->fixture->unknownProperty = 23;
96  // Don't uses __isset()
97  self::assertTrue(isset($this->fixture->unknownProperty));
98  // Don't uses __get()
99  self::assertSame(23, $this->fixture->unknownProperty);
100  // Don't uses __unset()
101  unset($this->fixture->unknownProperty);
102  // Uses __isset()
103  self::assertFalse(isset($this->fixture->unknownProperty));
104  }
105 
106  #[Test]
107  public function ‪publicPropertyCanBeHandledAsUsual(): void
108  {
109  self::assertFalse(isset($this->fixture->unsetPublicProperty));
110  $this->fixture->unsetPublicProperty = 23;
111  self::assertTrue(isset($this->fixture->unsetPublicProperty));
112  self::assertSame(23, $this->fixture->unsetPublicProperty);
113  unset($this->fixture->unsetPublicProperty);
114  self::assertFalse(isset($this->fixture->unsetPublicProperty));
115  }
116 
117  #[Test]
119  {
120  self::assertFalse(isset($this->fixture->unsetTaggedProperty));
121  $this->fixture->unsetTaggedProperty = 23;
122  self::assertTrue(isset($this->fixture->unsetTaggedProperty));
123  self::assertSame(23, $this->fixture->unsetTaggedProperty);
124  unset($this->fixture->unsetTaggedProperty);
125  self::assertFalse(isset($this->fixture->unsetTaggedProperty));
126  }
127 
131  public function ‪invalidPropertiesDataProvider(): array
132  {
133  return [
134  'untagged' => ['untaggedProperty'],
135  'unknown' => ['unknownProperty'],
136  ];
137  }
138 }
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\unknownPropertyCanBeHandledAsUsual
‪unknownPropertyCanBeHandledAsUsual()
Definition: PublicPropertyDeprecationTraitTest.php:88
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\invalidPropertiesDataProvider
‪array invalidPropertiesDataProvider()
Definition: PublicPropertyDeprecationTraitTest.php:129
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\issetDataProvider
‪static array issetDataProvider()
Definition: PublicPropertyDeprecationTraitTest.php:68
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\publicPropertyCanBeHandledAsUsual
‪publicPropertyCanBeHandledAsUsual()
Definition: PublicPropertyDeprecationTraitTest.php:105
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest
Definition: PublicPropertyDeprecationTraitTest.php:26
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\$fixture
‪object $fixture
Definition: PublicPropertyDeprecationTraitTest.php:30
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\setUp
‪setUp()
Definition: PublicPropertyDeprecationTraitTest.php:38
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility
‪TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait
Definition: PublicPropertyDeprecationTrait.php:67
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\issetWorksAsExpected
‪issetWorksAsExpected(bool $expected, string $property)
Definition: PublicPropertyDeprecationTraitTest.php:82
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\taggedPropertyCanBeHandledLikePublicProperty
‪taggedPropertyCanBeHandledLikePublicProperty()
Definition: PublicPropertyDeprecationTraitTest.php:116