|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Small\CodeGeneration\Creation\Src\Entity\Factories; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\Factories\AbstractEntityFactoryCreator; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\Factory\FileFactory; |
|
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\Factory\FindReplaceFactory; |
|
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\File\Writer; |
|
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper; |
|
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Config; |
|
11
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Small\ConfigTest; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\Factories\AbstractEntityFactoryCreator |
|
16
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\AbstractCreator |
|
17
|
|
|
* @small |
|
18
|
|
|
*/ |
|
19
|
|
|
class AbstractEntityFactoryCreatorTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @test |
|
23
|
|
|
*/ |
|
24
|
|
|
public function itWontLetYouPassAnewObjectFqn() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->expectException(\RuntimeException::class); |
|
27
|
|
|
$this->expectExceptionMessage('You should not pass a new object FQN to this creator'); |
|
28
|
|
|
$this->getCreator()->createTargetFileObject('\\Some\\Fqn'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
private function getCreator(): AbstractEntityFactoryCreator |
|
32
|
|
|
{ |
|
33
|
|
|
$namespaceHelper = new NamespaceHelper(); |
|
34
|
|
|
$config = new Config(ConfigTest::SERVER); |
|
35
|
|
|
|
|
36
|
|
|
return new AbstractEntityFactoryCreator( |
|
37
|
|
|
new FileFactory($namespaceHelper, $config), |
|
38
|
|
|
$namespaceHelper, |
|
39
|
|
|
new Writer(), |
|
40
|
|
|
$config, |
|
41
|
|
|
new FindReplaceFactory() |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @test |
|
47
|
|
|
*/ |
|
48
|
|
|
public function itCanCreateANewAbstractEntityFactory(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$file = $this->getCreator() |
|
51
|
|
|
->setProjectRootNamespace('My\\Test\\Project') |
|
52
|
|
|
->createTargetFileObject() |
|
53
|
|
|
->getTargetFile(); |
|
54
|
|
|
$expected = '<?php declare(strict_types=1); |
|
55
|
|
|
|
|
56
|
|
|
namespace My\Test\Project\Entity\Factories; |
|
57
|
|
|
|
|
58
|
|
|
// phpcs:disable -- line length |
|
59
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
60
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity as DSM; |
|
61
|
|
|
|
|
62
|
|
|
// phpcs:enable |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @SuppressWarnings(PHPMD.NumberOfChildren) |
|
66
|
|
|
*/ |
|
67
|
|
|
class AbstractEntityFactory |
|
68
|
|
|
{ |
|
69
|
|
|
/** |
|
70
|
|
|
* @var DSM\Factory\EntityFactory |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $entityFactory; |
|
73
|
|
|
|
|
74
|
|
|
public function __construct(DSM\Factory\EntityFactory $entityFactory, EntityManagerInterface $entityManager) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->entityFactory = $entityFactory; |
|
77
|
|
|
$this->entityFactory->setEntityManager($entityManager); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
'; |
|
81
|
|
|
$actual = $file->getContents(); |
|
82
|
|
|
self::assertSame($expected, $actual); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|