|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\AbstractIntegrationTest; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\RelationsGenerator; |
|
7
|
|
|
use Symfony\Component\Finder\Finder; |
|
8
|
|
|
|
|
9
|
|
|
class RemoveUnusedRelationsCommandTest extends AbstractCommandIntegrationTest |
|
10
|
|
|
{ |
|
11
|
|
|
public const WORK_DIR = AbstractIntegrationTest::VAR_PATH.'/'.self::TEST_TYPE.'/RemoveUnusedRelationsCommandTest/'; |
|
12
|
|
|
|
|
13
|
|
|
public function testGenerateRelationsNoFiltering(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$entityFqns = $this->generateEntities(); |
|
16
|
|
|
$this->getRelationsGenerator()->setEntityHasRelationToEntity( |
|
17
|
|
|
$entityFqns[0], |
|
18
|
|
|
RelationsGenerator::HAS_ONE_TO_ONE, |
|
19
|
|
|
$entityFqns[1] |
|
20
|
|
|
); |
|
21
|
|
|
$this->setupCopiedWorkDir(); |
|
22
|
|
|
$command = $this->container->get(RemoveUnusedRelationsCommand::class); |
|
23
|
|
|
$tester = $this->getCommandTester($command); |
|
24
|
|
|
$tester->execute( |
|
25
|
|
|
[ |
|
26
|
|
|
'-'.RemoveUnusedRelationsCommand::OPT_PROJECT_ROOT_PATH_SHORT => $this->copiedWorkDir, |
|
27
|
|
|
'-'.RemoveUnusedRelationsCommand::OPT_PROJECT_ROOT_NAMESPACE_SHORT => $this->getCopiedNamespaceRoot(), |
|
28
|
|
|
] |
|
29
|
|
|
); |
|
30
|
|
|
$expectedFilesFoundCount = 10; |
|
31
|
|
|
$actualFilesFound = $this->finderToArrayOfPaths( |
|
32
|
|
|
$this->finder()->files()->in( |
|
33
|
|
|
$this->copiedWorkDir.'/src/Entity/Relations/' |
|
34
|
|
|
) |
|
35
|
|
|
); |
|
36
|
|
|
self::assertCount($expectedFilesFoundCount, $actualFilesFound); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
private function finder(): Finder |
|
40
|
|
|
{ |
|
41
|
|
|
return new Finder(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
private function finderToArrayOfPaths(Finder $finder): array |
|
45
|
|
|
{ |
|
46
|
|
|
$return = []; |
|
47
|
|
|
foreach ($finder as $fileInfo) { |
|
48
|
|
|
$return[] = $fileInfo->getRealPath(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $return; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|