1
|
|
|
<?php namespace Phprest\Middleware; |
2
|
|
|
|
3
|
|
|
use Mockery; |
4
|
|
|
use Mockery\MockInterface; |
5
|
|
|
use Phprest\Application; |
6
|
|
|
use Phprest\Config; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
9
|
|
|
|
10
|
|
|
class ApiVersionTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @dataProvider appProvider |
14
|
|
|
* |
15
|
|
|
* @param Application $app |
16
|
|
|
*/ |
17
|
|
|
public function testHandle(Application $app): void |
18
|
|
|
{ |
19
|
|
|
$middleware = new ApiVersion($app); |
20
|
|
|
|
21
|
|
|
/** @var MockInterface $app */ |
22
|
|
|
$app->shouldReceive('handle')->andReturnUsing(function ($request) { |
23
|
|
|
$this->assertInstanceOf(\Phprest\HttpFoundation\Request::class, $request); |
24
|
|
|
|
25
|
|
|
/** @var \Phprest\HttpFoundation\Request $request */ |
26
|
|
|
$this->assertEquals('/2.6/temperatures', $request->getPathInfo()); |
27
|
|
|
}); |
28
|
|
|
|
29
|
|
|
$middleware->handle( |
30
|
|
|
Request::create('/temperatures') |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function appProvider(): array |
35
|
|
|
{ |
36
|
|
|
$app = Mockery::mock(Application::class); |
37
|
|
|
|
38
|
|
|
$config = new Config('test', '2.6'); |
39
|
|
|
$config->getContainer()->add(Application::CONTAINER_ID_VENDOR, $config->getVendor()); |
40
|
|
|
$config->getContainer()->add(Application::CONTAINER_ID_API_VERSION, $config->getApiVersion()); |
41
|
|
|
$config->getContainer()->add(Application::CONTAINER_ID_DEBUG, $config->isDebug()); |
42
|
|
|
|
43
|
|
|
$app->shouldReceive('getConfiguration')->andReturn($config); |
44
|
|
|
$app->shouldReceive('getContainer')->andReturn($config->getContainer()); |
45
|
|
|
|
46
|
|
|
return [[$app]]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function tearDown() |
50
|
|
|
{ |
51
|
|
|
Mockery::close(); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|