1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\Entity\Factory; |
4
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Factory\EntityFactory; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\String\EmailAddressFieldInterface; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\String\IsbnFieldInterface; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String\EmailAddressFieldTrait; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String\IsbnFieldTrait; |
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Validation\EntityValidatorFactory; |
11
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @coversDefaultClass \EdmondsCommerce\DoctrineStaticMeta\Entity\Factory\EntityFactory |
15
|
|
|
*/ |
16
|
|
|
class EntityFactoryTest extends AbstractTest |
17
|
|
|
{ |
18
|
|
|
public const WORK_DIR = AbstractTest::VAR_PATH . '/' . self::TEST_TYPE_LARGE . '/EntityFactoryTest'; |
19
|
|
|
|
20
|
|
|
private const TEST_ENTITY_FQN = self::TEST_PROJECT_ROOT_NAMESPACE . '\\Entities\\EntityFactoryTestEntity'; |
21
|
|
|
protected static $buildOnce = true; |
22
|
|
|
private $entityFqn; |
23
|
|
|
/** |
24
|
|
|
* @var EntityFactory |
25
|
|
|
*/ |
26
|
|
|
private $factory; |
27
|
|
|
|
28
|
|
|
public function setup() |
29
|
|
|
{ |
30
|
|
|
parent::setup(); |
31
|
|
|
if (false === static::$built) { |
32
|
|
|
$this->buildOnce(); |
33
|
|
|
} |
34
|
|
|
$this->setupCopiedWorkDir(); |
35
|
|
|
$this->entityFqn = $this->getCopiedFqn(self::TEST_ENTITY_FQN); |
36
|
|
|
$this->factory = new EntityFactory( |
37
|
|
|
$this->container->get(EntityValidatorFactory::class), |
38
|
|
|
$this->getNamespaceHelper() |
39
|
|
|
); |
40
|
|
|
$this->factory->setEntityManager($this->getEntityManager()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function buildOnce() |
44
|
|
|
{ |
45
|
|
|
$this->getEntityGenerator()->generateEntity(self::TEST_ENTITY_FQN); |
46
|
|
|
$this->getFieldSetter()->setEntityHasField( |
47
|
|
|
self::TEST_ENTITY_FQN, |
48
|
|
|
IsbnFieldTrait::class |
49
|
|
|
); |
50
|
|
|
$this->getFieldSetter()->setEntityHasField( |
51
|
|
|
self::TEST_ENTITY_FQN, |
52
|
|
|
EmailAddressFieldTrait::class |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
static::$built = true; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @test |
60
|
|
|
* @large |
61
|
|
|
* @covers ::create |
62
|
|
|
*/ |
63
|
|
|
public function itCanCreateAnEmptyEntity(): void |
64
|
|
|
{ |
65
|
|
|
$entity = $this->factory->create($this->entityFqn); |
66
|
|
|
self::assertInstanceOf($this->entityFqn, $entity); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @test |
71
|
|
|
* @large |
72
|
|
|
* @covers ::create |
73
|
|
|
*/ |
74
|
|
|
public function itThrowsAnExceptionIfThereIsAnInvalidProperty(): void |
75
|
|
|
{ |
76
|
|
|
$this->expectException(\InvalidArgumentException::class); |
77
|
|
|
$this->factory->create($this->entityFqn, ['invalidProperty' => true]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @test |
82
|
|
|
* @large |
83
|
|
|
* @covers ::create |
84
|
|
|
*/ |
85
|
|
|
public function itCanCreateAnEntityWithValues(): void |
86
|
|
|
{ |
87
|
|
|
$values = [ |
88
|
|
|
IsbnFieldInterface::PROP_ISBN => '978-3-16-148410-0', |
89
|
|
|
EmailAddressFieldInterface::PROP_EMAIL_ADDRESS => '[email protected]', |
90
|
|
|
]; |
91
|
|
|
$entity = $this->factory->create($this->entityFqn, $values); |
92
|
|
|
|
93
|
|
|
self::assertSame($entity->getIsbn(), $values[IsbnFieldInterface::PROP_ISBN]); |
|
|
|
|
94
|
|
|
|
95
|
|
|
self::assertSame($entity->getEmailAddress(), $values[EmailAddressFieldInterface::PROP_EMAIL_ADDRESS]); |
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @test |
100
|
|
|
* @large |
101
|
|
|
* @covers ::createFactoryForEntity |
102
|
|
|
*/ |
103
|
|
|
public function itCanCreateAnEntitySpecificFactory(): void |
104
|
|
|
{ |
105
|
|
|
$entityFactory = $this->factory->createFactoryForEntity($this->entityFqn); |
106
|
|
|
$entityFactoryFqn = $this->getNamespaceHelper()->getFactoryFqnFromEntityFqn($this->entityFqn); |
107
|
|
|
self::assertInstanceOf($entityFactoryFqn, $entityFactory); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.