Skip to content

Commit 7ef7225

Browse files
authored
Merge pull request #28 from php-vcr/improvements/php7-love
PHP 7.1 Love
2 parents aa27631 + 6b7bad2 commit 7ef7225

File tree

4 files changed

+55
-151
lines changed

4 files changed

+55
-151
lines changed

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
}
2020
},
2121
"require": {
22-
"php-vcr/php-vcr": "^1.4"
22+
"php-vcr/php-vcr": "^1.4",
23+
"php": "^7.1"
2324
},
2425
"require-dev": {
25-
"phpunit/phpunit": "^7"
26+
"phpunit/phpunit": "^7.0"
2627
}
2728
}

phpunit.xml.dist

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.0/phpunit.xsd"
55
backupGlobals="false"
66
convertErrorsToExceptions="true"
77
convertNoticesToExceptions="true"
@@ -10,15 +10,13 @@
1010
bootstrap="tests/bootstrap.php"
1111
cacheTokens="true"
1212
forceCoversAnnotation="false"
13-
mapTestClassNameToCoveredClassName="false"
1413
printerClass="PHPUnit\TextUI\ResultPrinter"
1514
processIsolation="false"
1615
stopOnError="false"
1716
stopOnFailure="false"
1817
stopOnIncomplete="false"
1918
stopOnSkipped="false"
2019
testSuiteLoaderClass="PHPUnit\Runner\StandardTestSuiteLoader"
21-
strict="false"
2220
verbose="true"
2321
>
2422

@@ -29,9 +27,6 @@
2927
</testsuites>
3028

3129
<filter>
32-
<blacklist>
33-
<directory>./vendor</directory>
34-
</blacklist>
3530
<whitelist processUncoveredFilesFromWhitelist="true">
3631
<directory suffix=".php">src</directory>
3732
</whitelist>

src/VCRTestListener.php

+37-130
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
2+
declare(strict_types=1);
23

34
namespace VCR\PHPUnit\TestListener;
45

56
use PHPUnit\Framework\AssertionFailedError;
67
use PHPUnit\Framework\Test;
8+
use PHPUnit\Framework\TestCase;
79
use PHPUnit\Framework\TestListener;
810
use PHPUnit\Framework\TestSuite;
911
use PHPUnit\Framework\Warning;
@@ -15,124 +17,21 @@
1517
* Here is an example XML configuration for activating this listener:
1618
*
1719
* <code>
18-
* <listeners>
19-
* <listener class="VCR\PHPUnit\TestListener\VCRTestListener" file="vendor/php-vcr/phpunit-testlistener-vcr/src/VCRTestListener.php" />
20-
* </listeners>
20+
* <listeners>
21+
* <listener class="VCR\PHPUnit\TestListener\VCRTestListener" file="vendor/php-vcr/phpunit-testlistener-vcr/src/VCRTestListener.php" />
22+
* </listeners>
2123
* </code>
2224
*
23-
* @author Adrian Philipp <[email protected]>
25+
* @author Adrian Philipp <[email protected]>
2426
* @author Davide Borsatto <[email protected]>
25-
* @copyright 2011-2017 Adrian Philipp <[email protected]>
26-
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
27-
*
28-
* @version Release: @package_version@
29-
*
30-
* @see http://www.phpunit.de/
27+
* @author Renato Mefi <[email protected]>
3128
*/
32-
class VCRTestListener implements TestListener
29+
final class VCRTestListener implements TestListener
3330
{
34-
/**
35-
* @var array
36-
*/
37-
protected $runs = array();
38-
39-
/**
40-
* @var array
41-
*/
42-
protected $options = array();
43-
44-
/**
45-
* @var int
46-
*/
47-
protected $suites = 0;
48-
49-
/**
50-
* Constructor.
51-
*
52-
* @param array $options
53-
*/
54-
public function __construct(array $options = array())
55-
{
56-
}
57-
58-
/**
59-
* An error occurred.
60-
*
61-
* @param Test $test
62-
* @param Exception $e
63-
* @param float $time
64-
*/
65-
public function addError(Test $test, \Throwable $t, float $time): void
66-
{
67-
}
68-
69-
/**
70-
* A warning occurred.
71-
*
72-
* @param Test $test
73-
* @param Warning $e
74-
* @param float $time
75-
*
76-
* @since Method available since Release 5.1.0
77-
*/
78-
public function addWarning(Test $test, Warning $e, float $time): void
79-
{
80-
}
81-
82-
/**
83-
* A failure occurred.
84-
*
85-
* @param Test $test
86-
* @param AssertionFailedError $e
87-
* @param float $time
88-
*/
89-
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
90-
{
91-
}
92-
93-
/**
94-
* Incomplete test.
95-
*
96-
* @param Test $test
97-
* @param \Exception $e
98-
* @param float $time
99-
*/
100-
public function addIncompleteTest(Test $test, \Throwable $e, float $time): void
101-
{
102-
}
103-
104-
/**
105-
* Skipped test.
106-
*
107-
* @param Test $test
108-
* @param \Exception $e
109-
* @param float $time
110-
*/
111-
public function addSkippedTest(Test $test, \Throwable $e, float $time): void
112-
{
113-
}
114-
115-
/**
116-
* Risky test.
117-
*
118-
* @param Test $test
119-
* @param \Exception $e
120-
* @param float $time
121-
*/
122-
public function addRiskyTest(Test $test, \Throwable $e, float $time): void
123-
{
124-
}
125-
126-
/**
127-
* A test started.
128-
*
129-
* @param Test $test
130-
*
131-
* @return bool|null
132-
*/
13331
public function startTest(Test $test): void
13432
{
135-
$class = get_class($test);
33+
$class = \get_class($test);
34+
\assert($test instanceof TestCase);
13635
$method = $test->getName(false);
13736

13837
if (!method_exists($class, $method)) {
@@ -147,7 +46,7 @@ public function startTest(Test $test): void
14746
$cassetteName = array_pop($parsed);
14847

14948
// If the cassette name ends in .json, then use the JSON storage format
150-
if (substr($cassetteName, '-5') == '.json') {
49+
if (substr($cassetteName, -5) === '.json') {
15150
VCR::configure()->setStorage('json');
15251
}
15352

@@ -159,9 +58,9 @@ public function startTest(Test $test): void
15958
VCR::insertCassette($cassetteName);
16059
}
16160

162-
private static function parseDocBlock($docBlock, $tag)
61+
private static function parseDocBlock($docBlock, $tag): array
16362
{
164-
$matches = array();
63+
$matches = [];
16564

16665
if (empty($docBlock)) {
16766
return $matches;
@@ -185,31 +84,39 @@ private static function parseDocBlock($docBlock, $tag)
18584
return $matches;
18685
}
18786

188-
/**
189-
* A test ended.
190-
*
191-
* @param Test $test
192-
* @param float $time
193-
*/
19487
public function endTest(Test $test, float $time): void
19588
{
19689
VCR::turnOff();
19790
}
19891

199-
/**
200-
* A test suite started.
201-
*
202-
* @param TestSuite $suite
203-
*/
92+
public function addError(Test $test, \Throwable $t, float $time): void
93+
{
94+
}
95+
96+
public function addWarning(Test $test, Warning $e, float $time): void
97+
{
98+
}
99+
100+
public function addFailure(Test $test, AssertionFailedError $e, float $time): void
101+
{
102+
}
103+
104+
public function addIncompleteTest(Test $test, \Throwable $e, float $time): void
105+
{
106+
}
107+
108+
public function addSkippedTest(Test $test, \Throwable $e, float $time): void
109+
{
110+
}
111+
112+
public function addRiskyTest(Test $test, \Throwable $e, float $time): void
113+
{
114+
}
115+
204116
public function startTestSuite(TestSuite $suite): void
205117
{
206118
}
207119

208-
/**
209-
* A test suite ended.
210-
*
211-
* @param TestSuite $suite
212-
*/
213120
public function endTestSuite(TestSuite $suite): void
214121
{
215122
}

tests/VCRTestListenerTest.php

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
<?php
2+
declare(strict_types=1);
23

34
namespace Tests\VCR\PHPUnit\TestListener;
45

56
use PHPUnit\Framework\TestCase;
67

7-
/**
8-
* Test integration of PHPVCR with PHPUnit using annotations.
9-
*/
10-
class VCRTestListenerTest extends TestCase
8+
final class VCRTestListenerTest extends TestCase
119
{
1210
/**
1311
* @vcr unittest_annotation_test
1412
*/
15-
public function testInterceptsWithAnnotations()
13+
public function testInterceptsWithAnnotations(): void
1614
{
1715
// Content of tests/fixtures/unittest_annotation_test: "This is a annotation test dummy".
1816
$result = file_get_contents('http://google.com');
@@ -22,28 +20,31 @@ public function testInterceptsWithAnnotations()
2220
/**
2321
* @vcr unittest_annotation_test.yml
2422
*/
25-
public function testInterceptsWithAnnotationsAndFileExtension()
23+
public function testInterceptsWithAnnotationsAndFileExtension(): void
2624
{
2725
$result = file_get_contents('http://google.com');
2826
$this->assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using annotations).');
2927
}
3028

3129
/**
3230
* @vcr unittest_annotation_test
33-
* @dataProvider aDataProvider
31+
*
32+
* @dataProvider dummyDataProvider
3433
*/
35-
public function testInterceptsWithAnnotationsWhenUsingDataProvider($dummyValue)
34+
public function testInterceptsWithAnnotationsWhenUsingDataProvider(int $dummyValue): void
3635
{
3736
// Content of tests/fixtures/unittest_annotation_test: "This is an annotation test dummy".
3837
$result = file_get_contents('http://google.com');
38+
// Just to avoid the dummy to annoy the static analyzers
39+
\assert(\is_int($dummyValue));
3940
$this->assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using annotations with data provider).');
4041
}
4142

42-
public function aDataProvider()
43+
public function dummyDataProvider(): array
4344
{
44-
return array(
45-
array(1),
46-
array(2),
47-
);
45+
return [
46+
[1],
47+
[2],
48+
];
4849
}
4950
}

0 commit comments

Comments
 (0)