From 5fa8bf6bf8c6fcfc2677aafd5a9f36531ae74f9f Mon Sep 17 00:00:00 2001 From: Alexandr Chernyaev Date: Mon, 2 Sep 2024 11:55:18 +0300 Subject: [PATCH] refs #2880 Added tests --- .../Screen/ScreenFillPublicPropertyTest.php | 26 +++++++++++++++++++ tests/Unit/Screen/Screens/ParentScreen.php | 16 ++++++++++++ .../Screens/ScreenWithInheritedProperties.php | 9 +++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/Unit/Screen/Screens/ParentScreen.php create mode 100644 tests/Unit/Screen/Screens/ScreenWithInheritedProperties.php diff --git a/tests/Unit/Screen/ScreenFillPublicPropertyTest.php b/tests/Unit/Screen/ScreenFillPublicPropertyTest.php index da41f352c..fbf5def60 100644 --- a/tests/Unit/Screen/ScreenFillPublicPropertyTest.php +++ b/tests/Unit/Screen/ScreenFillPublicPropertyTest.php @@ -7,6 +7,7 @@ use Orchid\Screen\Repository; use Orchid\Screen\Screen; use Orchid\Tests\TestUnitCase; +use Orchid\Tests\Unit\Screen\Screens\ScreenWithInheritedProperties; class ScreenFillPublicPropertyTest extends TestUnitCase { @@ -73,4 +74,29 @@ public function testFillPublicPropertyWithVariousValueTypes(): void $this->assertEquals($expectedValue, $this->screen->{$property}, "Failed asserting that property '$property' is set correctly."); } } + + /** + * Tests that the `getPublicPropertyNames` method correctly returns all public properties, + * including those defined in the parent class, ensuring they are accessible for filling. + */ + public function testGetPublicPropertyNamesIncludesInheritedProperties(): void + { + $screen = new ScreenWithInheritedProperties(); + + // Use reflection to access the protected method getPublicPropertyNames + $reflection = new \ReflectionClass($screen); + $method = $reflection->getMethod('getPublicPropertyNames'); + $method->setAccessible(true); + + // Invoke the protected method and get the result + $result = $method->invoke($screen); + + // Assert that the result contains all public properties, including those from the parent class + $this->assertEquals($result->all(), [ + 'childProperty1', + 'childProperty2', + 'parentProperty1', + 'parentProperty2', + ]); + } } diff --git a/tests/Unit/Screen/Screens/ParentScreen.php b/tests/Unit/Screen/Screens/ParentScreen.php new file mode 100644 index 000000000..ec92b6f15 --- /dev/null +++ b/tests/Unit/Screen/Screens/ParentScreen.php @@ -0,0 +1,16 @@ +