Skip to content

Commit 6126919

Browse files
authored
Merge pull request #26 from johnkary/support60
Add support for PHPUnit 6.0
2 parents f1ca1b1 + f94d09e commit 6126919

File tree

8 files changed

+166
-75
lines changed

8 files changed

+166
-75
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
/phpunit.xml
12
/vendor
23
/composer.lock

.travis.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,20 @@ language: php
33
sudo: false
44

55
php:
6-
- 5.6
76
- 7.0
87
- 7.1
98
- nightly
10-
- hhvm
119

1210
env:
13-
- PHPUNIT=4.7.*
14-
- PHPUNIT=4.8.*
15-
- PHPUNIT=5.0.*
16-
- PHPUNIT=5.1.*
17-
- PHPUNIT=5.2.*
18-
- PHPUNIT=5.3.*
19-
- PHPUNIT=5.4.*
20-
- PHPUNIT=5.5.*
21-
- PHPUNIT=5.6.*
22-
- PHPUNIT=5.7.*
11+
- PHPUNIT=6.0.*
2312

2413
cache:
2514
directories:
2615
- $HOME/.composer
2716

2817
before_script:
2918
- phpenv config-rm xdebug.ini || true
30-
- composer self-update
3119
- composer require phpunit/phpunit:${PHPUNIT}
3220

3321
script:
34-
- ./vendor/bin/phpunit -c phpunit.xml.example --testsuite tests
22+
- ./vendor/bin/phpunit -c phpunit.xml.example

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=5.6",
16-
"phpunit/phpunit": ">=4.7"
15+
"php": ">=7.0",
16+
"phpunit/phpunit": "^6.0"
1717
},
1818
"autoload": {
1919
"psr-0": {

phpunit.xml.example

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
<testsuite name="Project Test Suite">
1818
<directory>src/*/*/*/Tests</directory>
1919
</testsuite>
20-
<testsuite name="tests">
21-
<directory>tests</directory>
22-
</testsuite>
2320
</testsuites>
2421

2522
<listeners>
@@ -41,7 +38,7 @@
4138
<whitelist>
4239
<directory>src</directory>
4340
<exclude>
44-
<directory>src/*/Tests</directory>
41+
<directory>src/*/*/*/Tests</directory>
4542
</exclude>
4643
</whitelist>
4744
</filter>

src/JohnKary/PHPUnit/Listener/SpeedTrapListener.php

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22

33
namespace JohnKary\PHPUnit\Listener;
44

5+
use PHPUnit\Framework\AssertionFailedError;
6+
use PHPUnit\Framework\TestSuite;
7+
use PHPUnit\Framework\Test;
8+
use PHPUnit\Framework\TestCase;
9+
use PHPUnit\Framework\TestListener;
10+
use PHPUnit\Framework\Warning;
11+
512
/**
613
* A PHPUnit TestListener that exposes your slowest running tests by outputting
714
* results directly to the console.
815
*/
9-
class SpeedTrapListener implements \PHPUnit_Framework_TestListener
16+
class SpeedTrapListener implements TestListener
1017
{
1118
/**
1219
* Internal tracking for test suites.
@@ -53,92 +60,87 @@ public function __construct(array $options = array())
5360
/**
5461
* An error occurred.
5562
*
56-
* @param \PHPUnit_Framework_Test $test
57-
* @param \Exception $e
58-
* @param float $time
63+
* @param Test $test
64+
* @param \Exception $e
65+
* @param float $time
5966
*/
60-
public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time)
67+
public function addError(Test $test, \Exception $e, $time)
6168
{
6269
}
6370

6471
/**
6572
* A warning occurred.
6673
*
67-
* @param \PHPUnit_Framework_Test $test
68-
* @param \PHPUnit_Framework_Warning $e
69-
* @param float $time
70-
*
71-
* @since Method available since Release 6.0.0
72-
* @todo Uncomment in time for PHPUnit 6.0.0
73-
* @see https://github.com/sebastianbergmann/phpunit/pull/1840#issuecomment-162535997
74+
* @param Test $test
75+
* @param Warning $e
76+
* @param float $time
7477
*/
75-
public function addWarning(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_Warning $e, $time)
78+
public function addWarning(Test $test, Warning $e, $time)
7679
{
7780
}
7881

7982
/**
8083
* A failure occurred.
8184
*
82-
* @param \PHPUnit_Framework_Test $test
83-
* @param \PHPUnit_Framework_AssertionFailedError $e
84-
* @param float $time
85+
* @param Test $test
86+
* @param AssertionFailedError $e
87+
* @param float $time
8588
*/
86-
public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time)
89+
public function addFailure(Test $test, AssertionFailedError $e, $time)
8790
{
8891
}
8992

9093
/**
9194
* Incomplete test.
9295
*
93-
* @param \PHPUnit_Framework_Test $test
94-
* @param \Exception $e
95-
* @param float $time
96+
* @param Test $test
97+
* @param \Exception $e
98+
* @param float $time
9699
*/
97-
public function addIncompleteTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
100+
public function addIncompleteTest(Test $test, \Exception $e, $time)
98101
{
99102
}
100103

101104
/**
102105
* Risky test.
103106
*
104-
* @param \PHPUnit_Framework_Test $test
105-
* @param \Exception $e
106-
* @param float $time
107-
* @since Method available since Release 4.0.0
107+
* @param Test $test
108+
* @param \Exception $e
109+
* @param float $time
108110
*/
109-
public function addRiskyTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
111+
public function addRiskyTest(Test $test, \Exception $e, $time)
110112
{
111113
}
112114

113115
/**
114116
* Skipped test.
115117
*
116-
* @param \PHPUnit_Framework_Test $test
117-
* @param \Exception $e
118-
* @param float $time
118+
* @param Test $test
119+
* @param \Exception $e
120+
* @param float $time
119121
*/
120-
public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
122+
public function addSkippedTest(Test $test, \Exception $e, $time)
121123
{
122124
}
123125

124126
/**
125127
* A test started.
126128
*
127-
* @param \PHPUnit_Framework_Test $test
129+
* @param Test $test
128130
*/
129-
public function startTest(\PHPUnit_Framework_Test $test)
131+
public function startTest(Test $test)
130132
{
131133
}
132134

133135
/**
134136
* A test ended.
135137
*
136-
* @param \PHPUnit_Framework_Test $test
137-
* @param float $time
138+
* @param Test $test
139+
* @param float $time
138140
*/
139-
public function endTest(\PHPUnit_Framework_Test $test, $time)
141+
public function endTest(Test $test, $time)
140142
{
141-
if (!$test instanceof \PHPUnit_Framework_TestCase) return;
143+
if (!$test instanceof TestCase) return;
142144

143145
$time = $this->toMilliseconds($time);
144146
$threshold = $this->getSlowThreshold($test);
@@ -151,19 +153,19 @@ public function endTest(\PHPUnit_Framework_Test $test, $time)
151153
/**
152154
* A test suite started.
153155
*
154-
* @param \PHPUnit_Framework_TestSuite $suite
156+
* @param TestSuite $suite
155157
*/
156-
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
158+
public function startTestSuite(TestSuite $suite)
157159
{
158160
$this->suites++;
159161
}
160162

161163
/**
162164
* A test suite ended.
163165
*
164-
* @param \PHPUnit_Framework_TestSuite $suite
166+
* @param TestSuite $suite
165167
*/
166-
public function endTestSuite(\PHPUnit_Framework_TestSuite $suite)
168+
public function endTestSuite(TestSuite $suite)
167169
{
168170
$this->suites--;
169171

@@ -191,10 +193,10 @@ protected function isSlow($time, $slowThreshold)
191193
/**
192194
* Stores a test as slow.
193195
*
194-
* @param \PHPUnit_Framework_TestCase $test
196+
* @param TestCase $test
195197
* @param int $time Test execution time in milliseconds
196198
*/
197-
protected function addSlowTest(\PHPUnit_Framework_TestCase $test, $time)
199+
protected function addSlowTest(TestCase $test, $time)
198200
{
199201
$label = $this->makeLabel($test);
200202

@@ -225,10 +227,10 @@ protected function toMilliseconds($time)
225227
/**
226228
* Label for describing a test.
227229
*
228-
* @param \PHPUnit_Framework_TestCase $test
230+
* @param TestCase $test
229231
* @return string
230232
*/
231-
protected function makeLabel(\PHPUnit_Framework_TestCase $test)
233+
protected function makeLabel(TestCase $test)
232234
{
233235
return sprintf('%s:%s', get_class($test), $test->getName());
234236
}
@@ -319,10 +321,10 @@ protected function loadOptions(array $options)
319321
* public function testLongRunningProcess() {}
320322
* </code>
321323
*
322-
* @param \PHPUnit_Framework_TestCase $test
324+
* @param TestCase $test
323325
* @return int
324326
*/
325-
protected function getSlowThreshold(\PHPUnit_Framework_TestCase $test)
327+
protected function getSlowThreshold(TestCase $test)
326328
{
327329
$ann = $test->getAnnotations();
328330

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace JohnKary\PHPUnit\Listener\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
class ExceptionalTest extends TestCase
8+
{
9+
public function testExceptionCanBeThrownInTest()
10+
{
11+
$this->expectException('InvalidArgumentException');
12+
$this->expectExceptionMessage('CODE1');
13+
throw new \InvalidArgumentException('CODE1');
14+
}
15+
16+
public function testSkippedTest()
17+
{
18+
$this->markTestSkipped('Skipped tests do not cause Exceptions in Listener');
19+
}
20+
21+
public function testIncompleteTest()
22+
{
23+
$this->markTestIncomplete('Incomplete tests do not cause Exceptions in Listener');
24+
}
25+
}
26+
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
namespace JohnKary\PHPUnit\Listener\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
class SomeSlowTest extends TestCase
8+
{
9+
public function testFastTest()
10+
{
11+
$this->assertTrue(true);
12+
}
13+
14+
public function testSlowTests()
15+
{
16+
$this->extendTime(300);
17+
18+
$this->assertTrue(true);
19+
}
20+
21+
public function testAnotherSlowTests()
22+
{
23+
$this->extendTime(500);
24+
25+
$this->assertTrue(true);
26+
}
27+
28+
public function testLongEndToEndTest()
29+
{
30+
$this->extendTime(500);
31+
32+
$this->assertTrue(true);
33+
}
34+
35+
/**
36+
* @dataProvider provideTime
37+
*/
38+
public function testWithDataProvider($time)
39+
{
40+
$this->extendTime($time);
41+
42+
$this->assertTrue(true);
43+
}
44+
public function provideTime()
45+
{
46+
return array(
47+
'Rock' => array(800),
48+
'Chalk' => array(700),
49+
'Jayhawk' => array(600),
50+
);
51+
}
52+
53+
/**
54+
* This test's runtime would normally be under the suite's threshold, but
55+
* this annotation sets a lower threshold, causing it to be considered slow
56+
* and reported on in the test output.
57+
*
58+
* @slowThreshold 5
59+
*/
60+
public function testCanSetLowerSlowThreshold()
61+
{
62+
$this->extendTime(10);
63+
$this->assertTrue(true);
64+
}
65+
66+
/**
67+
* This test's runtime would normally be over the suite's threshold, but
68+
* this annotation sets a higher threshold, causing it to be not be
69+
* considered slow and not reported on in the test output.
70+
*
71+
* @slowThreshold 50000
72+
*/
73+
public function testCanSetHigherSlowThreshold()
74+
{
75+
$this->extendTime(600);
76+
$this->assertTrue(true);
77+
}
78+
79+
/**
80+
* @param int $ms Number of additional microseconds to execute code
81+
*/
82+
private function extendTime($ms)
83+
{
84+
usleep($ms * 1000);
85+
}
86+
}

tests/SlowTest.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)