Skip to content

Commit 7a38206

Browse files
authored
Merge pull request #8291 from kenjis/fix-tests
test: fix test code
2 parents d1b7921 + 8dae2a8 commit 7a38206

3 files changed

Lines changed: 53 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: 5 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
}
@@ -54,13 +55,16 @@ public function testAssertLogContains(): void
5455

5556
public function testEventTriggering(): void
5657
{
58+
$result = '';
59+
5760
Events::on('foo', static function ($arg) use (&$result): void {
5861
$result = $arg;
5962
});
6063

6164
Events::trigger('foo', 'bar');
6265

6366
$this->assertEventTriggered('foo');
67+
$this->assertSame('bar', $result);
6468
}
6569

6670
public function testStreamFilter(): void

0 commit comments

Comments
 (0)