diff --git a/.gitattributes b/.gitattributes index 7ae0617..8284bc2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,7 +3,6 @@ .github/ export-ignore .gitignore export-ignore .php_cs export-ignore -.scrutinizer.yml export-ignore .styleci.yml export-ignore .travis.yml export-ignore phpspec.yml.ci export-ignore diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c686117..4b5b3bb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -88,13 +88,7 @@ jobs: - name: Install dependencies run: | - composer require "friends-of-phpspec/phpspec-code-coverage:^6.1.0" --no-interaction --no-update composer update --prefer-dist --no-interaction --no-progress - name: Execute tests - run: composer test-ci - - - name: Upload coverage - run: | - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml + run: composer test diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 46a7560..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,8 +0,0 @@ -filter: - paths: [src/*] -checks: - php: - code_rating: true - duplication: true -tools: - external_code_coverage: true diff --git a/README.md b/README.md index 6132345..ab9e71c 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ [![Latest Version](https://img.shields.io/github/release/php-http/stopwatch-plugin.svg?style=flat-square)](https://github.com/php-http/stopwatch-plugin/releases) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) [![Build Status](https://github.com/php-http/stopwatch-plugin/actions/workflows/tests.yml/badge.svg)](https://github.com/php-http/stopwatch-plugin/actions/workflows/tests.yml) -[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-http/stopwatch-plugin.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/stopwatch-plugin) -[![Quality Score](https://img.shields.io/scrutinizer/g/php-http/stopwatch-plugin.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/stopwatch-plugin) [![Total Downloads](https://img.shields.io/packagist/dt/php-http/stopwatch-plugin.svg?style=flat-square)](https://packagist.org/packages/php-http/stopwatch-plugin) **Symfony Stopwatch plugin for HTTPlug.** diff --git a/composer.json b/composer.json index 07c4ba8..c79660e 100644 --- a/composer.json +++ b/composer.json @@ -16,16 +16,21 @@ "php-http/client-common": "^1.9 || ^2.0" }, "require-dev": { - "phpspec/phpspec": "^7.0" + "symfony/phpunit-bridge": "^5.3", + "guzzlehttp/psr7": "^2.1" }, "autoload": { "psr-4": { "Http\\Client\\Common\\Plugin\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "Http\\Client\\Common\\Plugin\\Tests\\": "tests/" + } + }, "scripts": { - "test": "vendor/bin/phpspec run", - "test-ci": "vendor/bin/phpspec run -c phpspec.yml.ci" + "test": "vendor/bin/simple-phpunit" }, "extra": { "branch-alias": { diff --git a/phpspec.yml.ci b/phpspec.yml.ci deleted file mode 100644 index f438833..0000000 --- a/phpspec.yml.ci +++ /dev/null @@ -1,10 +0,0 @@ -suites: - stopwatch_plugin_suite: - namespace: Http\Client\Common\Plugin - psr4_prefix: Http\Client\Common\Plugin -formatter.name: pretty -extensions: - FriendsOfPhpSpec\PhpSpec\CodeCoverage\CodeCoverageExtension: ~ -code_coverage: - format: clover - output: build/coverage.xml diff --git a/phpspec.yml.dist b/phpspec.yml.dist deleted file mode 100644 index 045e94e..0000000 --- a/phpspec.yml.dist +++ /dev/null @@ -1,5 +0,0 @@ -suites: - stopwatch_plugin_suite: - namespace: Http\Client\Common\Plugin - psr4_prefix: Http\Client\Common\Plugin -formatter.name: pretty diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..a53763d --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,21 @@ + + + + + ./ + + + ./Resources + ./tests + ./vendor + + + + + + + + ./tests/Unit + + + diff --git a/spec/StopwatchPluginSpec.php b/spec/StopwatchPluginSpec.php deleted file mode 100644 index ba80ba6..0000000 --- a/spec/StopwatchPluginSpec.php +++ /dev/null @@ -1,63 +0,0 @@ -beConstructedWith($stopwatch); - } - - function it_is_initializable(Stopwatch $stopwatch) - { - $this->shouldHaveType('Http\Client\Common\Plugin\StopwatchPlugin'); - } - - function it_is_a_plugin() - { - $this->shouldImplement('Http\Client\Common\Plugin'); - } - - function it_records_event(Stopwatch $stopwatch, RequestInterface $request, ResponseInterface $response, UriInterface $uri) - { - $request->getMethod()->willReturn('GET'); - $request->getUri()->willReturn($uri); - $uri->__toString()->willReturn('http://foo.com/bar'); - - $stopwatch->start('GET http://foo.com/bar', 'php_http.request')->shouldBeCalled(); - $stopwatch->stop('GET http://foo.com/bar', 'php_http.request')->shouldBeCalled(); - - $next = function (RequestInterface $request) use ($response) { - return new FulfilledPromise($response->getWrappedObject()); - }; - - $this->handleRequest($request, $next, function () {}); - } - - function it_records_event_on_error(Stopwatch $stopwatch, RequestInterface $request, UriInterface $uri) - { - $request->getMethod()->willReturn('GET'); - $request->getUri()->willReturn($uri); - $uri->__toString()->willReturn('http://foo.com/bar'); - - $stopwatch->start('GET http://foo.com/bar', 'php_http.request')->shouldBeCalled(); - $stopwatch->stop('GET http://foo.com/bar', 'php_http.request')->shouldBeCalled(); - - $next = function (RequestInterface $request) { - return new RejectedPromise(new NetworkException('', $request)); - }; - - $this->handleRequest($request, $next, function () {}); - } -} diff --git a/tests/Unit/StopwatchPluginTest.php b/tests/Unit/StopwatchPluginTest.php new file mode 100644 index 0000000..33a95b9 --- /dev/null +++ b/tests/Unit/StopwatchPluginTest.php @@ -0,0 +1,83 @@ +stopwatch = new Stopwatch(); + $this->plugin = new StopwatchPlugin($this->stopwatch); + } + + /** + * @test + */ + public function it_records_event(): void + { + // Arrange + $request = new Request('GET', 'https://localhost'); + $response = new Response(); + + $next = function (RequestInterface $request) use ($response) { + return new FulfilledPromise($response); + }; + $first = function (RequestInterface $request) { + throw new LogicException('Should not be called'); + }; + + // Act + $this->plugin->handleRequest($request, $next, $first); + + // Assert + $this->assertCount(1, $this->stopwatch->getSections()); + $this->assertFalse($this->stopwatch->getSectionEvents('__root__')['GET https://localhost']->isStarted()); + } + + /** + * @test + */ + public function it_records_event_on_error(): void + { + // Arrange + $request = new Request('GET', 'https://localhost'); + $response = new Response(); + + $next = function (RequestInterface $request) use ($response) { + return new RejectedPromise(new HttpException('', $request, $response)); + }; + $first = function (RequestInterface $request) { + throw new LogicException('Should not be called'); + }; + + // Act + $this->plugin->handleRequest($request, $next, $first); + + // Assert + $this->assertCount(1, $this->stopwatch->getSections()); + $this->assertFalse($this->stopwatch->getSectionEvents('__root__')['GET https://localhost']->isStarted()); + } +}