Skip to content

Commit 8dae2a8

Browse files
committed
test: move class in TestCase file
$ vendor/bin/phpunit tests/system/Test/TestCaseTest.php PHPUnit 9.6.15 by Sebastian Bergmann and contributors. Runtime: PHP 8.1.26 Configuration: /.../CodeIgniter4/phpunit.xml E........ 9 / 9 (100%) Time: 00:00.086, Memory: 16.00 MB There was 1 error: 1) CodeIgniter\Test\TestCaseTest::testGetPrivatePropertyWithObject Error: Class "CodeIgniter\Test\__TestForReflectionHelper" not found /.../CodeIgniter4/tests/system/Test/TestCaseTest.php:38 ERRORS! Tests: 9, Assertions: 19, Errors: 1.
1 parent 37a0406 commit 8dae2a8

3 files changed

Lines changed: 50 additions & 35 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <admin@codeigniter.com>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace Tests\Support\Test;
13+
14+
class TestForReflectionHelper
15+
{
16+
private string $private = 'secret';
17+
private static string $static_private = 'xyz';
18+
19+
public function getPrivate()
20+
{
21+
return $this->private;
22+
}
23+
24+
public static function getStaticPrivate()
25+
{
26+
return self::$static_private;
27+
}
28+
29+
private function privateMethod($param1, $param2)
30+
{
31+
return 'private ' . $param1 . $param2;
32+
}
33+
34+
private static function privateStaticMethod($param1, $param2)
35+
{
36+
return 'private_static ' . $param1 . $param2;
37+
}
38+
}

tests/system/Test/ReflectionHelperTest.php

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace CodeIgniter\Test;
1313

14+
use Tests\Support\Test\TestForReflectionHelper;
15+
1416
/**
1517
* @internal
1618
*
@@ -20,30 +22,30 @@ final class ReflectionHelperTest extends CIUnitTestCase
2022
{
2123
public function testGetPrivatePropertyWithObject(): void
2224
{
23-
$obj = new __TestForReflectionHelper();
25+
$obj = new TestForReflectionHelper();
2426
$actual = $this->getPrivateProperty($obj, 'private');
2527
$this->assertSame('secret', $actual);
2628
}
2729

2830
public function testGetPrivatePropertyWithObjectStaticCall(): void
2931
{
30-
$obj = new __TestForReflectionHelper();
32+
$obj = new TestForReflectionHelper();
3133
$actual = CIUnitTestCase::getPrivateProperty($obj, 'private');
3234
$this->assertSame('secret', $actual);
3335
}
3436

3537
public function testGetPrivatePropertyWithStatic(): void
3638
{
3739
$actual = $this->getPrivateProperty(
38-
__TestForReflectionHelper::class,
40+
TestForReflectionHelper::class,
3941
'static_private'
4042
);
4143
$this->assertSame('xyz', $actual);
4244
}
4345

4446
public function testSetPrivatePropertyWithObject(): void
4547
{
46-
$obj = new __TestForReflectionHelper();
48+
$obj = new TestForReflectionHelper();
4749
$this->setPrivateProperty(
4850
$obj,
4951
'private',
@@ -55,19 +57,19 @@ public function testSetPrivatePropertyWithObject(): void
5557
public function testSetPrivatePropertyWithStatic(): void
5658
{
5759
$this->setPrivateProperty(
58-
__TestForReflectionHelper::class,
60+
TestForReflectionHelper::class,
5961
'static_private',
6062
'abc'
6163
);
6264
$this->assertSame(
6365
'abc',
64-
__TestForReflectionHelper::getStaticPrivate()
66+
TestForReflectionHelper::getStaticPrivate()
6567
);
6668
}
6769

6870
public function testGetPrivateMethodInvokerWithObject(): void
6971
{
70-
$obj = new __TestForReflectionHelper();
72+
$obj = new TestForReflectionHelper();
7173
$method = $this->getPrivateMethodInvoker(
7274
$obj,
7375
'privateMethod'
@@ -81,7 +83,7 @@ public function testGetPrivateMethodInvokerWithObject(): void
8183
public function testGetPrivateMethodInvokerWithStatic(): void
8284
{
8385
$method = $this->getPrivateMethodInvoker(
84-
__TestForReflectionHelper::class,
86+
TestForReflectionHelper::class,
8587
'privateStaticMethod'
8688
);
8789
$this->assertSame(
@@ -90,29 +92,3 @@ public function testGetPrivateMethodInvokerWithStatic(): void
9092
);
9193
}
9294
}
93-
94-
class __TestForReflectionHelper
95-
{
96-
private string $private = 'secret';
97-
private static string $static_private = 'xyz';
98-
99-
public function getPrivate()
100-
{
101-
return $this->private;
102-
}
103-
104-
public static function getStaticPrivate()
105-
{
106-
return self::$static_private;
107-
}
108-
109-
private function privateMethod($param1, $param2)
110-
{
111-
return 'private ' . $param1 . $param2;
112-
}
113-
114-
private static function privateStaticMethod($param1, $param2)
115-
{
116-
return 'private_static ' . $param1 . $param2;
117-
}
118-
}

tests/system/Test/TestCaseTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use CodeIgniter\Events\Events;
1616
use CodeIgniter\HTTP\Response;
1717
use Config\App;
18+
use Tests\Support\Test\TestForReflectionHelper;
1819

1920
/**
2021
* @internal
@@ -35,7 +36,7 @@ protected function setUp(): void
3536

3637
public function testGetPrivatePropertyWithObject(): void
3738
{
38-
$obj = new __TestForReflectionHelper();
39+
$obj = new TestForReflectionHelper();
3940
$actual = $this->getPrivateProperty($obj, 'private');
4041
$this->assertSame('secret', $actual);
4142
}

0 commit comments

Comments
 (0)