Passed
Pull Request — master (#21)
by Pavel
06:33
created

RouteAccessibilityTest::setUpBeforeClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Tests\Configuration;
4
5
use ScayTrase\Api\Cruds\Tests\Fixtures\Common\Entity\MyEntity;
6
use ScayTrase\Api\Cruds\Tests\WebTestCase;
7
use Symfony\Bundle\FrameworkBundle\Client;
8
9
class RouteAccessibilityTest extends WebTestCase
10
{
11
    /** @var Client */
12
    private static $client;
13
14
    public static function setUpBeforeClass()
15
    {
16
        self::$client = self::createClient();
17
    }
18
19
    protected function setUp()
20
    {
21
        $this->loadFixtures([]);
22
        $entity = new MyEntity();
23
        $this->getEntityManager()->persist($entity);
24
        $this->getEntityManager()->flush();
25
    }
26
27
    public function getRequests()
28
    {
29
        return [
30
            'create' => ['/api/entity/my-entity/create', 'POST', ['data' => ['publicApiField' => 'my-value']]],
31
            'get' => ['/api/entity/my-entity/get', 'GET', ['identifier' => 1]],
32
            'update' => [
33
                '/api/entity/my-entity/update',
34
                'POST',
35
                [
36
                    'identifier' => 1,
37
                    'data' => [
38
                        'publicApiField' => 'my-updated-value',
39
                        'parent' => null,
40
                    ],
41
                ],
42
            ],
43
            'search' => ['/api/entity/my-entity/search', 'GET', ['criteria' => ['id' => 1]]],
44
            'count' => ['/api/entity/my-entity/count', 'GET', ['criteria' => ['id' => 1]]],
45
            'delete' => ['/api/entity/my-entity/delete', 'POST', ['identifier' => 1]],
46
        ];
47
    }
48
49
    /**
50
     * @dataProvider getRequests
51
     *
52
     * @param string $path
53
     * @param string $method
54
     * @param array $args
55
     */
56
    public function testRequestWasSuccessful($path, $method, array $args = [])
57
    {
58
        self::$client->request($method, $path, $args);
59
        self::assertTrue(self::$client->getResponse()->isSuccessful());
60
    }
61
}
62