Skip to content

Commit 667fc6b

Browse files
committed
Initial commit
0 parents  commit 667fc6b

21 files changed

+803
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
charset = utf-8
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
indent_style = space
9+
indent_size = 4
10+
11+
[*.yml*]
12+
indent_style = space
13+
indent_size = 2

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
spec/ export-ignore
2+
.editorconfig export-ignore
3+
.gitattributes export-ignore
4+
.gitignore export-ignore
5+
.scrutinizer.yml export-ignore
6+
.travis.yml export-ignore
7+
CONTRIBUTING.md export-ignore
8+
phpspec.yml.ci export-ignore
9+
phpspec.yml.dist export-ignore

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build/
2+
vendor/
3+
composer.lock
4+
phpspec.yml

.scrutinizer.yml

Lines changed: 8 additions & 0 deletions
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

.travis.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
language: php
2+
3+
php:
4+
- 5.4
5+
- 5.5
6+
- 5.6
7+
- 7.0
8+
- hhvm
9+
10+
matrix:
11+
allow_failures:
12+
- php: 7.0
13+
- php: hhvm
14+
include:
15+
- php: 5.5
16+
env:
17+
- COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
18+
- PHPSPEC_FLAGS="-c phpspec.yml.ci"
19+
- COVERAGE=true
20+
21+
install:
22+
- travis_retry composer self-update
23+
- if [[ "$TRAVIS_PHP_VERSION" == "5.4" ]]; then composer remove "zendframework/zend-diactoros" --dev --no-update; fi
24+
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-source --no-interaction
25+
26+
script: vendor/bin/phpspec run ${PHPSPEC_FLAGS}
27+
28+
after_script:
29+
- if [[ "$COVERAGE" = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
30+
- if [[ "$COVERAGE" = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Change Log
2+
3+
4+
## Unreleased

CONTRIBUTING.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributing
2+
3+
If you're here, you would like to contribute to this repository and you're really welcome!
4+
5+
6+
## Coding standard
7+
8+
This repository follows the [PSR-2 standard](http://www.php-fig.org/psr/psr-2/) and so, if you want to contribute,
9+
you must follow these rules.
10+
11+
12+
## Feature request
13+
14+
If you think a feature is missing, please report it or even better implement it :). If you report it, describe the more
15+
precisely what you would like to see implemented and we will discuss what is the best approach for it. If you can do
16+
some search before submitting it and link the resources to your description, you're awesome! It will allow me to more
17+
easily understood/implement it.
18+
19+
20+
## Bug report
21+
22+
If you think you have detected a bug or a doc issue, please report it or even better fix it :). If you report it,
23+
please be the more precise possible. Here a little list of required informations:
24+
25+
* Precise description of the bug.
26+
27+
28+
## Bug fix
29+
30+
If you're here, you are going to fix a bug and you're the best! To do it, first fork the repository, clone it and
31+
create a new branch with the following commands:
32+
33+
``` bash
34+
$ git clone [email protected]:your-name/repo-name.git
35+
$ git checkout -b bug-fix-description
36+
```
37+
38+
Then, install the dependencies through [Composer](https://getcomposer.org/):
39+
40+
``` bash
41+
$ composer install
42+
```
43+
44+
When you're on the new branch with the dependencies, code as much as you want and when the fix is ready, don't commit
45+
it immediately. Before, you will need to add tests and update the doc. For the tests, everything is tested with
46+
[PHPUnit](http://phpunit.de/) and the doc is in the markdown format under the `doc` directory.
47+
48+
To run the tests, use the following command:
49+
50+
``` bash
51+
$ vendor/bin/phpunit
52+
```
53+
54+
When you have fixed the bug, tested it and documented it, you can commit and push it with the following commands:
55+
56+
``` bash
57+
$ git commit -m "Bug fix description"
58+
$ git push origin bug-fix-description
59+
```
60+
61+
If you have reworked you patch, please squash all your commits in a single one with the following commands (here, we
62+
will assume you would like to squash 3 commits in a single one):
63+
64+
``` bash
65+
$ git rebase -i HEAD~3
66+
```
67+
68+
If your branch conflicts with the master branch, you will need to rebase and repush it with the following commands:
69+
70+
``` bash
71+
$ git remote add upstream [email protected]:php-http/repo-name.git
72+
$ git pull --rebase upstream master
73+
$ git push origin bug-fix-description -f
74+
```

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2015 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.

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# HTTP Guesser
2+
3+
[![Latest Version](https://img.shields.io/github/release/php-http/guesser.svg?style=flat-square)](https://github.com/php-http/guesser/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/guesser.svg?style=flat-square)](https://travis-ci.org/php-http/guesser)
6+
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-http/guesser.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/guesser)
7+
[![Quality Score](https://img.shields.io/scrutinizer/g/php-http/guesser.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/guesser)
8+
[![HHVM Status](https://img.shields.io/hhvm/php-http/guesser.svg?style=flat-square)](http://hhvm.h4cc.de/package/php-http/guesser)
9+
[![Total Downloads](https://img.shields.io/packagist/dt/php-http/guesser.svg?style=flat-square)](https://packagist.org/packages/php-http/guesser)
10+
11+
**Guesses adapters and message factories.**
12+
13+
14+
## Install
15+
16+
Via Composer
17+
18+
``` bash
19+
$ composer require php-http/guesser
20+
```
21+
22+
23+
## Usage
24+
25+
Guesser is a static container to easy auto initialization of objects.
26+
27+
Currently the following guessers are in the package:
28+
29+
- Adapter
30+
- Message Factory
31+
32+
33+
## Testing
34+
35+
``` bash
36+
$ phpspec run
37+
```
38+
39+
40+
## Contributing
41+
42+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
43+
44+
45+
## Security
46+
47+
If you discover any security related issues, please contact us at [[email protected]](mailto:[email protected]).
48+
49+
50+
## License
51+
52+
The MIT License (MIT). Please see [License File](LICENSE) for more information.

composer.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "php-http/guesser",
3+
"description": "Guesses adapters and message factories",
4+
"license": "MIT",
5+
"keywords": ["http", "guesser", "adapter", "message", "factory"],
6+
"homepage": "http://php-http.org",
7+
"authors": [
8+
{
9+
"name": "Eric GELOEN",
10+
"email": "[email protected]"
11+
},
12+
{
13+
"name": "Márk Sági-Kazár",
14+
"email": "[email protected]"
15+
}
16+
],
17+
"require": {
18+
"php": ">=5.4",
19+
"php-http/message-factory": "^0.1"
20+
},
21+
"require-dev": {
22+
"zendframework/zend-diactoros": "~1.0",
23+
"guzzlehttp/psr7": "~1.0",
24+
"phpspec/phpspec": "~2.1",
25+
"henrikbjorn/phpspec-code-coverage" : "~1.0"
26+
},
27+
"suggest": {
28+
"zendframework/zend-diactoros": "Used with Diactoros MessageFactory",
29+
"guzzlehttp/psr7": "Used with Guzzle PSR-7 MessageFactory"
30+
},
31+
"autoload": {
32+
"psr-4": {
33+
"Http\\Guesser\\": "src/"
34+
}
35+
},
36+
"extra": {
37+
"branch-alias": {
38+
"dev-master": "0.1-dev"
39+
}
40+
},
41+
"prefer-stable": true,
42+
"minimum-stability": "dev"
43+
}

phpspec.yml.ci

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
suites:
2+
guesser_suite:
3+
namespace: Http\Guesser
4+
psr4_prefix: Http\Guesser
5+
extensions:
6+
- PhpSpec\Extension\CodeCoverageExtension
7+
formatter.name: pretty
8+
code_coverage:
9+
format: clover
10+
output: build/coverage.xml

phpspec.yml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
suites:
2+
guesser_suite:
3+
namespace: Http\Guesser
4+
psr4_prefix: Http\Guesser
5+
formatter.name: pretty

spec/HttpAdapterGuesserSpec.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace spec\Http\Guesser;
4+
5+
use PhpSpec\ObjectBehavior;
6+
7+
class HttpAdapterGuesserSpec extends ObjectBehavior
8+
{
9+
function it_is_initializable()
10+
{
11+
$this->shouldHaveType('Http\Guesser\HttpAdapterGuesser');
12+
}
13+
14+
function it_registers_a_factory()
15+
{
16+
$this->reset();
17+
18+
$this->register('guzzle6', 'spec\Http\Guesser\AnotherGuzzle6HttpAdapter');
19+
20+
$this->guess()->shouldHaveType('spec\Http\Guesser\AnotherGuzzle6HttpAdapter');
21+
}
22+
23+
function it_resets_cache_when_a_factory_is_registered()
24+
{
25+
$this->reset();
26+
27+
$firstGuess = $this->guess();
28+
29+
$this->register('guzzle6', 'spec\Http\Guesser\AnotherGuzzle6HttpAdapter');
30+
31+
$this->guess()->shouldNotBe($firstGuess);
32+
}
33+
34+
function it_caches_guess()
35+
{
36+
$this->reset();
37+
38+
$firstGuess = $this->guess()->shouldHaveType('spec\Http\Guesser\Guzzle6HttpAdapter');
39+
40+
$this->guess()->shouldReturn($firstGuess);
41+
}
42+
43+
function it_guesses_guzzle6_then_guzzle5_by_default()
44+
{
45+
$this->reset();
46+
47+
$this->guess()->shouldHaveType('spec\Http\Guesser\Guzzle6HttpAdapter');
48+
49+
$this->register('guzzle6', 'invalid', '');
50+
51+
$this->guess()->shouldHaveType('spec\Http\Guesser\Guzzle5HttpAdapter');
52+
}
53+
54+
function it_throws_an_exception_when_no_message_factory_is_found()
55+
{
56+
$this->reset();
57+
58+
$this->register('guzzle6', 'invalid', '');
59+
$this->register('guzzle5', 'invalid', '');
60+
61+
$this->shouldThrow('Http\Guesser\CannotGuessException')->duringGuess();
62+
}
63+
64+
function reset()
65+
{
66+
$this->register('guzzle5', 'spec\Http\Guesser\Guzzle5HttpAdapter');
67+
$this->register('guzzle6', 'spec\Http\Guesser\Guzzle6HttpAdapter');
68+
}
69+
}
70+
71+
class Guzzle5HttpAdapter {}
72+
class Guzzle6HttpAdapter {}
73+
class AnotherGuzzle6HttpAdapter {}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace spec\Http\Guesser\MessageFactory;
4+
5+
use Psr\Http\Message\StreamInterface;
6+
use PhpSpec\Exception\Example\SkippingException;
7+
use PhpSpec\ObjectBehavior;
8+
9+
class DiactorosFactorySpec extends ObjectBehavior
10+
{
11+
function let()
12+
{
13+
if (!class_exists('Zend\Diactoros\Request')) {
14+
throw new SkippingException('Diactoros is not available');
15+
}
16+
}
17+
18+
function it_is_initializable()
19+
{
20+
$this->shouldHaveType('Http\Guesser\MessageFactory\DiactorosFactory');
21+
}
22+
23+
function it_is_a_message_factory()
24+
{
25+
$this->shouldImplement('Http\Message\MessageFactory');
26+
}
27+
28+
function it_creates_a_request()
29+
{
30+
$this->createRequest('GET', '/')->shouldHaveType('Psr\Http\Message\RequestInterface');
31+
}
32+
33+
function it_creates_a_response()
34+
{
35+
$this->createResponse()->shouldHaveType('Psr\Http\Message\ResponseInterface');
36+
}
37+
}

0 commit comments

Comments
 (0)