|
1 <?php |
|
2 |
|
3 use Mockery as m; |
|
4 |
|
5 use CorpusParole\Services\GeonamesResolverException; |
|
6 |
|
7 /** |
|
8 * |
|
9 */ |
|
10 class GeonamesControllerTest extends TestCase { |
|
11 |
|
12 private $geonamesResolver; |
|
13 |
|
14 public function setUp() { |
|
15 |
|
16 parent::setup(); |
|
17 |
|
18 // create a mock of the post repository interface and inject it into the |
|
19 // IoC container |
|
20 $this->geonamesResolver = m::mock('CorpusParole\Services\GeonamesResolverInterface'); |
|
21 $this->app->instance('CorpusParole\Services\GeonamesResolverInterface', $this->geonamesResolver); |
|
22 } |
|
23 |
|
24 public function tearDown() { |
|
25 m::close(); |
|
26 parent::tearDown(); |
|
27 } |
|
28 |
|
29 public function testShow() { |
|
30 $this->geonamesResolver |
|
31 ->shouldReceive('getLabels') |
|
32 ->with(['2968801', '2988507', '6255148']) |
|
33 ->once() |
|
34 ->andReturn(['2968801' => 'Villedieu-les-Poêles', '2988507' => 'Paris', '6255148' => 'Europe']); |
|
35 |
|
36 $response = $this->get('/api/v1/geonames/2968801,2988507,6255148')-> |
|
37 seeJsonEquals(['geonamesids' => ['2968801' => 'Villedieu-les-Poêles', '2988507' => 'Paris', '6255148' => 'Europe']]); |
|
38 } |
|
39 |
|
40 public function testShowOne() { |
|
41 $this->geonamesResolver |
|
42 ->shouldReceive('getLabels') |
|
43 ->with(['2968801']) |
|
44 ->once() |
|
45 ->andReturn([ |
|
46 '2968801' => 'Villedieu-les-Poêles' |
|
47 ]); |
|
48 $response = $this->get('/api/v1/geonames/2968801')-> |
|
49 seeJsonEquals(['geonamesids' => [ |
|
50 '2968801' => 'Villedieu-les-Poêles' |
|
51 ]]); |
|
52 } |
|
53 |
|
54 public function testShowUnknown() { |
|
55 $this->geonamesResolver |
|
56 ->shouldReceive('getLabels') |
|
57 ->with(['12345']) |
|
58 ->once() |
|
59 ->andReturn([ |
|
60 '12345' => null |
|
61 ]); |
|
62 $response = $this->get('/api/v1/geonames/12345')-> |
|
63 seeJsonEquals(['geonamesids' => [ |
|
64 '12345' => null |
|
65 ]]); |
|
66 } |
|
67 |
|
68 public function testShowMalformed() { |
|
69 $this->geonamesResolver |
|
70 ->shouldReceive('getLabels') |
|
71 ->with(['abcdef','ghij']) |
|
72 ->once() |
|
73 ->andThrow('CorpusParole\Services\GeonamesResolverException', "GeonamesId not in correct format", 400); |
|
74 $response = $this->get('/api/v1/geonames/abcdef,ghij'); |
|
75 |
|
76 $this->assertResponseStatus(400); |
|
77 } |
|
78 |
|
79 } |