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

UpdateTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
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 UpdateTest 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
    /**
23
     * @doesNotPerformAssertions
24
     */
25
    public function testCreateClass()
26
    {
27
        $this->provider->getId()->willReturn(1);
28
        $this->provider->getEntitySpec()->willReturn([
29
            [
30
                'name' => 'id',
31
                'type' => 'integer',
32
                'nullable' => false,
33
            ],
34
            [
35
                'name' => 'name',
36
                'type' => 'string',
37
                'nullable' => true,
38
            ],
39
            [
40
                'name' => 'email',
41
                'type' => 'string',
42
                'nullable' => false,
43
            ],
44
        ]);
45
        $this->provider->getPostParams()->willReturn([
46
            'name' => 'bob',
47
            'email' => '[email protected]',
48
        ]);
49
        $this->provider->getParams()->willReturn([
50
            'id' => 1,
51
            'name' => 'bob',
52
            'email' => '[email protected]',
53
        ]);
54
        $this->provider->getBaseName()->willReturn('User');
55
        $this->provider->getShortName()->willReturn('user');
56
        $this->provider->getEntityClassName()->willReturn('Dummy\\User');
57
        $this->provider->hasUnique()->willReturn(true);
58
        $this->provider->getIdName()->willReturn('id');
59
60
        $update = new Update('Dummy\\User', $this->factory->reveal());
61
62
        $code = $update->generate();
63
        $this->assertNotEmpty($code);
64
65
        // asserting php code is valid and can be loaded
66
        CodeLoader::loadCode($code, 'UpdateCest.php');
67
    }
68
}
69