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