‪TYPO3CMS  10.4
ObjectAccessTest.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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪ObjectAccessTest extends UnitTestCase
29 {
33  protected ‪$resetSingletonInstances = true;
34 
38  protected ‪$dummyObject;
39 
43  protected function ‪setUp(): void
44  {
45  parent::setUp();
46  $this->dummyObject = new ‪DummyClassWithGettersAndSetters();
47  $this->dummyObject->setProperty('string1');
48  $this->dummyObject->setAnotherProperty(42);
49  $this->dummyObject->shouldNotBePickedUp = true;
50  }
51 
56  {
57  $property = ‪ObjectAccess::getProperty($this->dummyObject, 'unexposedProperty', true);
58  self::assertEquals($property, 'unexposed', 'A property of a given object was not returned correctly.');
59  }
60 
65  {
66  $this->dummyObject->unknownProperty = 'unknown';
67  $property = ‪ObjectAccess::getProperty($this->dummyObject, 'unknownProperty', true);
68  self::assertEquals($property, 'unknown', 'A property of a given object was not returned correctly.');
69  }
70 
75  {
76  $this->expectException(PropertyNotAccessibleException::class);
77  $this->expectExceptionCode(1302855001);
78  ‪ObjectAccess::getProperty($this->dummyObject, 'notExistingProperty', true);
79  }
80 }
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ObjectAccessTest\setUp
‪setUp()
Definition: ObjectAccessTest.php:41
‪TYPO3\CMS\Extbase\Reflection\Exception\PropertyNotAccessibleException
Definition: PropertyNotAccessibleException.php:26
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ObjectAccessTest\$dummyObject
‪DummyClassWithGettersAndSetters $dummyObject
Definition: ObjectAccessTest.php:36
‪TYPO3\CMS\Extbase\Tests\Unit\Reflection\Fixture\DummyClassWithGettersAndSetters
Definition: DummyClassWithGettersAndSetters.php:22
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess
Definition: ObjectAccess.php:38
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ObjectAccessTest\getPropertyReturnsExpectedValueForUnknownPropertyIfForceDirectAccessIsTrue
‪getPropertyReturnsExpectedValueForUnknownPropertyIfForceDirectAccessIsTrue()
Definition: ObjectAccessTest.php:62
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ObjectAccessTest
Definition: ObjectAccessTest.php:29
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ObjectAccessTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: ObjectAccessTest.php:32
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ObjectAccessTest\getPropertyReturnsExpectedValueForUnexposedPropertyIfForceDirectAccessIsTrue
‪getPropertyReturnsExpectedValueForUnexposedPropertyIfForceDirectAccessIsTrue()
Definition: ObjectAccessTest.php:53
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection
Definition: ObjectAccessTest.php:18
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess\getProperty
‪static mixed getProperty($subject, string $propertyName, bool $forceDirectAccess=false)
Definition: ObjectAccess.php:62
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ObjectAccessTest\getPropertyThrowsPropertyNotAccessibleExceptionForNotExistingPropertyIfForceDirectAccessIsTrue
‪getPropertyThrowsPropertyNotAccessibleExceptionForNotExistingPropertyIfForceDirectAccessIsTrue()
Definition: ObjectAccessTest.php:72