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
|
|
View Code Duplication |
public function testPathNotMatches($path, $method) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$container = self::$kernel->getContainer(); |
47
|
|
|
$router = $container->get('router'); |
48
|
|
|
|
49
|
|
|
$context = new RequestContext('', $method); |
50
|
|
|
$router->getMatcher()->setContext($context); |
51
|
|
|
$router->match($path); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @dataProvider getValidRoutes |
56
|
|
|
* |
57
|
|
|
* @param string $path |
58
|
|
|
* @param string $method |
59
|
|
|
*/ |
60
|
|
View Code Duplication |
public function testPathMatches($path, $method) |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$container = self::$kernel->getContainer(); |
63
|
|
|
$router = $container->get('router'); |
64
|
|
|
|
65
|
|
|
$context = new RequestContext('', $method); |
66
|
|
|
$router->getMatcher()->setContext($context); |
67
|
|
|
|
68
|
|
|
$match = $router->match($path); |
69
|
|
|
self::assertNotNull($match); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.