‪TYPO3CMS  11.5
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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪PublicPropertyDeprecationTraitTest extends UnitTestCase
27 {
32  protected ‪$fixture;
33 
40  protected function ‪setUp(): void
41  {
42  parent::setUp();
43  $this->fixture = new class () {
45  private $deprecatedPublicProperties = [
46  'taggedProperty' => 'taggedProperty is deprecated',
47  'unsetTaggedProperty' => 'unsetTaggedProperty is deprecated',
48  ];
49 
50  public $publicProperty = 'publicProperty';
51 
52  public $unsetPublicProperty;
53 
57  protected $taggedProperty = 'taggedProperty';
58 
62  protected $unsetTaggedProperty;
63 
64  protected $untaggedProperty = 'untaggedProperty';
65  };
66  }
67 
71  public function ‪issetDataProvider(): array
72  {
73  return [
74  'public property' => [true, 'publicProperty'],
75  'unset public property' => [false, 'unsetPublicProperty'],
76  'tagged property' => [true, 'taggedProperty'],
77  'unset tagged property' => [false, 'unsetTaggedProperty'],
78  'untagged property' => [false, 'untaggedProperty'],
79  'unknown property' => [false, 'unknownProperty'],
80  ];
81  }
82 
89  public function ‪issetWorksAsExpected(bool $expected, string $property): void
90  {
91  self::assertSame($expected, isset($this->fixture->$property));
92  }
93 
97  public function ‪unknownPropertyCanBeHandledAsUsual(): void
98  {
99  // Uses __isset()
100  self::assertFalse(isset($this->fixture->unknownProperty));
101  // Uses __set()
102  $this->fixture->unknownProperty = 23;
103  // Don't uses __isset()
104  self::assertTrue(isset($this->fixture->unknownProperty));
105  // Don't uses __get()
106  self::assertSame(23, $this->fixture->unknownProperty);
107  // Don't uses __unset()
108  unset($this->fixture->unknownProperty);
109  // Uses __isset()
110  self::assertFalse(isset($this->fixture->unknownProperty));
111  }
112 
116  public function ‪publicPropertyCanBeHandledAsUsual(): void
117  {
118  self::assertFalse(isset($this->fixture->unsetPublicProperty));
119  $this->fixture->unsetPublicProperty = 23;
120  self::assertTrue(isset($this->fixture->unsetPublicProperty));
121  self::assertSame(23, $this->fixture->unsetPublicProperty);
122  unset($this->fixture->unsetPublicProperty);
123  self::assertFalse(isset($this->fixture->unsetPublicProperty));
124  }
125 
130  {
131  self::assertFalse(isset($this->fixture->unsetTaggedProperty));
132  $this->fixture->unsetTaggedProperty = 23;
133  self::assertTrue(isset($this->fixture->unsetTaggedProperty));
134  self::assertSame(23, $this->fixture->unsetTaggedProperty);
135  unset($this->fixture->unsetTaggedProperty);
136  self::assertFalse(isset($this->fixture->unsetTaggedProperty));
137  }
138 
142  public function ‪invalidPropertiesDataProvider(): array
143  {
144  return [
145  'untagged' => ['untaggedProperty'],
146  'unknown' => ['unknownProperty'],
147  ];
148  }
149 }
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\issetDataProvider
‪array issetDataProvider()
Definition: PublicPropertyDeprecationTraitTest.php:69
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\unknownPropertyCanBeHandledAsUsual
‪unknownPropertyCanBeHandledAsUsual()
Definition: PublicPropertyDeprecationTraitTest.php:95
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\invalidPropertiesDataProvider
‪array invalidPropertiesDataProvider()
Definition: PublicPropertyDeprecationTraitTest.php:140
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\publicPropertyCanBeHandledAsUsual
‪publicPropertyCanBeHandledAsUsual()
Definition: PublicPropertyDeprecationTraitTest.php:114
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest
Definition: PublicPropertyDeprecationTraitTest.php:27
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\$fixture
‪object $fixture
Definition: PublicPropertyDeprecationTraitTest.php:31
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\setUp
‪setUp()
Definition: PublicPropertyDeprecationTraitTest.php:39
‪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:87
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Compatibility\PublicPropertyDeprecationTraitTest\taggedPropertyCanBeHandledLikePublicProperty
‪taggedPropertyCanBeHandledLikePublicProperty()
Definition: PublicPropertyDeprecationTraitTest.php:127