|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ScayTrase\Api\Cruds\Tests\Configuration; |
|
4
|
|
|
|
|
5
|
|
|
use ScayTrase\Api\Cruds\Tests\AbstractCrudsWebTest; |
|
6
|
|
|
use Symfony\Component\Routing\Exception\MethodNotAllowedException; |
|
7
|
|
|
use Symfony\Component\Routing\Exception\ResourceNotFoundException; |
|
8
|
|
|
use Symfony\Component\Routing\RequestContext; |
|
9
|
|
|
|
|
10
|
|
|
class RoutingTest extends AbstractCrudsWebTest |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @dataProvider getKernelClasses |
|
15
|
|
|
* |
|
16
|
|
|
* @param $kernel |
|
17
|
|
|
*/ |
|
18
|
|
|
public function testEntityRouting($kernel) |
|
19
|
|
|
{ |
|
20
|
|
|
self::createAndBootKernel($kernel); |
|
21
|
|
|
|
|
22
|
|
|
$this->matchPath('/api/entity/my-entity/create', 'POST'); |
|
23
|
|
|
$this->matchPath('/api/entity/my-entity/create', 'GET', true); |
|
24
|
|
|
$this->matchPath('/api/entity/my-entity/get', 'GET'); |
|
25
|
|
|
$this->matchPath('/api/entity/my-entity/get', 'POST'); |
|
26
|
|
|
$this->matchPath('/api/entity/my-entity/update', 'POST'); |
|
27
|
|
|
$this->matchPath('/api/entity/my-entity/update', 'GET', true); |
|
28
|
|
|
$this->matchPath('/api/entity/my-entity/delete', 'POST'); |
|
29
|
|
|
$this->matchPath('/api/entity/my-entity/delete', 'GET', true); |
|
30
|
|
|
$this->matchPath('/api/entity/my-entity/search', 'GET'); |
|
31
|
|
|
$this->matchPath('/api/entity/my-entity/search', 'POST'); |
|
32
|
|
|
$this->matchPath('/api/entity/my-entity/count', 'GET'); |
|
33
|
|
|
$this->matchPath('/api/entity/my-entity/count', 'POST'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
private function matchPath($path, $method = 'GET', $catch = false) |
|
37
|
|
|
{ |
|
38
|
|
|
$container = self::$kernel->getContainer(); |
|
39
|
|
|
$router = $container->get('router'); |
|
40
|
|
|
|
|
41
|
|
|
$context = new RequestContext('', $method); |
|
42
|
|
|
$router->getMatcher()->setContext($context); |
|
43
|
|
|
|
|
44
|
|
|
try { |
|
45
|
|
|
$router->match($path); |
|
46
|
|
|
} catch (MethodNotAllowedException $exception) { |
|
47
|
|
|
if (!$catch) { |
|
48
|
|
|
self::fail( |
|
49
|
|
|
sprintf( |
|
50
|
|
|
'Method %s not allowed. Allowed methods are: %s', |
|
51
|
|
|
$context->getMethod(), |
|
52
|
|
|
implode(', ', $exception->getAllowedMethods()) |
|
53
|
|
|
) |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
} catch (ResourceNotFoundException $exception) { |
|
57
|
|
|
if (!$catch) { |
|
58
|
|
|
self::fail(sprintf('Resource not found: %s', $path)); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|