File tree Expand file tree Collapse file tree 3 files changed +83
-1
lines changed Expand file tree Collapse file tree 3 files changed +83
-1
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace spec \Http \Discovery \UriFactory ;
4
+
5
+ use Psr \Http \Message \UriInterface ;
6
+ use PhpSpec \ObjectBehavior ;
7
+
8
+ class DiactorosFactorySpec extends ObjectBehavior
9
+ {
10
+ function let ()
11
+ {
12
+ if (!class_exists ('Zend\Diactoros\Uri ' )) {
13
+ throw new SkippingException ('Diactoros is not available ' );
14
+ }
15
+ }
16
+
17
+ function it_is_initializable ()
18
+ {
19
+ $ this ->shouldHaveType ('Http\Discovery\UriFactory\DiactorosFactory ' );
20
+ }
21
+
22
+ function it_is_a_uri_factory ()
23
+ {
24
+ $ this ->shouldImplement ('Http\Message\UriFactory ' );
25
+ }
26
+
27
+ function it_creates_a_uri_from_string ()
28
+ {
29
+ $ this ->createUri ('http://php-http.org ' )->shouldHaveType ('Psr\Http\Message\UriInterface ' );
30
+ }
31
+
32
+ function it_creates_a_uri_from_uri (UriInterface $ uri )
33
+ {
34
+ $ this ->createUri ($ uri )->shouldReturn ($ uri );
35
+ }
36
+
37
+ function it_throws_an_exception_when_uri_is_invalid ()
38
+ {
39
+ $ this ->shouldThrow ('InvalidArgumentException ' )->duringCreateUri (null );
40
+ }
41
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace spec \Http \Discovery \UriFactory ;
4
+
5
+ use Psr \Http \Message \UriInterface ;
6
+ use PhpSpec \ObjectBehavior ;
7
+
8
+ class GuzzleFactorySpec extends ObjectBehavior
9
+ {
10
+ function it_is_initializable ()
11
+ {
12
+ $ this ->shouldHaveType ('Http\Discovery\UriFactory\GuzzleFactory ' );
13
+ }
14
+
15
+ function it_is_a_uri_factory ()
16
+ {
17
+ $ this ->shouldImplement ('Http\Message\UriFactory ' );
18
+ }
19
+
20
+ function it_creates_a_uri_from_string ()
21
+ {
22
+ $ this ->createUri ('http://php-http.org ' )->shouldHaveType ('Psr\Http\Message\UriInterface ' );
23
+ }
24
+
25
+ function it_creates_a_uri_from_uri (UriInterface $ uri )
26
+ {
27
+ $ this ->createUri ($ uri )->shouldReturn ($ uri );
28
+ }
29
+
30
+ function it_throws_an_exception_when_uri_is_invalid ()
31
+ {
32
+ $ this ->shouldThrow ('InvalidArgumentException ' )->duringCreateUri (null );
33
+ }
34
+ }
Original file line number Diff line number Diff line change 12
12
namespace Http \Discovery \UriFactory ;
13
13
14
14
use Http \Message \UriFactory ;
15
+ use Psr \Http \Message \UriInterface ;
15
16
use Zend \Diactoros \Uri ;
16
17
17
18
/**
@@ -26,6 +27,12 @@ class DiactorosFactory implements UriFactory
26
27
*/
27
28
public function createUri ($ uri )
28
29
{
29
- return new Uri ($ uri );
30
+ if ($ uri instanceof UriInterface) {
31
+ return $ uri ;
32
+ } elseif (is_string ($ uri )) {
33
+ return new Uri ($ uri );
34
+ }
35
+
36
+ throw new \InvalidArgumentException ('URI must be a string or UriInterface ' );
30
37
}
31
38
}
You can’t perform that action at this time.
0 commit comments