Skip to content

Commit 35418e4

Browse files
committed
Initial commit
0 parents  commit 35418e4

18 files changed

+419
-0
lines changed

Diff for: .editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

Diff for: .gitattributes

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.editorconfig export-ignore
2+
.gitattributes export-ignore
3+
.github/ export-ignore
4+
.gitignore export-ignore
5+
.php_cs export-ignore
6+
.scrutinizer.yml export-ignore
7+
.styleci.yml export-ignore
8+
.travis.yml export-ignore
9+
phpspec.yml.ci export-ignore
10+
phpspec.yml.dist export-ignore
11+
phpunit.xml.dist export-ignore
12+
spec/ export-ignore
13+
tests/ export-ignore

Diff for: .github/CONTRIBUTING.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Contributing
2+
3+
Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html).

Diff for: .github/ISSUE_TEMPLATE.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
| Q | A
2+
| ------------ | ---
3+
| Bug? | no
4+
| New Feature? | no
5+
| Version | Specific version or SHA of a commit
6+
7+
8+
#### Actual Behavior
9+
10+
What is the actual behavior?
11+
12+
13+
#### Expected Behavior
14+
15+
What is the behavior you expect?
16+
17+
18+
#### Steps to Reproduce
19+
20+
What are the steps to reproduce this bug? Please add code examples,
21+
screenshots or links to GitHub repositories that reproduce the problem.
22+
23+
24+
#### Possible Solutions
25+
26+
If you have already ideas how to solve the issue, add them here.
27+
(remove this section if not needed)

Diff for: .github/PULL_REQUEST_TEMPLATE.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
| Q | A
2+
| --------------- | ---
3+
| Bug fix? | no|yes
4+
| New feature? | no|yes
5+
| BC breaks? | no|yes
6+
| Deprecations? | no|yes
7+
| Related tickets | fixes #X, partially #Y, mentioned in #Z
8+
| Documentation | if this is a new feature, link to pull request in https://github.com/php-http/documentation that adds relevant documentation
9+
| License | MIT
10+
11+
12+
#### What's in this PR?
13+
14+
Explain what the changes in this PR do.
15+
16+
17+
#### Why?
18+
19+
Which problem does the PR fix? (remove this section if you linked an issue above)
20+
21+
22+
#### Example Usage
23+
24+
``` php
25+
// If you added new features, show examples of how to use them here
26+
// (remove this section if not a new feature)
27+
28+
$foo = new Foo();
29+
30+
// Now we can do
31+
$foo->doSomething();
32+
```
33+
34+
35+
#### Checklist
36+
37+
- [ ] Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix
38+
- [ ] Documentation pull request created (if not simply a bugfix)
39+
40+
41+
#### To Do
42+
43+
- [ ] If the PR is not complete but you want to discuss the approach, list what remains to be done here

Diff for: .gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build/
2+
vendor/
3+
composer.lock
4+
phpspec.yml
5+
phpunit.xml

Diff for: .php_cs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
/*
4+
* In order to make it work, fabpot/php-cs-fixer and sllh/php-cs-fixer-styleci-bridge must be installed globally
5+
* with composer.
6+
*
7+
* @link https://github.com/Soullivaneuh/php-cs-fixer-styleci-bridge
8+
* @link https://github.com/FriendsOfPHP/PHP-CS-Fixer
9+
*/
10+
11+
use SLLH\StyleCIBridge\ConfigBridge;
12+
13+
return ConfigBridge::create();

Diff for: .scrutinizer.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
filter:
2+
paths: [src/*]
3+
checks:
4+
php:
5+
code_rating: true
6+
duplication: true
7+
tools:
8+
external_code_coverage: true

Diff for: .styleci.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
preset: symfony
2+
3+
finder:
4+
exclude:
5+
- "spec"
6+
path:
7+
- "src"
8+
- "tests"
9+
10+
enabled:
11+
- short_array_syntax

Diff for: .travis.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
language: php
2+
3+
sudo: false
4+
5+
cache:
6+
directories:
7+
- $HOME/.composer/cache/files
8+
9+
php:
10+
- 5.4
11+
- 5.5
12+
- 5.6
13+
- 7.0
14+
- hhvm
15+
16+
env:
17+
global:
18+
- TEST_COMMAND="composer test"
19+
20+
branches:
21+
except:
22+
- /^analysis-.*$/
23+
24+
matrix:
25+
fast_finish: true
26+
include:
27+
- php: 5.4
28+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci"
29+
30+
before_install:
31+
- travis_retry composer self-update
32+
33+
install:
34+
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
35+
36+
script:
37+
- $TEST_COMMAND
38+
39+
after_success:
40+
- if [[ "$COVERAGE" = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
41+
- if [[ "$COVERAGE" = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Change Log
2+
3+
4+
## 1.0.0 - 2016-05-05
5+
6+
- Initial release

Diff for: LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2015-2016 PHP HTTP Team <[email protected]>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

Diff for: README.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Stopwatch Plugin
2+
3+
[![Latest Version](https://img.shields.io/github/release/php-http/stopwatch-plugin.svg?style=flat-square)](https://github.com/php-http/stopwatch-plugin/releases)
4+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
5+
[![Build Status](https://img.shields.io/travis/php-http/stopwatch-plugin.svg?style=flat-square)](https://travis-ci.org/php-http/stopwatch-plugin)
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)
8+
[![Total Downloads](https://img.shields.io/packagist/dt/php-http/stopwatch-plugin.svg?style=flat-square)](https://packagist.org/packages/php-http/stopwatch-plugin)
9+
10+
**Symfony Stopwatch plugin for HTTPlug.**
11+
12+
13+
## Install
14+
15+
Via Composer
16+
17+
``` bash
18+
$ composer require php-http/stopwatch-plugin
19+
```
20+
21+
22+
## Documentation
23+
24+
Please see the [official documentation](http://docs.php-http.org/en/latest/plugins/stopwatch.html).
25+
26+
27+
## Testing
28+
29+
``` bash
30+
$ composer test
31+
```
32+
33+
34+
## Contributing
35+
36+
Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html).
37+
38+
39+
## Security
40+
41+
If you discover any security related issues, please contact us at [[email protected]](mailto:[email protected]).
42+
43+
44+
## License
45+
46+
The MIT License (MIT). Please see [License File](LICENSE) for more information.

Diff for: composer.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "php-http/stopwatch-plugin",
3+
"description": "Symfony Stopwatch plugin for HTTPlug",
4+
"license": "MIT",
5+
"keywords": ["stopwatch", "http", "httplug", "plugin"],
6+
"homepage": "http://httplug.io",
7+
"authors": [
8+
{
9+
"name": "Márk Sági-Kazár",
10+
"email": "[email protected]"
11+
}
12+
],
13+
"require": {
14+
"php": ">=5.4",
15+
"symfony/stopwatch": "^2.3",
16+
"php-http/client-common": "^1.1"
17+
},
18+
"require-dev": {
19+
"phpspec/phpspec": "^2.5",
20+
"henrikbjorn/phpspec-code-coverage" : "^1.0"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"Http\\Client\\Common\\Plugin\\": "src/"
25+
}
26+
},
27+
"scripts": {
28+
"test": "vendor/bin/phpspec run",
29+
"test-ci": "vendor/bin/phpspec run -c phpspec.yml.ci"
30+
},
31+
"extra": {
32+
"branch-alias": {
33+
"dev-master": "1.0-dev"
34+
}
35+
},
36+
"prefer-stable": true,
37+
"minimum-stability": "dev"
38+
}

Diff for: phpspec.yml.ci

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
suites:
2+
stopwatch_plugin_suite:
3+
namespace: Http\Client\Common\Plugin
4+
psr4_prefix: Http\Client\Common\Plugin
5+
formatter.name: pretty
6+
extensions:
7+
- PhpSpec\Extension\CodeCoverageExtension
8+
code_coverage:
9+
format: clover
10+
output: build/coverage.xml

Diff for: phpspec.yml.dist

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
suites:
2+
stopwatch_plugin_suite:
3+
namespace: Http\Client\Common\Plugin
4+
psr4_prefix: Http\Client\Common\Plugin
5+
formatter.name: pretty

Diff for: spec/StopwatchPluginSpec.php

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace spec\Http\Client\Common\Plugin;
4+
5+
use Http\Client\Exception\NetworkException;
6+
use Http\Promise\FulfilledPromise;
7+
use Http\Promise\RejectedPromise;
8+
use Psr\Http\Message\RequestInterface;
9+
use Psr\Http\Message\ResponseInterface;
10+
use Symfony\Component\Stopwatch\Stopwatch;
11+
use PhpSpec\ObjectBehavior;
12+
13+
class StopwatchPluginSpec extends ObjectBehavior
14+
{
15+
function let(Stopwatch $stopwatch)
16+
{
17+
$this->beConstructedWith($stopwatch);
18+
}
19+
20+
function it_is_initializable(Stopwatch $stopwatch)
21+
{
22+
$this->shouldHaveType('Http\Client\Common\Plugin\StopwatchPlugin');
23+
}
24+
25+
function it_is_a_plugin()
26+
{
27+
$this->shouldImplement('Http\Client\Common\Plugin');
28+
}
29+
30+
function it_records_event(Stopwatch $stopwatch, RequestInterface $request, ResponseInterface $response)
31+
{
32+
$request->getMethod()->willReturn('GET');
33+
$request->getRequestTarget()->willReturn('/');
34+
35+
$stopwatch->start('GET /', 'php_http.request')->shouldBeCalled();
36+
$stopwatch->stop('GET /', 'php_http.request')->shouldBeCalled();
37+
38+
$next = function (RequestInterface $request) use ($response) {
39+
return new FulfilledPromise($response->getWrappedObject());
40+
};
41+
42+
$this->handleRequest($request, $next, function () {});
43+
}
44+
45+
function it_records_event_on_error(Stopwatch $stopwatch, RequestInterface $request)
46+
{
47+
$request->getMethod()->willReturn('GET');
48+
$request->getRequestTarget()->willReturn('/');
49+
50+
$stopwatch->start('GET /', 'php_http.request')->shouldBeCalled();
51+
$stopwatch->stop('GET /', 'php_http.request')->shouldBeCalled();
52+
53+
$next = function (RequestInterface $request) {
54+
return new RejectedPromise(new NetworkException('', $request));
55+
};
56+
57+
$this->handleRequest($request, $next, function () {});
58+
}
59+
}

0 commit comments

Comments
 (0)