Skip to content

Commit 5c31f6a

Browse files
committed
Inspection corrections and fixes
1 parent 62e7f02 commit 5c31f6a

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

ext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function enable_failed()
101101
{
102102
$language = $this->container->get('language');
103103
$language->add_lang('common', 'phpbb/skeleton');
104-
return array_map(static function($error) use ($language) {
104+
return array_map(static function ($error) use ($language) {
105105
return is_array($error) ? call_user_func_array([$language, 'lang'], $error) : $language->lang($error);
106106
}, $this->errors);
107107
}

tests/ext_test.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,32 +97,57 @@ public function test_enable_failed_returns_expected()
9797
$this->assertEquals(['LANG: SOME_ERROR'], $method->invoke($ext));
9898
}
9999

100+
public function test_enable_failed_returns_parameterized_error()
101+
{
102+
$ext = $this->getMockBuilder(ext::class)
103+
->disableOriginalConstructor()
104+
->getMock();
105+
106+
$this->setExtErrors($ext, [['PHP_VERSION_ERROR', '7.1.0', '5.5.0']]);
107+
108+
$languageMock = $this->createMock(language::class);
109+
$languageMock->method('add_lang')->willReturn(null);
110+
$languageMock->method('lang')->willReturnCallback(function (...$args) {
111+
return implode(':', $args);
112+
});
113+
114+
$containerMock = $this->createMock(ContainerInterface::class);
115+
$containerMock->method('get')->with('language')->willReturn($languageMock);
116+
117+
$this->setProperty($ext, 'container', $containerMock);
118+
119+
$method = (new \ReflectionClass($ext))->getMethod('enable_failed');
120+
$method->setAccessible(true);
121+
122+
$this->assertEquals(['PHP_VERSION_ERROR:7.1.0:5.5.0'], $method->invoke($ext));
123+
}
124+
100125
public function test_phpbb_requirement_min_error()
101126
{
102127
$this->setExtErrors($this->ext, []);
103128
$this->invokeProtectedMethod($this->ext, 'phpbb_requirement', ['3.2.2']);
104-
$this->assertContains('PHPBB_VERSION_MIN_ERROR', $this->getExtErrors($this->ext));
129+
$this->assertContains('PHPBB_VERSION_MIN_ERROR', $this->getExtErrorKeys($this->ext));
105130
}
106131

107132
public function test_phpbb_requirement_max_error()
108133
{
109134
$this->setExtErrors($this->ext, []);
110135
$this->invokeProtectedMethod($this->ext, 'phpbb_requirement', ['4.0.0-dev']);
111-
$this->assertContains('PHPBB_VERSION_MAX_ERROR', $this->getExtErrors($this->ext));
136+
$this->assertContains('PHPBB_VERSION_MAX_ERROR', $this->getExtErrorKeys($this->ext));
112137
}
113138

114139
public function test_php_requirement_error()
115140
{
116141
$this->setExtErrors($this->ext, []);
117142
$this->invokeProtectedMethod($this->ext, 'php_requirement', [50500]);
118-
$this->assertContains('PHP_VERSION_ERROR', $this->getExtErrors($this->ext));
143+
$this->assertContains('PHP_VERSION_ERROR', $this->getExtErrorKeys($this->ext));
119144
}
120145

121146
public function test_ziparchive_exists_error()
122147
{
123148
$this->setExtErrors($this->ext, []);
124149
$this->invokeProtectedMethod($this->ext, 'ziparchive_exists', ['NotZipArchive']);
125-
$this->assertContains('NO_ZIPARCHIVE_ERROR', $this->getExtErrors($this->ext));
150+
$this->assertContains('NO_ZIPARCHIVE_ERROR', $this->getExtErrorKeys($this->ext));
126151
}
127152

128153
// --- Helpers ---
@@ -138,9 +163,14 @@ protected function getExtErrors($ext): array
138163
{
139164
$prop = (new \ReflectionClass($ext))->getProperty('errors');
140165
$prop->setAccessible(true);
166+
return $prop->getValue($ext);
167+
}
168+
169+
protected function getExtErrorKeys($ext): array
170+
{
141171
return array_map(static function ($e) {
142172
return is_array($e) ? $e[0] : $e;
143-
}, $prop->getValue($ext));
173+
}, $this->getExtErrors($ext));
144174
}
145175

146176
protected function setExtErrors($ext, array $errors): void

0 commit comments

Comments
 (0)