Skip to content

Commit b7aba28

Browse files
committed
Add testing
Add tests for HttpMethods, fix body mistake Add tests for Body, fix multipart data mistake Add tests for exceptions Readd CI badges Remove PlainText spec
1 parent d9b9043 commit b7aba28

16 files changed

+405
-4
lines changed

.gitattributes

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
spec/ export-ignore
12
.editorconfig export-ignore
23
.gitattributes export-ignore
34
.gitignore export-ignore
5+
.scrutinizer.yml export-ignore
6+
.travis.yml export-ignore
47
CONTRIBUTING.md export-ignore
8+
phpspec.yml.ci export-ignore
9+
phpspec.yml.dist export-ignore

.scrutinizer.yml

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

.travis.yml

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

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
[![Latest Version](https://img.shields.io/github/release/php-http/client.svg?style=flat-square)](https://github.com/php-http/client/releases)
44
[![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/client.svg?style=flat-square)](https://travis-ci.org/php-http/client)
6+
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-http/client.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/client)
7+
[![Quality Score](https://img.shields.io/scrutinizer/g/php-http/client.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/client)
58
[![Total Downloads](https://img.shields.io/packagist/dt/php-http/client.svg?style=flat-square)](https://packagist.org/packages/php-http/client)
69

710
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/php-http/adapter?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
@@ -32,6 +35,13 @@ There is also a virtual package which is versioned together with this contract p
3235
Please see the [official documentation](http://php-http.readthedocs.org/en/latest/).
3336

3437

38+
## Testing
39+
40+
``` bash
41+
$ composer test
42+
```
43+
44+
3545
## Contributing
3646

3747
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

composer.json

+8
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@
1818
"php": ">=5.4",
1919
"psr/http-message": "^1.0"
2020
},
21+
"require-dev": {
22+
"phpspec/phpspec": "^2.2",
23+
"henrikbjorn/phpspec-code-coverage" : "^1.0"
24+
},
2125
"autoload": {
2226
"psr-4": {
2327
"Http\\Client\\": "src/"
2428
}
2529
},
30+
"scripts": {
31+
"test": "vendor/bin/phpspec run",
32+
"test-ci": "vendor/bin/phpspec run -c phpspec.yml.ci"
33+
},
2634
"extra": {
2735
"branch-alias": {
2836
"dev-master": "0.2-dev"

phpspec.yml.ci

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

phpspec.yml.dist

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

spec/Body/CombinedMultipartSpec.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace spec\Http\Client\Body;
4+
5+
use PhpSpec\ObjectBehavior;
6+
7+
class CombinedMultipartSpec extends ObjectBehavior
8+
{
9+
protected $file;
10+
11+
function let()
12+
{
13+
$this->file = tempnam(sys_get_temp_dir(), 'multipart');
14+
15+
$this->beConstructedWith(['data' => 1], ['file' => $this->file], 'boundary');
16+
}
17+
18+
function it_is_initializable()
19+
{
20+
$this->shouldHaveType('Http\Client\Body\CombinedMultipart');
21+
}
22+
23+
function it_is_body()
24+
{
25+
$this->shouldImplement('Http\Client\Body');
26+
}
27+
28+
function it_is_multipart()
29+
{
30+
$this->shouldHaveType('Http\Client\Body\Multipart');
31+
}
32+
33+
function it_has_content_header()
34+
{
35+
$this->getContentHeaders()->shouldReturn(['Content-Type' => 'multipart/form-data; boundary=boundary']);
36+
}
37+
38+
function it_is_streamable()
39+
{
40+
$body = sprintf("--boundary\r\nContent-Disposition: form-data; name=\"data\"\r\n\r\n1\r\n--boundary\r\nContent-Disposition: form-data; name=\"file\"; filename=\"%s\"\r\n\r\n\r\n", basename($this->file));
41+
42+
$this->toStreamable()->shouldReturn($body);
43+
}
44+
}

spec/Body/FilesSpec.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace spec\Http\Client\Body;
4+
5+
use PhpSpec\ObjectBehavior;
6+
7+
class FilesSpec extends ObjectBehavior
8+
{
9+
protected $file;
10+
11+
function let()
12+
{
13+
$this->file = tempnam(sys_get_temp_dir(), 'multipart');
14+
15+
$this->beConstructedWith(['file' => $this->file], 'boundary');
16+
}
17+
18+
function it_is_initializable()
19+
{
20+
$this->shouldHaveType('Http\Client\Body\Files');
21+
}
22+
23+
function it_is_body()
24+
{
25+
$this->shouldImplement('Http\Client\Body');
26+
}
27+
28+
function it_is_multipart()
29+
{
30+
$this->shouldHaveType('Http\Client\Body\Multipart');
31+
}
32+
33+
function it_has_content_header()
34+
{
35+
$this->getContentHeaders()->shouldReturn(['Content-Type' => 'multipart/form-data; boundary=boundary']);
36+
}
37+
38+
function it_is_streamable()
39+
{
40+
$body = sprintf("--boundary\r\nContent-Disposition: form-data; name=\"file\"; filename=\"%s\"\r\n\r\n\r\n", basename($this->file));
41+
42+
$this->toStreamable()->shouldReturn($body);
43+
}
44+
}

spec/Body/MultipartDataSpec.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace spec\Http\Client\Body;
4+
5+
use PhpSpec\ObjectBehavior;
6+
7+
class MultipartDataSpec extends ObjectBehavior
8+
{
9+
function let()
10+
{
11+
$this->beConstructedWith(['data' => 1], 'boundary');
12+
}
13+
14+
function it_is_initializable()
15+
{
16+
$this->shouldHaveType('Http\Client\Body\MultipartData');
17+
}
18+
19+
function it_is_body()
20+
{
21+
$this->shouldImplement('Http\Client\Body');
22+
}
23+
24+
function it_is_multipart()
25+
{
26+
$this->shouldHaveType('Http\Client\Body\Multipart');
27+
}
28+
29+
function it_has_content_header()
30+
{
31+
$this->getContentHeaders()->shouldReturn(['Content-Type' => 'multipart/form-data; boundary=boundary']);
32+
}
33+
34+
function it_is_streamable()
35+
{
36+
$body = "--boundary\r\nContent-Disposition: form-data; name=\"data\"\r\n\r\n1\r\n";
37+
38+
$this->toStreamable()->shouldReturn($body);
39+
}
40+
}

spec/Body/UrlencodedDataSpec.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace spec\Http\Client\Body;
4+
5+
use PhpSpec\ObjectBehavior;
6+
7+
class UrlencodedDataSpec extends ObjectBehavior
8+
{
9+
function let()
10+
{
11+
$this->beConstructedWith(['data1' => 1, 'data2' => 2]);
12+
}
13+
14+
function it_is_initializable()
15+
{
16+
$this->shouldHaveType('Http\Client\Body\UrlencodedData');
17+
}
18+
19+
function it_is_body()
20+
{
21+
$this->shouldImplement('Http\Client\Body');
22+
}
23+
24+
function it_has_content_header()
25+
{
26+
$this->getContentHeaders()->shouldReturn(['Content-Type' => 'application/x-www-form-urlencoded']);
27+
}
28+
29+
function it_is_streamable()
30+
{
31+
$this->toStreamable()->shouldReturn('data1=1&data2=2');
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace spec\Http\Client\Exception;
4+
5+
use PhpSpec\ObjectBehavior;
6+
7+
class InvalidArgumentExceptionSpec extends ObjectBehavior
8+
{
9+
function it_is_initializable()
10+
{
11+
$this->shouldHaveType('Http\Client\Exception\InvalidArgumentException');
12+
}
13+
14+
function it_is_invalid_argument_exception()
15+
{
16+
$this->shouldHaveType('InvalidArgumentException');
17+
}
18+
19+
function it_is_exception()
20+
{
21+
$this->shouldImplement('Http\Client\Exception');
22+
}
23+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace spec\Http\Client\Exception;
4+
5+
use PhpSpec\ObjectBehavior;
6+
7+
class RuntimeExceptionSpec extends ObjectBehavior
8+
{
9+
function it_is_initializable()
10+
{
11+
$this->shouldHaveType('Http\Client\Exception\RuntimeException');
12+
}
13+
14+
function it_is_runtime_exception()
15+
{
16+
$this->shouldHaveType('RuntimeException');
17+
}
18+
19+
function it_is_exception()
20+
{
21+
$this->shouldImplement('Http\Client\Exception');
22+
}
23+
}

0 commit comments

Comments
 (0)