1+ <?php
2+
3+ namespace Briedis \ApiBuilder \Tests ;
4+
5+ use Briedis \ApiBuilder \RouteBuilder ;
6+ use Briedis \ApiBuilder \Tests \Stubs \GetMethodStub ;
7+ use Briedis \ApiBuilder \Tests \Stubs \InvalidMethodStub ;
8+ use Briedis \ApiBuilder \Tests \Stubs \PostMethodStub ;
9+ use Illuminate \Contracts \Routing \Registrar ;
10+ use Mockery ;
11+ use Mockery \Mock ;
12+ use Mockery \MockInterface ;
13+ use PHPUnit_Framework_TestCase ;
14+
15+ class RouteBuilderTest extends PHPUnit_Framework_TestCase
16+ {
17+ /** @var Registrar|MockInterface|Mock */
18+ private $ mock ;
19+
20+ /** @var RouteBuilder */
21+ private $ builder ;
22+
23+
24+ public static function tearDownAfterClass ()
25+ {
26+ Mockery::close ();
27+ parent ::tearDownAfterClass ();
28+ }
29+
30+ protected function setUp ()
31+ {
32+ parent ::setUp ();
33+ $ this ->mock = Mockery::mock (Registrar::class);
34+ $ this ->builder = new RouteBuilder ($ this ->mock );
35+ }
36+
37+ public function testGetMethod ()
38+ {
39+ $ method = new GetMethodStub ;
40+ $ this ->mock ->shouldReceive ('get ' )->with ($ method ::URI , 'action ' )->once ();
41+ $ this ->builder ->add ($ method , 'action ' );
42+ }
43+
44+ public function testPostMethod ()
45+ {
46+ $ method = new PostMethodStub ;
47+ $ this ->mock ->shouldReceive ('post ' )->with ($ method ::URI , 'controller@method ' )->once ();
48+ $ this ->builder ->add ($ method , 'controller@method ' );
49+ }
50+
51+ public function testInvalidMethod ()
52+ {
53+ $ method = new InvalidMethodStub ;
54+ self ::setExpectedException (\InvalidArgumentException::class);
55+ $ this ->builder ->add ($ method , 'controller@method ' );
56+ }
57+ }
0 commit comments