Skip to content

Replace PHPSpec with PHPUnit #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions .scrutinizer.yml

This file was deleted.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**
Expand Down
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 0 additions & 10 deletions phpspec.yml.ci

This file was deleted.

5 changes: 0 additions & 5 deletions phpspec.yml.dist

This file was deleted.

21 changes: 21 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<coverage>
<include>
<directory>./</directory>
</include>
<exclude>
<directory>./Resources</directory>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<php>
<env name="SHELL_VERBOSITY" value="-1"/>
</php>
<testsuites>
<testsuite name="StopwatchPlugin unit tests">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
</phpunit>
63 changes: 0 additions & 63 deletions spec/StopwatchPluginSpec.php

This file was deleted.

83 changes: 83 additions & 0 deletions tests/Unit/StopwatchPluginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

declare(strict_types=1);

namespace Http\Client\Common\Plugin\Tests\Unit;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Http\Client\Common\Plugin\StopwatchPlugin;
use Http\Client\Exception\HttpException;
use Http\Promise\FulfilledPromise;
use Http\Promise\RejectedPromise;
use LogicException;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestInterface;
use Symfony\Component\Stopwatch\Stopwatch;

final class StopwatchPluginTest extends TestCase
{
/**
* @var Stopwatch
*/
private $stopwatch;

/**
* @var StopwatchPlugin
*/
private $plugin;

public function setUp(): void
{
$this->stopwatch = new Stopwatch();
$this->plugin = new StopwatchPlugin($this->stopwatch);
}

/**
* @test
*/
public function it_records_event(): void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the phpunit convention is to have methods start with test and then we would not need the annotation.

i don't know how much people use this form or the other form (but all things i work on have the testXY form). wdyt of renaming this to testRecordEvent, and the other testRecordError ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both are fine.. in our code base we only use it_should_be.... together with @test
I decided to keep the original names from phpspec... given there are just 2, does it really matter? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, does not really matter. just noticed and wanted to discuss it. fine for me.

{
// 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());
}
}