Skip to content

Commit cec043a

Browse files
authored
Merge pull request #21 from ruudk/replace-phpspec
Replace PHPSpec with PHPUnit
2 parents 15502fb + b9f7067 commit cec043a

10 files changed

+113
-99
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
.github/ export-ignore
44
.gitignore export-ignore
55
.php_cs export-ignore
6-
.scrutinizer.yml export-ignore
76
.styleci.yml export-ignore
87
.travis.yml export-ignore
98
phpspec.yml.ci export-ignore

.github/workflows/tests.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,7 @@ jobs:
8888

8989
- name: Install dependencies
9090
run: |
91-
composer require "friends-of-phpspec/phpspec-code-coverage:^6.1.0" --no-interaction --no-update
9291
composer update --prefer-dist --no-interaction --no-progress
9392
9493
- name: Execute tests
95-
run: composer test-ci
96-
97-
- name: Upload coverage
98-
run: |
99-
wget https://scrutinizer-ci.com/ocular.phar
100-
php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml
94+
run: composer test

.scrutinizer.yml

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

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
[![Latest Version](https://img.shields.io/github/release/php-http/stopwatch-plugin.svg?style=flat-square)](https://github.com/php-http/stopwatch-plugin/releases)
44
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
55
[![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)
6-
[![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)
7-
[![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)
86
[![Total Downloads](https://img.shields.io/packagist/dt/php-http/stopwatch-plugin.svg?style=flat-square)](https://packagist.org/packages/php-http/stopwatch-plugin)
97

108
**Symfony Stopwatch plugin for HTTPlug.**

composer.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@
1616
"php-http/client-common": "^1.9 || ^2.0"
1717
},
1818
"require-dev": {
19-
"phpspec/phpspec": "^7.0"
19+
"symfony/phpunit-bridge": "^5.3",
20+
"guzzlehttp/psr7": "^2.1"
2021
},
2122
"autoload": {
2223
"psr-4": {
2324
"Http\\Client\\Common\\Plugin\\": "src/"
2425
}
2526
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"Http\\Client\\Common\\Plugin\\Tests\\": "tests/"
30+
}
31+
},
2632
"scripts": {
27-
"test": "vendor/bin/phpspec run",
28-
"test-ci": "vendor/bin/phpspec run -c phpspec.yml.ci"
33+
"test": "vendor/bin/simple-phpunit"
2934
},
3035
"extra": {
3136
"branch-alias": {

phpspec.yml.ci

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

phpspec.yml.dist

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

phpunit.xml.dist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="./vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true">
3+
<coverage>
4+
<include>
5+
<directory>./</directory>
6+
</include>
7+
<exclude>
8+
<directory>./Resources</directory>
9+
<directory>./tests</directory>
10+
<directory>./vendor</directory>
11+
</exclude>
12+
</coverage>
13+
<php>
14+
<env name="SHELL_VERBOSITY" value="-1"/>
15+
</php>
16+
<testsuites>
17+
<testsuite name="StopwatchPlugin unit tests">
18+
<directory suffix="Test.php">./tests/Unit</directory>
19+
</testsuite>
20+
</testsuites>
21+
</phpunit>

spec/StopwatchPluginSpec.php

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

tests/Unit/StopwatchPluginTest.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Http\Client\Common\Plugin\Tests\Unit;
6+
7+
use GuzzleHttp\Psr7\Request;
8+
use GuzzleHttp\Psr7\Response;
9+
use Http\Client\Common\Plugin\StopwatchPlugin;
10+
use Http\Client\Exception\HttpException;
11+
use Http\Promise\FulfilledPromise;
12+
use Http\Promise\RejectedPromise;
13+
use LogicException;
14+
use PHPUnit\Framework\TestCase;
15+
use Psr\Http\Message\RequestInterface;
16+
use Symfony\Component\Stopwatch\Stopwatch;
17+
18+
final class StopwatchPluginTest extends TestCase
19+
{
20+
/**
21+
* @var Stopwatch
22+
*/
23+
private $stopwatch;
24+
25+
/**
26+
* @var StopwatchPlugin
27+
*/
28+
private $plugin;
29+
30+
public function setUp(): void
31+
{
32+
$this->stopwatch = new Stopwatch();
33+
$this->plugin = new StopwatchPlugin($this->stopwatch);
34+
}
35+
36+
/**
37+
* @test
38+
*/
39+
public function it_records_event(): void
40+
{
41+
// Arrange
42+
$request = new Request('GET', 'https://localhost');
43+
$response = new Response();
44+
45+
$next = function (RequestInterface $request) use ($response) {
46+
return new FulfilledPromise($response);
47+
};
48+
$first = function (RequestInterface $request) {
49+
throw new LogicException('Should not be called');
50+
};
51+
52+
// Act
53+
$this->plugin->handleRequest($request, $next, $first);
54+
55+
// Assert
56+
$this->assertCount(1, $this->stopwatch->getSections());
57+
$this->assertFalse($this->stopwatch->getSectionEvents('__root__')['GET https://localhost']->isStarted());
58+
}
59+
60+
/**
61+
* @test
62+
*/
63+
public function it_records_event_on_error(): void
64+
{
65+
// Arrange
66+
$request = new Request('GET', 'https://localhost');
67+
$response = new Response();
68+
69+
$next = function (RequestInterface $request) use ($response) {
70+
return new RejectedPromise(new HttpException('', $request, $response));
71+
};
72+
$first = function (RequestInterface $request) {
73+
throw new LogicException('Should not be called');
74+
};
75+
76+
// Act
77+
$this->plugin->handleRequest($request, $next, $first);
78+
79+
// Assert
80+
$this->assertCount(1, $this->stopwatch->getSections());
81+
$this->assertFalse($this->stopwatch->getSectionEvents('__root__')['GET https://localhost']->isStarted());
82+
}
83+
}

0 commit comments

Comments
 (0)