Passed
Push — master ( 6f905d...2edd34 )
by Oleg
02:55
created

GetsTest::testCreateClass()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 27
nc 1
nop 0
dl 0
loc 41
rs 8.8571
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Generator\Tests;
5
6
use PHPUnit\Framework\TestCase;
7
use Prophecy\Argument;
8
use SlayerBirden\DFCodeGeneration\CodeLoader;
9
10
class GetsTest extends TestCase
11
{
12
    private $provider;
13
    private $factory;
14
15
    protected function setUp()
16
    {
17
        $this->provider = $this->prophesize(EntityProviderInterface::class);
18
        $this->factory = $this->prophesize(EntityProviderFactoryInterface::class);
19
        $this->factory->create(Argument::any())->willReturn($this->provider->reveal());
20
    }
21
22
    public function testCreateClass()
23
    {
24
        $this->provider->getId()->willReturn(1);
25
        $this->provider->getEntitySpec()->willReturn([
26
            [
27
                'name' => 'id',
28
                'type' => 'integer',
29
                'nullable' => false,
30
            ],
31
            [
32
                'name' => 'name',
33
                'type' => 'string',
34
                'nullable' => true,
35
            ],
36
            [
37
                'name' => 'email',
38
                'type' => 'string',
39
                'nullable' => false,
40
            ],
41
        ]);
42
        $this->provider->getPostParams()->willReturn([
43
            'name' => 'bob',
44
            'email' => '[email protected]',
45
        ]);
46
        $this->provider->getParams()->willReturn([
47
            'id' => 1,
48
            'name' => 'bob',
49
            'email' => '[email protected]',
50
        ]);
51
        $this->provider->getBaseName()->willReturn('User');
52
        $this->provider->getShortName()->willReturn('user');
53
        $this->provider->getEntityClassName()->willReturn('Dummy\\User');
54
        $this->provider->hasUnique()->willReturn(true);
55
        $this->provider->getIdName()->willReturn('id');
56
57
        $gets = new Gets('Dummy\\User', $this->factory->reveal());
58
        $code = $gets->generate();
59
        $this->assertNotEmpty($code);
60
61
        // asserting php code is valid and can be loaded
62
        CodeLoader::loadCode($code, 'GetsCest.php');
63
    }
64
}
65