diff --git a/composer.json b/composer.json index 97f7641..9490f69 100644 --- a/composer.json +++ b/composer.json @@ -19,9 +19,10 @@ } }, "require": { - "php-vcr/php-vcr": "^1.4" + "php-vcr/php-vcr": "^1.4", + "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "^7" + "phpunit/phpunit": "^7.0" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b78b5db..56a2491 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ @@ -29,9 +27,6 @@ - - ./vendor - src diff --git a/src/VCRTestListener.php b/src/VCRTestListener.php index 1f0df1a..efc87d4 100644 --- a/src/VCRTestListener.php +++ b/src/VCRTestListener.php @@ -1,9 +1,11 @@ - * - * - * + * + * + * * * - * @author Adrian Philipp + * @author Adrian Philipp * @author Davide Borsatto - * @copyright 2011-2017 Adrian Philipp - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * - * @version Release: @package_version@ - * - * @see http://www.phpunit.de/ + * @author Renato Mefi */ -class VCRTestListener implements TestListener +final class VCRTestListener implements TestListener { - /** - * @var array - */ - protected $runs = array(); - - /** - * @var array - */ - protected $options = array(); - - /** - * @var int - */ - protected $suites = 0; - - /** - * Constructor. - * - * @param array $options - */ - public function __construct(array $options = array()) - { - } - - /** - * An error occurred. - * - * @param Test $test - * @param Exception $e - * @param float $time - */ - public function addError(Test $test, \Throwable $t, float $time): void - { - } - - /** - * A warning occurred. - * - * @param Test $test - * @param Warning $e - * @param float $time - * - * @since Method available since Release 5.1.0 - */ - public function addWarning(Test $test, Warning $e, float $time): void - { - } - - /** - * A failure occurred. - * - * @param Test $test - * @param AssertionFailedError $e - * @param float $time - */ - public function addFailure(Test $test, AssertionFailedError $e, float $time): void - { - } - - /** - * Incomplete test. - * - * @param Test $test - * @param \Exception $e - * @param float $time - */ - public function addIncompleteTest(Test $test, \Throwable $e, float $time): void - { - } - - /** - * Skipped test. - * - * @param Test $test - * @param \Exception $e - * @param float $time - */ - public function addSkippedTest(Test $test, \Throwable $e, float $time): void - { - } - - /** - * Risky test. - * - * @param Test $test - * @param \Exception $e - * @param float $time - */ - public function addRiskyTest(Test $test, \Throwable $e, float $time): void - { - } - - /** - * A test started. - * - * @param Test $test - * - * @return bool|null - */ public function startTest(Test $test): void { - $class = get_class($test); + $class = \get_class($test); + \assert($test instanceof TestCase); $method = $test->getName(false); if (!method_exists($class, $method)) { @@ -147,7 +46,7 @@ public function startTest(Test $test): void $cassetteName = array_pop($parsed); // If the cassette name ends in .json, then use the JSON storage format - if (substr($cassetteName, '-5') == '.json') { + if (substr($cassetteName, -5) === '.json') { VCR::configure()->setStorage('json'); } @@ -159,9 +58,9 @@ public function startTest(Test $test): void VCR::insertCassette($cassetteName); } - private static function parseDocBlock($docBlock, $tag) + private static function parseDocBlock($docBlock, $tag): array { - $matches = array(); + $matches = []; if (empty($docBlock)) { return $matches; @@ -185,31 +84,39 @@ private static function parseDocBlock($docBlock, $tag) return $matches; } - /** - * A test ended. - * - * @param Test $test - * @param float $time - */ public function endTest(Test $test, float $time): void { VCR::turnOff(); } - /** - * A test suite started. - * - * @param TestSuite $suite - */ + public function addError(Test $test, \Throwable $t, float $time): void + { + } + + public function addWarning(Test $test, Warning $e, float $time): void + { + } + + public function addFailure(Test $test, AssertionFailedError $e, float $time): void + { + } + + public function addIncompleteTest(Test $test, \Throwable $e, float $time): void + { + } + + public function addSkippedTest(Test $test, \Throwable $e, float $time): void + { + } + + public function addRiskyTest(Test $test, \Throwable $e, float $time): void + { + } + public function startTestSuite(TestSuite $suite): void { } - /** - * A test suite ended. - * - * @param TestSuite $suite - */ public function endTestSuite(TestSuite $suite): void { } diff --git a/tests/VCRTestListenerTest.php b/tests/VCRTestListenerTest.php index db68b73..c2608f9 100644 --- a/tests/VCRTestListenerTest.php +++ b/tests/VCRTestListenerTest.php @@ -1,18 +1,16 @@ assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using annotations).'); @@ -30,20 +28,23 @@ public function testInterceptsWithAnnotationsAndFileExtension() /** * @vcr unittest_annotation_test - * @dataProvider aDataProvider + * + * @dataProvider dummyDataProvider */ - public function testInterceptsWithAnnotationsWhenUsingDataProvider($dummyValue) + public function testInterceptsWithAnnotationsWhenUsingDataProvider(int $dummyValue): void { // Content of tests/fixtures/unittest_annotation_test: "This is an annotation test dummy". $result = file_get_contents('http://google.com'); + // Just to avoid the dummy to annoy the static analyzers + \assert(\is_int($dummyValue)); $this->assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using annotations with data provider).'); } - public function aDataProvider() + public function dummyDataProvider(): array { - return array( - array(1), - array(2), - ); + return [ + [1], + [2], + ]; } }