diff --git a/tests/_support/Test/TestForReflectionHelper.php b/tests/_support/Test/TestForReflectionHelper.php new file mode 100644 index 000000000000..6ea9bea597cd --- /dev/null +++ b/tests/_support/Test/TestForReflectionHelper.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace Tests\Support\Test; + +class TestForReflectionHelper +{ + private string $private = 'secret'; + private static string $static_private = 'xyz'; + + public function getPrivate() + { + return $this->private; + } + + public static function getStaticPrivate() + { + return self::$static_private; + } + + private function privateMethod($param1, $param2) + { + return 'private ' . $param1 . $param2; + } + + private static function privateStaticMethod($param1, $param2) + { + return 'private_static ' . $param1 . $param2; + } +} diff --git a/tests/system/Test/ReflectionHelperTest.php b/tests/system/Test/ReflectionHelperTest.php index 414053b26dc1..86eb65ffbf51 100644 --- a/tests/system/Test/ReflectionHelperTest.php +++ b/tests/system/Test/ReflectionHelperTest.php @@ -11,6 +11,8 @@ namespace CodeIgniter\Test; +use Tests\Support\Test\TestForReflectionHelper; + /** * @internal * @@ -20,14 +22,14 @@ final class ReflectionHelperTest extends CIUnitTestCase { public function testGetPrivatePropertyWithObject(): void { - $obj = new __TestForReflectionHelper(); + $obj = new TestForReflectionHelper(); $actual = $this->getPrivateProperty($obj, 'private'); $this->assertSame('secret', $actual); } public function testGetPrivatePropertyWithObjectStaticCall(): void { - $obj = new __TestForReflectionHelper(); + $obj = new TestForReflectionHelper(); $actual = CIUnitTestCase::getPrivateProperty($obj, 'private'); $this->assertSame('secret', $actual); } @@ -35,7 +37,7 @@ public function testGetPrivatePropertyWithObjectStaticCall(): void public function testGetPrivatePropertyWithStatic(): void { $actual = $this->getPrivateProperty( - __TestForReflectionHelper::class, + TestForReflectionHelper::class, 'static_private' ); $this->assertSame('xyz', $actual); @@ -43,7 +45,7 @@ public function testGetPrivatePropertyWithStatic(): void public function testSetPrivatePropertyWithObject(): void { - $obj = new __TestForReflectionHelper(); + $obj = new TestForReflectionHelper(); $this->setPrivateProperty( $obj, 'private', @@ -55,19 +57,19 @@ public function testSetPrivatePropertyWithObject(): void public function testSetPrivatePropertyWithStatic(): void { $this->setPrivateProperty( - __TestForReflectionHelper::class, + TestForReflectionHelper::class, 'static_private', 'abc' ); $this->assertSame( 'abc', - __TestForReflectionHelper::getStaticPrivate() + TestForReflectionHelper::getStaticPrivate() ); } public function testGetPrivateMethodInvokerWithObject(): void { - $obj = new __TestForReflectionHelper(); + $obj = new TestForReflectionHelper(); $method = $this->getPrivateMethodInvoker( $obj, 'privateMethod' @@ -81,7 +83,7 @@ public function testGetPrivateMethodInvokerWithObject(): void public function testGetPrivateMethodInvokerWithStatic(): void { $method = $this->getPrivateMethodInvoker( - __TestForReflectionHelper::class, + TestForReflectionHelper::class, 'privateStaticMethod' ); $this->assertSame( @@ -90,29 +92,3 @@ public function testGetPrivateMethodInvokerWithStatic(): void ); } } - -class __TestForReflectionHelper -{ - private string $private = 'secret'; - private static string $static_private = 'xyz'; - - public function getPrivate() - { - return $this->private; - } - - public static function getStaticPrivate() - { - return self::$static_private; - } - - private function privateMethod($param1, $param2) - { - return 'private ' . $param1 . $param2; - } - - private static function privateStaticMethod($param1, $param2) - { - return 'private_static ' . $param1 . $param2; - } -} diff --git a/tests/system/Test/TestCaseTest.php b/tests/system/Test/TestCaseTest.php index e5e1ed8cb3f6..ea71ddd0ac48 100644 --- a/tests/system/Test/TestCaseTest.php +++ b/tests/system/Test/TestCaseTest.php @@ -15,6 +15,7 @@ use CodeIgniter\Events\Events; use CodeIgniter\HTTP\Response; use Config\App; +use Tests\Support\Test\TestForReflectionHelper; /** * @internal @@ -35,7 +36,7 @@ protected function setUp(): void public function testGetPrivatePropertyWithObject(): void { - $obj = new __TestForReflectionHelper(); + $obj = new TestForReflectionHelper(); $actual = $this->getPrivateProperty($obj, 'private'); $this->assertSame('secret', $actual); } @@ -54,6 +55,8 @@ public function testAssertLogContains(): void public function testEventTriggering(): void { + $result = ''; + Events::on('foo', static function ($arg) use (&$result): void { $result = $arg; }); @@ -61,6 +64,7 @@ public function testEventTriggering(): void Events::trigger('foo', 'bar'); $this->assertEventTriggered('foo'); + $this->assertSame('bar', $result); } public function testStreamFilter(): void