|
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
|
|
|
|