Skip to content

Commit 0d91c70

Browse files
author
Gavin Love
committed
General 7.X tidyups
1 parent 24d380e commit 0d91c70

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

src/IgnoreTestPolicy.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,5 @@
44

55
interface IgnoreTestPolicy
66
{
7-
/**
8-
* @return boolean
9-
*/
10-
public function shouldIgnore(\ReflectionObject $testReflection);
7+
public function shouldIgnore(\ReflectionObject $testReflection):bool;
118
}

src/TestListener.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44

55
use PHPUnit\Framework\TestListener as BaseTestListener;
66
use PHPUnit\Framework\TestListenerDefaultImplementation;
7+
use PHPUnit\Framework\Test;
78

89
class TestListener implements BaseTestListener
910
{
1011
use TestListenerDefaultImplementation;
1112

1213
private $ignorePolicy;
1314

14-
const PHPUNIT_PROPERTY_PREFIX = 'PHPUnit_';
15+
private const PHPUNIT_PROPERTY_PREFIX = 'PHPUnit_';
1516

1617
public function __construct(IgnoreTestPolicy $ignorePolicy = null)
1718
{
18-
$this->ignorePolicy = ($ignorePolicy) ?: new NeverIgnoreTestPolicy();
19+
$this->ignorePolicy = $ignorePolicy ?: new NeverIgnoreTestPolicy();
1920
}
2021

21-
public function endTest(\PHPUnit\Framework\Test $test, float $time): void
22+
public function endTest(Test $test, float $time): void
2223
{
2324
$testReflection = new \ReflectionObject($test);
2425

@@ -29,7 +30,7 @@ public function endTest(\PHPUnit\Framework\Test $test, float $time): void
2930
$this->safelyFreeProperties($test, $testReflection->getProperties());
3031
}
3132

32-
private function safelyFreeProperties(\PHPUnit\Framework\Test $test, array $properties)
33+
private function safelyFreeProperties(Test $test, array $properties)
3334
{
3435
foreach ($properties as $property) {
3536
if ($this->isSafeToFreeProperty($property)) {
@@ -48,7 +49,7 @@ private function isNotPhpUnitProperty(\ReflectionProperty $property)
4849
return 0 !== strpos($property->getDeclaringClass()->getName(), self::PHPUNIT_PROPERTY_PREFIX);
4950
}
5051

51-
private function freeProperty(\PHPUnit\Framework\Test $test, \ReflectionProperty $property)
52+
private function freeProperty(Test $test, \ReflectionProperty $property)
5253
{
5354
$property->setAccessible(true);
5455
$property->setValue($test, null);
@@ -57,7 +58,7 @@ private function freeProperty(\PHPUnit\Framework\Test $test, \ReflectionProperty
5758

5859
class NeverIgnoreTestPolicy implements IgnoreTestPolicy
5960
{
60-
public function shouldIgnore(\ReflectionObject $testReflection)
61+
public function shouldIgnore(\ReflectionObject $testReflection): bool
6162
{
6263
return false;
6364
}

tests/TestListenerTest.php

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

66
class TestListenerTest extends \PHPUnit\Framework\TestCase
77
{
8+
/** @var DummyTest */
89
private $dummyTest;
910

1011
protected function setUp()
1112
{
1213
$this->dummyTest = new DummyTest();
1314
}
1415

15-
/**
16-
* @test
17-
*/
18-
public function shouldFreeTestProperty()
16+
public function testShouldFreeTestProperty():void
1917
{
2018
$this->endTest(new TestListener());
2119

2220
$this->assertFreesTestProperty();
2321
}
2422

25-
private function endTest(TestListener $listener)
23+
private function endTest(TestListener $listener):void
2624
{
2725
$listener->endTest($this->dummyTest, 0);
2826
}
2927

30-
private function assertFreesTestProperty()
28+
private function assertFreesTestProperty():void
3129
{
3230
$this->assertNull($this->dummyTest->property);
3331
}
3432

35-
/**
36-
* @test
37-
*/
38-
public function shouldNotFreePhpUnitProperty()
33+
public function testShouldNotFreePhpUnitProperty():void
3934
{
4035
$this->endTest(new TestListener());
4136

4237
$this->assertDoesNotFreePHPUnitProperty();
4338
}
4439

45-
private function assertDoesNotFreePHPUnitProperty()
40+
private function assertDoesNotFreePHPUnitProperty():void
4641
{
4742
$this->assertNotNull($this->dummyTest->phpUnitProperty);
4843
}
4944

50-
/**
51-
* @test
52-
*/
53-
public function shouldNotFreeTestPropertyWithIgnoreAlwaysPolicy()
45+
public function testShouldNotFreeTestPropertyWithIgnoreAlwaysPolicy(): void
5446
{
5547
$this->endTest(new TestListener(new AlwaysIgnoreTestPolicy()));
5648

5749
$this->assertDoesNotFreeTestProperty();
5850
}
5951

60-
private function assertDoesNotFreeTestProperty()
52+
private function assertDoesNotFreeTestProperty():void
6153
{
6254
$this->assertNotNull($this->dummyTest->property);
6355
}
@@ -75,7 +67,7 @@ class DummyTest extends \PHPUnit_Fake
7567

7668
class AlwaysIgnoreTestPolicy implements IgnoreTestPolicy
7769
{
78-
public function shouldIgnore(\ReflectionObject $testReflection)
70+
public function shouldIgnore(\ReflectionObject $testReflection): bool
7971
{
8072
return true;
8173
}

0 commit comments

Comments
 (0)