Skip to content

Commit 9a2ae0e

Browse files
committed
Fix ext test
1 parent b956951 commit 9a2ae0e

File tree

1 file changed

+13
-30
lines changed

1 file changed

+13
-30
lines changed

tests/ext_test.php

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
namespace phpbb\skeleton\tests;
1515

1616
use phpbb\db\migrator;
17-
use phpbb\finder;
17+
use phpbb\finder\finder;
1818
use phpbb\language\language;
1919
use phpbb\skeleton\ext;
20+
use phpbb_test_case;
21+
use ReflectionClass;
2022
use Symfony\Component\DependencyInjection\ContainerInterface;
2123

22-
class ext_test extends \phpbb_test_case
24+
class ext_test extends phpbb_test_case
2325
{
24-
protected $ext;
26+
protected ext $ext;
2527

2628
protected function setUp(): void
2729
{
@@ -34,16 +36,11 @@ protected function setUp(): void
3436
);
3537
}
3638

37-
public function test_ext_is_instance_of_base()
38-
{
39-
$this->assertInstanceOf(ext::class, $this->ext);
40-
}
41-
4239
public function test_is_enableable_true()
4340
{
4441
$ext = $this->getMockBuilder(ext::class)
4542
->disableOriginalConstructor()
46-
->setMethods(['ziparchive_exists', 'phpbb_requirement', 'php_requirement'])
43+
->onlyMethods(['ziparchive_exists', 'phpbb_requirement', 'php_requirement'])
4744
->getMock();
4845

4946
$ext->method('ziparchive_exists')->willReturn(null);
@@ -58,7 +55,7 @@ public function test_is_enableable_with_errors()
5855
{
5956
$ext = $this->getMockBuilder(ext::class)
6057
->disableOriginalConstructor()
61-
->setMethods(['ziparchive_exists', 'phpbb_requirement', 'php_requirement', 'enable_failed'])
58+
->onlyMethods(['ziparchive_exists', 'phpbb_requirement', 'php_requirement', 'enable_failed'])
6259
->getMock();
6360

6461
$ext->method('ziparchive_exists')->willReturnCallback(function () use ($ext) {
@@ -91,8 +88,7 @@ public function test_enable_failed_returns_expected()
9188

9289
$this->setProperty($ext, 'container', $containerMock);
9390

94-
$method = (new \ReflectionClass($ext))->getMethod('enable_failed');
95-
$method->setAccessible(true);
91+
$method = (new ReflectionClass($ext))->getMethod('enable_failed');
9692

9793
$this->assertEquals(['LANG: SOME_ERROR'], $method->invoke($ext));
9894
}
@@ -101,14 +97,7 @@ public function test_phpbb_requirement_min_error()
10197
{
10298
$this->setExtErrors($this->ext, []);
10399
$this->invokeProtectedMethod($this->ext, 'phpbb_requirement', ['3.2.2']);
104-
$this->assertContains('PHPBB_VERSION_MIN_ERROR', $this->getExtErrors($this->ext));
105-
}
106-
107-
public function test_phpbb_requirement_max_error()
108-
{
109-
$this->setExtErrors($this->ext, []);
110-
$this->invokeProtectedMethod($this->ext, 'phpbb_requirement', ['4.0.0-dev']);
111-
$this->assertContains('PHPBB_VERSION_MAX_ERROR', $this->getExtErrors($this->ext));
100+
$this->assertContains('PHPBB_VERSION_ERROR', $this->getExtErrors($this->ext));
112101
}
113102

114103
public function test_php_requirement_error()
@@ -129,22 +118,17 @@ public function test_ziparchive_exists_error()
129118

130119
protected function invokeProtectedMethod($object, string $methodName, array $args = [])
131120
{
132-
$method = (new \ReflectionClass($object))->getMethod($methodName);
133-
$method->setAccessible(true);
134-
return $method->invokeArgs($object, $args);
121+
return (new ReflectionClass($object))->getMethod($methodName)->invokeArgs($object, $args);
135122
}
136123

137124
protected function getExtErrors($ext): array
138125
{
139-
$prop = (new \ReflectionClass($ext))->getProperty('errors');
140-
$prop->setAccessible(true);
141-
return $prop->getValue($ext);
126+
return (new ReflectionClass($ext))->getProperty('errors')->getValue($ext);
142127
}
143128

144129
protected function setExtErrors($ext, array $errors): void
145130
{
146-
$prop = (new \ReflectionClass($ext))->getProperty('errors');
147-
$prop->setAccessible(true);
131+
$prop = (new ReflectionClass($ext))->getProperty('errors');
148132
$prop->setValue($ext, $errors);
149133
}
150134

@@ -157,8 +141,7 @@ protected function appendExtError($ext, string $error): void
157141

158142
protected function setProperty($object, string $property, $value): void
159143
{
160-
$prop = (new \ReflectionClass($object))->getProperty($property);
161-
$prop->setAccessible(true);
144+
$prop = (new ReflectionClass($object))->getProperty($property);
162145
$prop->setValue($object, $value);
163146
}
164147
}

0 commit comments

Comments
 (0)