nelson6e65 /
php_nml
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * PHP: Nelson Martell Library file |
||
| 5 | * |
||
| 6 | * Copyright © 2016-2021 Nelson Martell (http://nelson6e65.github.io) |
||
| 7 | * |
||
| 8 | * Licensed under The MIT License (MIT) |
||
| 9 | * For full copyright and license information, please see the LICENSE |
||
| 10 | * Redistributions of files must retain the above copyright notice. |
||
| 11 | * |
||
| 12 | * @copyright 2016-2021 Nelson Martell |
||
| 13 | * @link http://nelson6e65.github.io/php_nml/ |
||
| 14 | * @since v0.6.0, v0.7.0 |
||
| 15 | * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) |
||
| 16 | * */ |
||
| 17 | |||
| 18 | declare(strict_types=1); |
||
| 19 | |||
| 20 | namespace NelsonMartell\Test\Helpers; |
||
| 21 | |||
| 22 | use ReflectionClass; |
||
| 23 | use BadMethodCallException; |
||
| 24 | use NelsonMartell\Extensions\Text; |
||
| 25 | use NelsonMartell\IStrictPropertiesContainer; |
||
| 26 | use PHPUnit\Framework\TestCase; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Test helper for classes implementing ``NelsonMartell\IStrictPropertiesContainer`` interface and |
||
| 30 | * ``NelsonMartell\PropertiesHandler`` trait. |
||
| 31 | * |
||
| 32 | * |
||
| 33 | * @author Nelson Martell <[email protected]> |
||
| 34 | * |
||
| 35 | * @see HasReadOnlyProperties |
||
| 36 | * @see HasReadWriteProperties |
||
| 37 | * @see HasUnaccesibleProperties |
||
| 38 | * @see HasWriteOnlyProperties |
||
| 39 | * */ |
||
| 40 | trait ImplementsIStrictPropertiesContainer |
||
| 41 | { |
||
| 42 | /** |
||
| 43 | * @return string |
||
| 44 | */ |
||
| 45 | abstract public function getTargetClassName(): string; |
||
| 46 | |||
| 47 | abstract public function objectInstanceProvider(): array; |
||
| 48 | |||
| 49 | public function testImplementsIStrictPropertiesContainerInterface(): void |
||
| 50 | { |
||
| 51 | $className = $this->getTargetClassName(); |
||
| 52 | $class = new ReflectionClass($className); |
||
| 53 | |||
| 54 | /** @var TestCase $this */ |
||
| 55 | if ($class->isTrait()) { |
||
| 56 | $this->assertTrue(true); |
||
| 57 | return; |
||
| 58 | } |
||
| 59 | |||
| 60 | $message = Text::format( |
||
| 61 | '"{0}" do not implements "{1}" interface.', |
||
| 62 | $className, |
||
| 63 | IStrictPropertiesContainer::class |
||
| 64 | ); |
||
| 65 | |||
| 66 | $this->assertContains( |
||
| 67 | IStrictPropertiesContainer::class, |
||
| 68 | $class->getInterfaceNames(), |
||
| 69 | $message |
||
| 70 | ); |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @depends testImplementsIStrictPropertiesContainerInterface |
||
| 75 | * @dataProvider objectInstanceProvider |
||
| 76 | * |
||
| 77 | * @param IStrictPropertiesContainer $obj |
||
| 78 | */ |
||
| 79 | public function testIsUnableToCreateDirectAttributesOutsideOfClassDefinition(IStrictPropertiesContainer $obj) |
||
| 80 | { |
||
| 81 | /** @var TestCase $this */ |
||
| 82 | $this->expectException(BadMethodCallException::class); |
||
| 83 | |||
| 84 | /** @phpstan-ignore-next-line */ |
||
| 85 | $obj->thisPropertyNameIsMaybeImposibleThatExistsInClassToBeUsedAsNameOfPropertyOfAnyClassGiven = 'No way'; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 86 | } |
||
| 87 | } |
||
| 88 |