File tree Expand file tree Collapse file tree 12 files changed +174
-31
lines changed Expand file tree Collapse file tree 12 files changed +174
-31
lines changed Original file line number Diff line number Diff line change 16
16
],
17
17
"require" : {
18
18
"php" : " >=5.4" ,
19
- "php-http/message-factory" : " ^1.0" ,
20
19
"puli/composer-plugin" : " 1.0.0-beta8" ,
21
20
"puli/discovery" : " 1.0.0-beta8"
22
21
},
23
22
"require-dev" : {
24
- "php-http/message" : " ^0.1" ,
25
- "zendframework/zend-diactoros" : " ^1.0" ,
26
- "guzzlehttp/psr7" : " ^1.0" ,
27
- "php-http/guzzle6-adapter" : " ^0.2" ,
23
+ "php-http/httplug" : " 1.0.0-beta" ,
24
+ "php-http/message-factory" : " ^1.0" ,
28
25
"puli/cli" : " 1.0.0-beta9" ,
29
26
"phpspec/phpspec" : " ^2.4" ,
30
27
"henrikbjorn/phpspec-code-coverage" : " ^1.0"
31
28
},
32
- "suggest" : {
33
- "php-http/message" : " To use Guzzle or Diactoros factories"
34
- },
35
29
"autoload" : {
36
30
"psr-4" : {
37
31
"Http\\ Discovery\\ " : " src/"
38
32
}
39
33
},
34
+ "autoload-dev" : {
35
+ "psr-4" : {
36
+ "spec\\ Http\\ Discovery\\ " : " spec/"
37
+ }
38
+ },
40
39
"scripts" : {
41
40
"test" : " vendor/bin/phpspec run" ,
42
41
"test-ci" : " vendor/bin/phpspec run -c phpspec.yml.ci"
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace spec \Http \Discovery ;
4
+
5
+ use Puli \GeneratedPuliFactory ;
6
+ use Puli \Discovery \Api \Discovery ;
7
+ use Puli \Repository \Api \ResourceRepository ;
8
+ use PhpSpec \ObjectBehavior ;
9
+
10
+ abstract class ClassDiscoveryBehavior extends ObjectBehavior
11
+ {
12
+ function let (
13
+ GeneratedPuliFactory $ puliFactory ,
14
+ ResourceRepository $ repository ,
15
+ Discovery $ discovery
16
+ ) {
17
+ $ puliFactory ->createRepository ()->willReturn ($ repository );
18
+ $ puliFactory ->createDiscovery ($ repository )->willReturn ($ discovery );
19
+
20
+ $ this ->setPuliFactory ($ puliFactory );
21
+ }
22
+
23
+ function letgo ()
24
+ {
25
+ $ this ->resetPuliFactory ();
26
+ }
27
+ }
Original file line number Diff line number Diff line change 2
2
3
3
namespace spec \Http \Discovery ;
4
4
5
- use PhpSpec \ObjectBehavior ;
5
+ use Puli \Discovery \Binding \ClassBinding ;
6
+ use Puli \Discovery \Api \Discovery ;
6
7
7
- class HttpAsyncClientDiscoverySpec extends ObjectBehavior
8
+ class HttpAsyncClientDiscoverySpec extends ClassDiscoveryBehavior
8
9
{
9
10
function it_is_initializable ()
10
11
{
@@ -16,8 +17,15 @@ function it_is_a_class_discovery()
16
17
$ this ->shouldHaveType ('Http\Discovery\ClassDiscovery ' );
17
18
}
18
19
19
- function it_finds_an_http_client ()
20
- {
20
+ function it_finds_an_async_http_client (
21
+ Discovery $ discovery ,
22
+ ClassBinding $ binding
23
+ ) {
24
+ $ binding ->hasParameterValue ('depends ' )->willReturn (false );
25
+ $ binding ->getClassName ()->willReturn ('spec\Http\Discovery\Stub\HttpAsyncClientStub ' );
26
+
27
+ $ discovery ->findBindings ('Http\Client\HttpAsyncClient ' )->willReturn ([$ binding ]);
28
+
21
29
$ this ->find ()->shouldImplement ('Http\Client\HttpAsyncClient ' );
22
30
}
23
31
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace spec \Http \Discovery ;
4
4
5
- use PhpSpec \ObjectBehavior ;
5
+ use Puli \Discovery \Binding \ClassBinding ;
6
+ use Puli \Discovery \Api \Discovery ;
6
7
7
- class HttpClientDiscoverySpec extends ObjectBehavior
8
+ class HttpClientDiscoverySpec extends ClassDiscoveryBehavior
8
9
{
9
10
function it_is_initializable ()
10
11
{
@@ -16,8 +17,15 @@ function it_is_a_class_discovery()
16
17
$ this ->shouldHaveType ('Http\Discovery\ClassDiscovery ' );
17
18
}
18
19
19
- function it_finds_an_http_client ()
20
- {
20
+ function it_finds_an_http_client (
21
+ Discovery $ discovery ,
22
+ ClassBinding $ binding
23
+ ) {
24
+ $ binding ->hasParameterValue ('depends ' )->willReturn (false );
25
+ $ binding ->getClassName ()->willReturn ('spec\Http\Discovery\Stub\HttpClientStub ' );
26
+
27
+ $ discovery ->findBindings ('Http\Client\HttpClient ' )->willReturn ([$ binding ]);
28
+
21
29
$ this ->find ()->shouldImplement ('Http\Client\HttpClient ' );
22
30
}
23
31
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace spec \Http \Discovery ;
4
4
5
- use PhpSpec \ObjectBehavior ;
5
+ use Http \Message \MessageFactory ;
6
+ use Puli \Discovery \Binding \ClassBinding ;
7
+ use Puli \Discovery \Api \Discovery ;
6
8
7
- class MessageFactoryDiscoverySpec extends ObjectBehavior
9
+ class MessageFactoryDiscoverySpec extends ClassDiscoveryBehavior
8
10
{
9
11
function it_is_initializable ()
10
12
{
@@ -16,8 +18,15 @@ function it_is_a_class_discovery()
16
18
$ this ->shouldHaveType ('Http\Discovery\ClassDiscovery ' );
17
19
}
18
20
19
- function it_finds_an_http_message_factory ()
20
- {
21
- $ this ->find ()->shouldHaveType ('Http\Message\MessageFactory ' );
21
+ function it_finds_a_message_factory (
22
+ Discovery $ discovery ,
23
+ ClassBinding $ binding
24
+ ) {
25
+ $ binding ->hasParameterValue ('depends ' )->willReturn (false );
26
+ $ binding ->getClassName ()->willReturn ('spec\Http\Discovery\Stub\MessageFactoryStub ' );
27
+
28
+ $ discovery ->findBindings ('Http\Message\MessageFactory ' )->willReturn ([$ binding ]);
29
+
30
+ $ this ->find ()->shouldImplement ('Http\Message\MessageFactory ' );
22
31
}
23
32
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace spec \Http \Discovery ;
4
4
5
- use PhpSpec \ObjectBehavior ;
5
+ use Puli \Discovery \Binding \ClassBinding ;
6
+ use Puli \Discovery \Api \Discovery ;
6
7
7
- class StreamFactoryDiscoverySpec extends ObjectBehavior
8
+ class StreamFactoryDiscoverySpec extends ClassDiscoveryBehavior
8
9
{
9
10
function it_is_initializable ()
10
11
{
@@ -16,8 +17,15 @@ function it_is_a_class_discovery()
16
17
$ this ->shouldHaveType ('Http\Discovery\ClassDiscovery ' );
17
18
}
18
19
19
- function it_finds_an_http_stream_factory ()
20
- {
21
- $ this ->find ()->shouldHaveType ('Http\Message\StreamFactory ' );
20
+ function it_finds_a_stream_factory (
21
+ Discovery $ discovery ,
22
+ ClassBinding $ binding
23
+ ) {
24
+ $ binding ->hasParameterValue ('depends ' )->willReturn (false );
25
+ $ binding ->getClassName ()->willReturn ('spec\Http\Discovery\Stub\StreamFactoryStub ' );
26
+
27
+ $ discovery ->findBindings ('Http\Message\StreamFactory ' )->willReturn ([$ binding ]);
28
+
29
+ $ this ->find ()->shouldImplement ('Http\Message\StreamFactory ' );
22
30
}
23
31
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace spec \Http \Discovery \Stub ;
4
+
5
+ use Http \Client \HttpAsyncClient ;
6
+ use Psr \Http \Message \RequestInterface ;
7
+
8
+ class HttpAsyncClientStub implements HttpAsyncClient
9
+ {
10
+ public function sendAsyncRequest (RequestInterface $ request )
11
+ {
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace spec \Http \Discovery \Stub ;
4
+
5
+ use Http \Client \HttpClient ;
6
+ use Psr \Http \Message \RequestInterface ;
7
+
8
+ class HttpClientStub implements HttpClient
9
+ {
10
+ public function sendRequest (RequestInterface $ request )
11
+ {
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace spec \Http \Discovery \Stub ;
4
+
5
+ use Http \Message \MessageFactory ;
6
+
7
+ class MessageFactoryStub implements MessageFactory
8
+ {
9
+ public function createRequest (
10
+ $ method ,
11
+ $ uri ,
12
+ array $ headers = [],
13
+ $ body = null ,
14
+ $ protocolVersion = '1.1 '
15
+ ) {
16
+ }
17
+
18
+ public function createResponse (
19
+ $ statusCode = 200 ,
20
+ $ reasonPhrase = null ,
21
+ array $ headers = [],
22
+ $ body = null ,
23
+ $ protocolVersion = '1.1 '
24
+ ) {
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace spec \Http \Discovery \Stub ;
4
+
5
+ use Http \Message \StreamFactory ;
6
+
7
+ class StreamFactoryStub implements StreamFactory
8
+ {
9
+ public function createStream ($ body = null )
10
+ {
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace spec \Http \Discovery \Stub ;
4
+
5
+ use Http \Message \UriFactory ;
6
+
7
+ class UriFactoryStub implements UriFactory
8
+ {
9
+ public function createUri ($ uri )
10
+ {
11
+ }
12
+ }
Original file line number Diff line number Diff line change 2
2
3
3
namespace spec \Http \Discovery ;
4
4
5
- use PhpSpec \ObjectBehavior ;
5
+ use Puli \Discovery \Binding \ClassBinding ;
6
+ use Puli \Discovery \Api \Discovery ;
6
7
7
- class UriFactoryDiscoverySpec extends ObjectBehavior
8
+ class UriFactoryDiscoverySpec extends ClassDiscoveryBehavior
8
9
{
9
10
function it_is_initializable ()
10
11
{
@@ -16,8 +17,15 @@ function it_is_a_class_discovery()
16
17
$ this ->shouldHaveType ('Http\Discovery\ClassDiscovery ' );
17
18
}
18
19
19
- function it_finds_an_http_uri_factory ()
20
- {
21
- $ this ->find ()->shouldHaveType ('Http\Message\UriFactory ' );
20
+ function it_finds_a_uri_factory (
21
+ Discovery $ discovery ,
22
+ ClassBinding $ binding
23
+ ) {
24
+ $ binding ->hasParameterValue ('depends ' )->willReturn (false );
25
+ $ binding ->getClassName ()->willReturn ('spec\Http\Discovery\Stub\UriFactoryStub ' );
26
+
27
+ $ discovery ->findBindings ('Http\Message\UriFactory ' )->willReturn ([$ binding ]);
28
+
29
+ $ this ->find ()->shouldImplement ('Http\Message\UriFactory ' );
22
30
}
23
31
}
You can’t perform that action at this time.
0 commit comments