Skip to content

Commit 3e48e13

Browse files
jrfnlgrogy
authored andcommitted
PHPUnit: don't use __construct() / cross-version compat up to PHPUnit 7.x
The `__construct()` method in the PHPUnit `TestCase` class is used by that class itself. Overloading it from a child class , while not problematic in PHPUnit 4.x, is problematic in later PHPUnit versions. Better to use the `setUpBeforeClass()`or `setUp()` methods instead to set up fixtures. With this change, the unit tests can now be run on PHPUnit 4 - 7.
1 parent 61235f3 commit 3e48e13

File tree

9 files changed

+75
-75
lines changed

9 files changed

+75
-75
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"php-parallel-lint/php-console-highlighter": "For colored console output"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "^4.8.36",
21+
"phpunit/phpunit": "^4.8.36 || ^5.0 || ^6.0 || ^7.0",
2222
"php-parallel-lint/php-parallel-lint": "^1.0"
2323
},
2424
"bin": ["var-dump-check"],

tests/JakubOnderka/PhpVarDumpCheck/CheckTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
class CheckTest extends TestCase
77
{
8-
protected $uut;
8+
protected static $uut;
99

1010

11-
public function __construct()
11+
public static function setUpBeforeClass()
1212
{
1313
$settings = new PhpVarDumpCheck\Settings();
14-
$this->uut = new PhpVarDumpCheck\Checker($settings);
14+
self::$uut = new PhpVarDumpCheck\Checker($settings);
1515
}
1616

1717

@@ -21,7 +21,7 @@ public function testCheck_emptyFile_noDump()
2121
<?php
2222
2323
PHP;
24-
$result = $this->uut->check($content);
24+
$result = self::$uut->check($content);
2525
$this->assertCount(0, $result);
2626
}
2727

@@ -32,7 +32,7 @@ public function testCheck_singleVarDump_dump()
3232
<?php
3333
var_dump('Ahoj');
3434
PHP;
35-
$result = $this->uut->check($content);
35+
$result = self::$uut->check($content);
3636
$this->assertCount(1, $result);
3737
$this->assertEquals('var_dump', $result[0]->getType());
3838
$this->assertTrue($result[0]->isSure());
@@ -46,7 +46,7 @@ public function testCheck_singlePrintR_dump()
4646
<?php
4747
print_r('Ahoj');
4848
PHP;
49-
$result = $this->uut->check($content);
49+
$result = self::$uut->check($content);
5050
$this->assertCount(1, $result);
5151
$this->assertEquals('print_r', $result[0]->getType());
5252
$this->assertTrue($result[0]->isSure());
@@ -60,7 +60,7 @@ public function testCheck_singleVarExport_dump()
6060
<?php
6161
var_export('Ahoj');
6262
PHP;
63-
$result = $this->uut->check($content);
63+
$result = self::$uut->check($content);
6464
$this->assertCount(1, $result);
6565
$this->assertEquals('var_export', $result[0]->getType());
6666
$this->assertTrue($result[0]->isSure());
@@ -80,7 +80,7 @@ public function testCheck_templateSingleVarExport_dump()
8080
?>
8181
var_export('Ahoj');
8282
PHP;
83-
$result = $this->uut->check($content);
83+
$result = self::$uut->check($content);
8484
$this->assertCount(1, $result);
8585
$this->assertEquals('var_export', $result[0]->getType());
8686
$this->assertTrue($result[0]->isSure());
@@ -95,7 +95,7 @@ public function testCheck_singleVarExportWhitespaces_dump()
9595
var_export ( 'Ahoj'
9696
) ;
9797
PHP;
98-
$result = $this->uut->check($content);
98+
$result = self::$uut->check($content);
9999
$this->assertCount(1, $result);
100100
$this->assertEquals('var_export', $result[0]->getType());
101101
$this->assertTrue($result[0]->isSure());
@@ -110,7 +110,7 @@ public function testCheck_singleVarExportWhitespaces_comments()
110110
var_export /* v */ ( /* v */ 'Ahoj'/* v */
111111
) ;
112112
PHP;
113-
$result = $this->uut->check($content);
113+
$result = self::$uut->check($content);
114114
$this->assertCount(1, $result);
115115
$this->assertEquals('var_export', $result[0]->getType());
116116
$this->assertTrue($result[0]->isSure());
@@ -127,7 +127,7 @@ public function testCheck_singlePrintRWithReturnFalse_dump()
127127
<?php
128128
print_r('Ahoj', false);
129129
PHP;
130-
$result = $this->uut->check($content);
130+
$result = self::$uut->check($content);
131131
$this->assertCount(1, $result);
132132
$this->assertEquals('print_r', $result[0]->getType());
133133
$this->assertTrue($result[0]->isSure());
@@ -141,7 +141,7 @@ public function testCheck_singlePrintRWithReturnFalseComments_dump()
141141
<?php
142142
print_r('Ahoj'/**/,/**/false/**/);
143143
PHP;
144-
$result = $this->uut->check($content);
144+
$result = self::$uut->check($content);
145145
$this->assertCount(1, $result);
146146
$this->assertEquals('print_r', $result[0]->getType());
147147
$this->assertTrue($result[0]->isSure());
@@ -155,7 +155,7 @@ public function testCheck_singlePrintRWithReturnNull_dump()
155155
<?php
156156
print_r('Ahoj', null);
157157
PHP;
158-
$result = $this->uut->check($content);
158+
$result = self::$uut->check($content);
159159
$this->assertCount(1, $result);
160160
$this->assertEquals('print_r', $result[0]->getType());
161161
$this->assertTrue($result[0]->isSure());
@@ -169,7 +169,7 @@ public function testCheck_singlePrintRWithReturnIntZero_dump()
169169
<?php
170170
print_r('Ahoj', 0);
171171
PHP;
172-
$result = $this->uut->check($content);
172+
$result = self::$uut->check($content);
173173
$this->assertCount(1, $result);
174174
$this->assertEquals('print_r', $result[0]->getType());
175175
$this->assertTrue($result[0]->isSure());
@@ -183,7 +183,7 @@ public function testCheck_singlePrintRWithReturnFloatZero_dump()
183183
<?php
184184
print_r('Ahoj', 0.0);
185185
PHP;
186-
$result = $this->uut->check($content);
186+
$result = self::$uut->check($content);
187187
$this->assertCount(1, $result);
188188
$this->assertEquals('print_r', $result[0]->getType());
189189
$this->assertTrue($result[0]->isSure());
@@ -197,7 +197,7 @@ public function testCheck_singlePrintRWithReturnFalseVariableAssign_dump()
197197
<?php
198198
print_r('Ahoj', \$var = false);
199199
PHP;
200-
$result = $this->uut->check($content);
200+
$result = self::$uut->check($content);
201201
$this->assertCount(1, $result);
202202
$this->assertEquals('print_r', $result[0]->getType());
203203
$this->assertTrue($result[0]->isSure());
@@ -211,7 +211,7 @@ public function testCheck_staticMethodInOtherClass_ignore()
211211
<?php
212212
OtherClass::print_r('Ahoj');
213213
PHP;
214-
$result = $this->uut->check($content);
214+
$result = self::$uut->check($content);
215215
$this->assertCount(0, $result);
216216
}
217217

@@ -223,7 +223,7 @@ public function testCheck_objectMethod_ignore()
223223
\$object = new stdClass();
224224
\$object->print_r('Ahoj');
225225
PHP;
226-
$result = $this->uut->check($content);
226+
$result = self::$uut->check($content);
227227
$this->assertCount(0, $result);
228228
}
229229

@@ -241,7 +241,7 @@ public function print_r()
241241
\$object = new print_r();
242242
\$object->print_r();
243243
PHP;
244-
$result = $this->uut->check($content);
244+
$result = self::$uut->check($content);
245245
$this->assertCount(1, $result);
246246
$this->assertEquals('print_r', $result[0]->getType());
247247
$this->assertTrue($result[0]->isSure());
@@ -254,7 +254,7 @@ public function testCheck_debugRightAfterStart_dump()
254254
$content = <<<PHP
255255
<?php print_r('ahoj');
256256
PHP;
257-
$result = $this->uut->check($content);
257+
$result = self::$uut->check($content);
258258
$this->assertCount(1, $result);
259259
}
260260
}

tests/JakubOnderka/PhpVarDumpCheck/DoctrineTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55

66
class DoctrineTest extends TestCase
77
{
8-
protected $uut;
8+
protected static $uut;
99

1010

11-
public function __construct()
11+
public static function setUpBeforeClass()
1212
{
1313
$settings = new PhpVarDumpCheck\Settings();
1414
$settings->functionsToCheck = array_merge($settings->functionsToCheck, [
1515
PhpVarDumpCheck\Settings::DOCTRINE_DUMP,
1616
PhpVarDumpCheck\Settings::DOCTRINE_DUMP_2,
1717
]);
1818

19-
$this->uut = new PhpVarDumpCheck\Checker($settings);
19+
self::$uut = new PhpVarDumpCheck\Checker($settings);
2020
}
2121

2222

@@ -26,7 +26,7 @@ public function testCheck_zendDebugDump()
2626
<?php
2727
Doctrine::dump(\$var);
2828
PHP;
29-
$result = $this->uut->check($content);
29+
$result = self::$uut->check($content);
3030
$this->assertCount(1, $result);
3131
}
3232

@@ -37,7 +37,7 @@ public function testCheck_zendDebugDumpReturn()
3737
<?php
3838
Doctrine::dump(\$var, null, false);
3939
PHP;
40-
$result = $this->uut->check($content);
40+
$result = self::$uut->check($content);
4141
$this->assertCount(1, $result);
4242
}
4343

@@ -52,7 +52,7 @@ public function testCheck_zendNamespaceDump()
5252
\\Doctrine\\Common\\Util\\Debug::dump(\$form);
5353
PHP;
5454

55-
$result = $this->uut->check($content);
55+
$result = self::$uut->check($content);
5656
$this->assertCount(1, $result);
5757
}
5858
}

tests/JakubOnderka/PhpVarDumpCheck/LadybugTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
class LadybugTest extends TestCase
77
{
8-
private $uut;
8+
protected static $uut;
99

1010

11-
public function __construct()
11+
public static function setUpBeforeClass()
1212
{
1313
$settings = new PhpVarDumpCheck\Settings();
1414
$settings->functionsToCheck = array_merge($settings->functionsToCheck, [
@@ -17,7 +17,7 @@ public function __construct()
1717
PhpVarDumpCheck\Settings::LADYBUG_DUMP_SHORTCUT,
1818
PhpVarDumpCheck\Settings::LADYBUG_DUMP_DIE_SHORTCUT,
1919
]);
20-
$this->uut = new PhpVarDumpCheck\Checker($settings);
20+
self::$uut = new PhpVarDumpCheck\Checker($settings);
2121
}
2222

2323

@@ -27,7 +27,7 @@ public function testCheck_ladybugDump()
2727
<?php
2828
ladybug_dump(\$var);
2929
PHP;
30-
$result = $this->uut->check($content);
30+
$result = self::$uut->check($content);
3131
$this->assertCount(1, $result);
3232
}
3333

@@ -38,7 +38,7 @@ public function testCheck_ladybugDumpDie()
3838
<?php
3939
ladybug_dump_die(\$var);
4040
PHP;
41-
$result = $this->uut->check($content);
41+
$result = self::$uut->check($content);
4242
$this->assertCount(1, $result);
4343
}
4444

@@ -49,7 +49,7 @@ public function testCheck_ladybugDumpShortcut()
4949
<?php
5050
ld(\$var);
5151
PHP;
52-
$result = $this->uut->check($content);
52+
$result = self::$uut->check($content);
5353
$this->assertCount(1, $result);
5454
}
5555

@@ -60,7 +60,7 @@ public function testCheck_ladybugDumpDieShortcut()
6060
<?php
6161
ldd(\$var);
6262
PHP;
63-
$result = $this->uut->check($content);
63+
$result = self::$uut->check($content);
6464
$this->assertCount(1, $result);
6565
}
6666

@@ -74,7 +74,7 @@ public function testCheck_dumpsWithNamespace()
7474
\\ld('Ahoj');
7575
\\ldd('Ahoj');
7676
PHP;
77-
$result = $this->uut->check($content);
77+
$result = self::$uut->check($content);
7878
$this->assertCount(4, $result);
7979
}
8080
}

tests/JakubOnderka/PhpVarDumpCheck/LaravelTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55

66
class LaravelTest extends TestCase
77
{
8-
private $uut;
8+
protected static $uut;
99

1010

11-
public function __construct()
11+
public static function setUpBeforeClass()
1212
{
1313
$settings = new PhpVarDumpCheck\Settings();
1414
$settings->functionsToCheck = array_merge($settings->functionsToCheck, [
1515
PhpVarDumpCheck\Settings::LARAVEL_DUMP_DD,
1616
PhpVarDumpCheck\Settings::LARAVEL_DUMP,
1717
]);
18-
$this->uut = new PhpVarDumpCheck\Checker($settings);
18+
self::$uut = new PhpVarDumpCheck\Checker($settings);
1919
}
2020

2121

@@ -25,7 +25,7 @@ public function testCheck_laravelDumpDd()
2525
<?php
2626
dd(\$var);
2727
PHP;
28-
$result = $this->uut->check($content);
28+
$result = self::$uut->check($content);
2929
$this->assertCount(1, $result);
3030
}
3131

@@ -35,7 +35,7 @@ public function testCheck_laravelDump()
3535
<?php
3636
dump(\$var);
3737
PHP;
38-
$result = $this->uut->check($content);
38+
$result = self::$uut->check($content);
3939
$this->assertCount(1, $result);
4040
}
4141
}

0 commit comments

Comments
 (0)