1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ScayTrase\Api\Cruds\Tests\Configuration; |
4
|
|
|
|
5
|
|
|
use ScayTrase\Api\Cruds\Tests\WebTestCase; |
6
|
|
|
use Symfony\Component\Routing\RequestContext; |
7
|
|
|
|
8
|
|
|
final class RoutingTestCase extends WebTestCase |
9
|
|
|
{ |
10
|
|
|
public function getValidRoutes() |
11
|
|
|
{ |
12
|
|
|
return [ |
13
|
|
|
'valid create POST' => ['/api/entity/my-entity/create', 'POST'], |
14
|
|
|
'valid get GET' => ['/api/entity/my-entity/get', 'GET'], |
15
|
|
|
'valid get POST' => ['/api/entity/my-entity/get', 'POST'], |
16
|
|
|
'valid update POST' => ['/api/entity/my-entity/update', 'POST'], |
17
|
|
|
'valid delete POST' => ['/api/entity/my-entity/delete', 'POST'], |
18
|
|
|
'valid search GET' => ['/api/entity/my-entity/search', 'GET'], |
19
|
|
|
'valid search POST' => ['/api/entity/my-entity/search', 'POST'], |
20
|
|
|
'valid count GET' => ['/api/entity/my-entity/count', 'GET'], |
21
|
|
|
'valid count POST' => ['/api/entity/my-entity/count', 'POST'], |
22
|
|
|
]; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getInvalidRoutes() |
26
|
|
|
{ |
27
|
|
|
return [ |
28
|
|
|
'invalid create GET' => ['/api/entity/my-entity/create', 'GET'], |
29
|
|
|
'invalid update GET' => ['/api/entity/my-entity/update', 'GET'], |
30
|
|
|
'invalid delete POST' => ['/api/entity/my-entity/delete', 'GET'], |
31
|
|
|
]; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @dataProvider getInvalidRoutes |
36
|
|
|
* @expectedException \Symfony\Component\Routing\Exception\MethodNotAllowedException |
37
|
|
|
* |
38
|
|
|
* @param $path |
39
|
|
|
* @param $method |
40
|
|
|
*/ |
41
|
|
|
public function testPathNotMatches($path, $method) |
42
|
|
|
{ |
43
|
|
|
$this->createRouter($method)->match($path); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @dataProvider getValidRoutes |
48
|
|
|
* |
49
|
|
|
* @param string $path |
50
|
|
|
* @param string $method |
51
|
|
|
*/ |
52
|
|
|
public function testPathMatches($path, $method) |
53
|
|
|
{ |
54
|
|
|
self::assertNotNull($this->createRouter($method)->match($path)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param $method |
59
|
|
|
* |
60
|
|
|
* @return object|\Symfony\Bundle\FrameworkBundle\Routing\Router |
61
|
|
|
*/ |
62
|
|
|
private function createRouter($method) |
63
|
|
|
{ |
64
|
|
|
$container = self::$kernel->getContainer(); |
65
|
|
|
$router = $container->get('router'); |
66
|
|
|
|
67
|
|
|
$context = new RequestContext('', $method); |
68
|
|
|
$router->getMatcher()->setContext($context); |
69
|
|
|
|
70
|
|
|
return $router; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|