1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EllipseSynergie\ApiResponse\Tests\Laravel; |
4
|
|
|
|
5
|
|
|
use League\Fractal\Manager; |
6
|
|
|
use Mockery as m; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class ResponseTest |
10
|
|
|
* |
11
|
|
|
* @package EllipseSynergie\ApiResponse\Tests\Laravel |
12
|
|
|
* @author Maxime Beaudoin <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class ResponseTest extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
public function testErrorWrongArgsValidator() |
17
|
|
|
{ |
18
|
|
|
$messageBag = m::mock('Illuminate\Support\MessageBag'); |
19
|
|
|
$messageBag->shouldReceive('toArray')->andReturn(['foo' => 'bar']); |
20
|
|
|
|
21
|
|
|
$validator = m::mock('Illuminate\Contracts\Validation\Validator'); |
22
|
|
|
$validator->shouldReceive('getMessageBag')->once()->andReturn($messageBag); |
23
|
|
|
$response = new ResponseFake(new Manager()); |
24
|
|
|
|
25
|
|
|
$response->errorWrongArgsValidator($validator); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testWithPaginatorWorkProperly() |
29
|
|
|
{ |
30
|
|
|
$paginator = m::mock('Illuminate\Contracts\Pagination\LengthAwarePaginator'); |
31
|
|
|
$paginator->shouldReceive('items')->andReturn([['foo' => 'bar']]); |
32
|
|
|
$paginator->shouldReceive('currentPage')->andReturn(1); |
33
|
|
|
$paginator->shouldReceive('lastPage')->andReturn(2); |
34
|
|
|
$paginator->shouldReceive('total')->andReturn(3); |
35
|
|
|
$paginator->shouldReceive('perPage')->andReturn(1); |
36
|
|
|
$paginator->shouldReceive('url')->andReturn('localhost'); |
37
|
|
|
$paginator->shouldReceive('count')->andReturn(3); |
38
|
|
|
$paginator->shouldReceive('appends')->andReturn([['foo' => 'bar']]); |
39
|
|
|
|
40
|
|
|
$response = new ResponseFake(new Manager()); |
41
|
|
|
|
42
|
|
|
$result = $response->withPaginator($paginator, function ($data) { |
43
|
|
|
return $data; |
44
|
|
|
}, 'data', ['foo' => 'bar']); |
45
|
|
|
|
46
|
|
|
$this->assertSame(['foo' => 'bar'], $result['data'][0]); |
47
|
|
|
$this->assertSame('bar', $result['meta']['foo']); |
48
|
|
|
$this->assertSame( |
49
|
|
|
[ |
50
|
|
|
'total' => 3, |
51
|
|
|
'count' => 3, |
52
|
|
|
'per_page' => 1, |
53
|
|
|
'current_page' => 1, |
54
|
|
|
'total_pages' => 2, |
55
|
|
|
'links' => [ |
56
|
|
|
'next' => 'localhost' |
57
|
|
|
], |
58
|
|
|
], |
59
|
|
|
$result['meta']['pagination'] |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function tearDown() |
64
|
|
|
{ |
65
|
|
|
m::close(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|