Test Failed
Push — master ( 25b8d1...f70cb8 )
by Pavel
03:49
created

AccessTest::setUpBeforeClass()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
rs 8.8571
cc 1
eloc 20
nc 1
nop 0
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Tests;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Doctrine\ORM\Tools\SchemaTool;
7
use Doctrine\ORM\Tools\SchemaValidator;
8
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
9
10
class AccessTest extends WebTestCase
11
{
12
    use CrudsTestCaseTrait;
13
    /** @var  EntityManagerInterface */
14
    public static $em;
15
16
    /**
17
     * @throws \Doctrine\ORM\Tools\ToolsException
18
     */
19
    public static function setUpBeforeClass()
20
    {
21
        parent::setUpBeforeClass();
22
        static::$kernel = static::createKernel([]);
23
        static::$kernel->boot();
24
        /** @var EntityManagerInterface $em */
25
        static::$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
26
27
        $metadata = static::$em->getMetadataFactory()->getAllMetadata();
28
        $tool     = new SchemaTool(static::$em);
29
        $tool->dropDatabase();
30
        $tool->createSchema($metadata);
31
        $validator = new SchemaValidator(static::$em);
32
        $errors    = $validator->validateMapping();
33
        static::assertCount(
34
            0,
35
            $errors,
36
            implode(
37
                "\n\n",
38
                array_map(
39
                    function ($l) {
40
                        return implode("\n\n", $l);
41
                    },
42
                    $errors
43
                )
44
            )
45
        );
46
    }
47
48
    public function testEntityRouting()
49
    {
50
        self::bootKernel();
51
52
        $this->doRequest('/api/entity/my-entity/create', 'POST', ['data' => ['publicApiField' => 'my-value']]);
53
        $this->doRequest('/api/entity/my-entity/read', 'GET', ['identifier' => 1]);
54
        $this->doRequest(
55
            '/api/entity/my-entity/update',
56
            'POST',
57
            [
58
                'identifier' => 1,
59
                'data'       => [
60
                    'publicApiField' => 'my-updated-value',
61
                ],
62
            ]
63
        );
64
        $this->doRequest('/api/entity/my-entity/search', 'GET', ['criteria' => []]);
65
        $this->doRequest('/api/entity/my-entity/delete', 'POST', ['identifier' => 1]);
66
    }
67
68
    private function doRequest($path, $method, array $args = [])
69
    {
70
        $client = self::createClient();
71
        $client->request($method, $path, $args);
72
73
        print($path);
74
        print(PHP_EOL);
75
        print((string)$client->getResponse());
76
        print(PHP_EOL);
77
        print(PHP_EOL);
78
        print(PHP_EOL);
79
    }
80
}
81