Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sagikazarmark committed May 4, 2016
0 parents commit 35418e4
Show file tree
Hide file tree
Showing 18 changed files with 419 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.editorconfig export-ignore
.gitattributes export-ignore
.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
phpspec.yml.dist export-ignore
phpunit.xml.dist export-ignore
spec/ export-ignore
tests/ export-ignore
3 changes: 3 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Contributing

Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html).
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
| Q | A
| ------------ | ---
| Bug? | no
| New Feature? | no
| Version | Specific version or SHA of a commit


#### Actual Behavior

What is the actual behavior?


#### Expected Behavior

What is the behavior you expect?


#### Steps to Reproduce

What are the steps to reproduce this bug? Please add code examples,
screenshots or links to GitHub repositories that reproduce the problem.


#### Possible Solutions

If you have already ideas how to solve the issue, add them here.
(remove this section if not needed)
43 changes: 43 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
| Q | A
| --------------- | ---
| Bug fix? | no|yes
| New feature? | no|yes
| BC breaks? | no|yes
| Deprecations? | no|yes
| Related tickets | fixes #X, partially #Y, mentioned in #Z
| Documentation | if this is a new feature, link to pull request in https://github.com/php-http/documentation that adds relevant documentation
| License | MIT


#### What's in this PR?

Explain what the changes in this PR do.


#### Why?

Which problem does the PR fix? (remove this section if you linked an issue above)


#### Example Usage

``` php
// If you added new features, show examples of how to use them here
// (remove this section if not a new feature)

$foo = new Foo();

// Now we can do
$foo->doSomething();
```


#### Checklist

- [ ] Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix
- [ ] Documentation pull request created (if not simply a bugfix)


#### To Do

- [ ] If the PR is not complete but you want to discuss the approach, list what remains to be done here
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build/
vendor/
composer.lock
phpspec.yml
phpunit.xml
13 changes: 13 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/*
* In order to make it work, fabpot/php-cs-fixer and sllh/php-cs-fixer-styleci-bridge must be installed globally
* with composer.
*
* @link https://github.com/Soullivaneuh/php-cs-fixer-styleci-bridge
* @link https://github.com/FriendsOfPHP/PHP-CS-Fixer
*/

use SLLH\StyleCIBridge\ConfigBridge;

return ConfigBridge::create();
8 changes: 8 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
filter:
paths: [src/*]
checks:
php:
code_rating: true
duplication: true
tools:
external_code_coverage: true
11 changes: 11 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
preset: symfony

finder:
exclude:
- "spec"
path:
- "src"
- "tests"

enabled:
- short_array_syntax
41 changes: 41 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
language: php

sudo: false

cache:
directories:
- $HOME/.composer/cache/files

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

env:
global:
- TEST_COMMAND="composer test"

branches:
except:
- /^analysis-.*$/

matrix:
fast_finish: true
include:
- php: 5.4
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci"

before_install:
- travis_retry composer self-update

install:
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction

script:
- $TEST_COMMAND

after_success:
- if [[ "$COVERAGE" = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [[ "$COVERAGE" = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Change Log


## 1.0.0 - 2016-05-05

- Initial release
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2015-2016 PHP HTTP Team <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Stopwatch Plugin

[![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://img.shields.io/travis/php-http/stopwatch-plugin.svg?style=flat-square)](https://travis-ci.org/php-http/stopwatch-plugin)
[![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.**


## Install

Via Composer

``` bash
$ composer require php-http/stopwatch-plugin
```


## Documentation

Please see the [official documentation](http://docs.php-http.org/en/latest/plugins/stopwatch.html).


## Testing

``` bash
$ composer test
```


## Contributing

Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html).


## Security

If you discover any security related issues, please contact us at [[email protected]](mailto:[email protected]).


## License

The MIT License (MIT). Please see [License File](LICENSE) for more information.
38 changes: 38 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "php-http/stopwatch-plugin",
"description": "Symfony Stopwatch plugin for HTTPlug",
"license": "MIT",
"keywords": ["stopwatch", "http", "httplug", "plugin"],
"homepage": "http://httplug.io",
"authors": [
{
"name": "Márk Sági-Kazár",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.4",
"symfony/stopwatch": "^2.3",
"php-http/client-common": "^1.1"
},
"require-dev": {
"phpspec/phpspec": "^2.5",
"henrikbjorn/phpspec-code-coverage" : "^1.0"
},
"autoload": {
"psr-4": {
"Http\\Client\\Common\\Plugin\\": "src/"
}
},
"scripts": {
"test": "vendor/bin/phpspec run",
"test-ci": "vendor/bin/phpspec run -c phpspec.yml.ci"
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"prefer-stable": true,
"minimum-stability": "dev"
}
10 changes: 10 additions & 0 deletions phpspec.yml.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
suites:
stopwatch_plugin_suite:
namespace: Http\Client\Common\Plugin
psr4_prefix: Http\Client\Common\Plugin
formatter.name: pretty
extensions:
- PhpSpec\Extension\CodeCoverageExtension
code_coverage:
format: clover
output: build/coverage.xml
5 changes: 5 additions & 0 deletions phpspec.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
suites:
stopwatch_plugin_suite:
namespace: Http\Client\Common\Plugin
psr4_prefix: Http\Client\Common\Plugin
formatter.name: pretty
59 changes: 59 additions & 0 deletions spec/StopwatchPluginSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace spec\Http\Client\Common\Plugin;

use Http\Client\Exception\NetworkException;
use Http\Promise\FulfilledPromise;
use Http\Promise\RejectedPromise;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\Stopwatch\Stopwatch;
use PhpSpec\ObjectBehavior;

class StopwatchPluginSpec extends ObjectBehavior
{
function let(Stopwatch $stopwatch)
{
$this->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)
{
$request->getMethod()->willReturn('GET');
$request->getRequestTarget()->willReturn('/');

$stopwatch->start('GET /', 'php_http.request')->shouldBeCalled();
$stopwatch->stop('GET /', '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)
{
$request->getMethod()->willReturn('GET');
$request->getRequestTarget()->willReturn('/');

$stopwatch->start('GET /', 'php_http.request')->shouldBeCalled();
$stopwatch->stop('GET /', 'php_http.request')->shouldBeCalled();

$next = function (RequestInterface $request) {
return new RejectedPromise(new NetworkException('', $request));
};

$this->handleRequest($request, $next, function () {});
}
}
Loading

0 comments on commit 35418e4

Please sign in to comment.