Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit f1cccc9

Browse files
committed
Added return value type hints to code snippets where overrideable methods such as setUp, tearDown etc. are shown. This avoids a fatal error when overriding those methods in a test class, for example: PHP Fatal error: Declaration of ExampleTest::setUpBeforeClass() must be compatible with PHPUnit\Framework\TestCase::setUpBeforeClass(): void in /home/dave/tests/ExampleTest.php on line 3 Also updated where the onNotSuccessfulTest method is shown, updating the argument from an Exception to a Throwable, to match the source code.
1 parent 22a25c9 commit f1cccc9

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

src/code-coverage-analysis.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ PHPUnit でこれを実現するには、
209209
{
210210
protected $ba;
211211
212-
protected function setUp()
212+
protected function setUp(): void
213213
{
214214
$this->ba = new BankAccount;
215215
}

src/fixtures.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ producer-consumer の関係を使って複数のテストでフィクスチャ
5555
{
5656
protected $stack;
5757
58-
protected function setUp()
58+
protected function setUp(): void
5959
{
6060
$this->stack = [];
6161
}
@@ -100,7 +100,7 @@ producer-consumer の関係を使って複数のテストでフィクスチャ
100100
101101
class TemplateMethodsTest extends TestCase
102102
{
103-
public static function setUpBeforeClass()
103+
public static function setUpBeforeClass(): void
104104
{
105105
fwrite(STDOUT, __METHOD__ . "\n");
106106
}
@@ -110,7 +110,7 @@ producer-consumer の関係を使って複数のテストでフィクスチャ
110110
fwrite(STDOUT, __METHOD__ . "\n");
111111
}
112112
113-
protected function assertPreConditions()
113+
protected function assertPreConditions(): void
114114
{
115115
fwrite(STDOUT, __METHOD__ . "\n");
116116
}
@@ -127,7 +127,7 @@ producer-consumer の関係を使って複数のテストでフィクスチャ
127127
$this->assertTrue(false);
128128
}
129129
130-
protected function assertPostConditions()
130+
protected function assertPostConditions(): void
131131
{
132132
fwrite(STDOUT, __METHOD__ . "\n");
133133
}
@@ -137,15 +137,15 @@ producer-consumer の関係を使って複数のテストでフィクスチャ
137137
fwrite(STDOUT, __METHOD__ . "\n");
138138
}
139139
140-
public static function tearDownAfterClass()
140+
public static function tearDownAfterClass(): void
141141
{
142142
fwrite(STDOUT, __METHOD__ . "\n");
143143
}
144144
145-
protected function onNotSuccessfulTest(Exception $e)
145+
protected function onNotSuccessfulTest(Throwable $t): void
146146
{
147147
fwrite(STDOUT, __METHOD__ . "\n");
148-
throw $e;
148+
throw $t;
149149
}
150150
}
151151
@@ -245,12 +245,12 @@ tearDown() よりも setUp()
245245
{
246246
protected static $dbh;
247247
248-
public static function setUpBeforeClass()
248+
public static function setUpBeforeClass(): void
249249
{
250250
self::$dbh = new PDO('sqlite::memory:');
251251
}
252252
253-
public static function tearDownAfterClass()
253+
public static function tearDownAfterClass(): void
254254
{
255255
self::$dbh = null;
256256
}

src/incomplete-and-skipped-tests.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ MySQLi 拡張モジュールが使用可能かを調べたうえで、もし使
133133
134134
class DatabaseTest extends TestCase
135135
{
136-
protected function setUp()
136+
protected function setUp(): void
137137
{
138138
if (!extension_loaded('mysqli')) {
139139
$this->markTestSkipped(

src/test-doubles.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ vfsStream のような仮想ファイルシステムがなければ、外部へ
10451045
10461046
class ExampleTest extends TestCase
10471047
{
1048-
protected function setUp()
1048+
protected function setUp(): void
10491049
{
10501050
if (file_exists(dirname(__FILE__) . '/id')) {
10511051
rmdir(dirname(__FILE__) . '/id');
@@ -1061,7 +1061,7 @@ vfsStream のような仮想ファイルシステムがなければ、外部へ
10611061
$this->assertTrue(file_exists(dirname(__FILE__) . '/id'));
10621062
}
10631063
1064-
protected function tearDown()
1064+
protected function tearDown(): void
10651065
{
10661066
if (file_exists(dirname(__FILE__) . '/id')) {
10671067
rmdir(dirname(__FILE__) . '/id');
@@ -1096,7 +1096,7 @@ vfsStream のような仮想ファイルシステムがなければ、外部へ
10961096
10971097
class ExampleTest extends TestCase
10981098
{
1099-
public function setUp()
1099+
public function setUp(): void
11001100
{
11011101
vfsStreamWrapper::register();
11021102
vfsStreamWrapper::setRoot(new vfsStreamDirectory('exampleDir'));

0 commit comments

Comments
 (0)