Skip to content

Commit

Permalink
refs #2880 Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Sep 2, 2024
1 parent 84978d9 commit 5fa8bf6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/Unit/Screen/ScreenFillPublicPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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',
]);
}
}
16 changes: 16 additions & 0 deletions tests/Unit/Screen/Screens/ParentScreen.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Orchid\Tests\Unit\Screen\Screens;

use Orchid\Screen\Screen;

class ParentScreen extends Screen
{
public $parentProperty1;
public $parentProperty2;

public function layout(): iterable
{
// TODO: Implement layout() method.
}
}
9 changes: 9 additions & 0 deletions tests/Unit/Screen/Screens/ScreenWithInheritedProperties.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Orchid\Tests\Unit\Screen\Screens;

class ScreenWithInheritedProperties extends ParentScreen
{
public $childProperty1;
public $childProperty2;
}

0 comments on commit 5fa8bf6

Please sign in to comment.