Repository navigation
Expand file tree
/
Copy pathRequestTest.php
More file actions
108 lines (83 loc) · 3.66 KB
/
Copy pathRequestTest.php
File metadata and controls
108 lines (83 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Dingo\Api\Tests\Http\Middleware;
use Mockery as m;
use Dingo\Api\Http\Request;
use Dingo\Api\Routing\Router;
use Dingo\Api\Http\Validation;
use PHPUnit_Framework_TestCase;
use Dingo\Api\Exception\Handler;
use Dingo\Api\Http\Validation\Accept;
use Dingo\Api\Http\Validation\Domain;
use Dingo\Api\Http\Validation\Prefix;
use Dingo\Api\Http\RequestValidator;
use Dingo\Api\Tests\Stubs\ApplicationStub;
use Dingo\Api\Http\Parser\Accept as AcceptParser;
use Illuminate\Http\Request as IlluminateRequest;
use Illuminate\Events\Dispatcher as EventDispatcher;
use Dingo\Api\Contract\Http\Request as RequestContract;
use Dingo\Api\Http\Middleware\Request as RequestMiddleware;
class RequestTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->app = new ApplicationStub;
$this->router = m::mock(Router::class);
$this->validator = new RequestValidator($this->app);
$this->handler = m::mock(Handler::class);
$this->events = new EventDispatcher($this->app);
$this->app->alias(Request::class, RequestContract::class);
$this->middleware = new RequestMiddleware($this->app, $this->handler, $this->router, $this->validator, $this->events);
}
public function tearDown()
{
m::close();
}
public function testNoPrefixOrDomainDoesNotMatch()
{
$this->app[Domain::class] = new Validation\Domain(null);
$this->app[Prefix::class] = new Validation\Prefix(null);
$this->app[Accept::class] = new Validation\Accept(new AcceptParser('vnd', 'api', 'v1', 'json'));
$request = Request::create('foo', 'GET');
$this->middleware->handle($request, function ($handled) use ($request) {
$this->assertSame($handled, $request);
});
}
public function testPrefixMatchesAndSendsRequestThroughRouter()
{
$this->app[Domain::class] = new Validation\Domain(null);
$this->app[Prefix::class] = new Validation\Prefix('/');
$this->app[Accept::class] = new Validation\Accept(new AcceptParser('vnd', 'api', 'v1', 'json'));
$request = IlluminateRequest::create('foo', 'GET');
$this->router->shouldReceive('dispatch')->once();
$this->middleware->handle($request, function () {
//
});
$this->app[Domain::class] = new Validation\Domain(null);
$this->app[Prefix::class] = new Validation\Prefix('bar');
$this->app[Accept::class] = new Validation\Accept(new AcceptParser('vnd', 'api', 'v1', 'json'));
$request = IlluminateRequest::create('bar/foo', 'GET');
$this->router->shouldReceive('dispatch')->once();
$this->middleware->handle($request, function () {
//
});
$request = IlluminateRequest::create('bing/bar/foo', 'GET');
$this->middleware->handle($request, function ($handled) use ($request) {
$this->assertSame($handled, $request);
});
}
public function testDomainMatchesAndSendsRequestThroughRouter()
{
$this->app[Domain::class] = new Validation\Domain('foo.bar');
$this->app[Prefix::class] = new Validation\Prefix(null);
$this->app[Accept::class] = new Validation\Accept(new AcceptParser('vnd', 'api', 'v1', 'json'));
$request = IlluminateRequest::create('http://foo.bar/baz', 'GET');
$this->router->shouldReceive('dispatch')->once();
$this->middleware->handle($request, function () {
//
});
$request = IlluminateRequest::create('http://bing.foo.bar/baz', 'GET');
$this->middleware->handle($request, function ($handled) use ($request) {
$this->assertSame($handled, $request);
});
}
}