1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\CodeGeneration\Command; |
4
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\RemoveUnusedRelationsCommand; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\RelationsGenerator; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest; |
8
|
|
|
use Symfony\Component\Finder\Finder; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class RemoveUnusedRelationsCommandTest |
12
|
|
|
* |
13
|
|
|
* @package EdmondsCommerce\DoctrineStaticMeta\Tests\Large\CodeGeneration\Command |
14
|
|
|
* @coversDefaultClass \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\RemoveUnusedRelationsCommand |
15
|
|
|
*/ |
16
|
|
|
class RemoveUnusedRelationsCommandTest extends AbstractCommandTest |
17
|
|
|
{ |
18
|
|
|
public const WORK_DIR = AbstractTest::VAR_PATH . |
19
|
|
|
'/' . |
20
|
|
|
self::TEST_TYPE_LARGE . |
21
|
|
|
'/RemoveUnusedRelationsCommandTest/'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @test |
25
|
|
|
* @large |
26
|
|
|
* @covers ::execute |
27
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
28
|
|
|
* @throws \ReflectionException |
29
|
|
|
*/ |
30
|
|
|
public function removeUnusedRelations(): void |
31
|
|
|
{ |
32
|
|
|
$entityFqns = $this->generateEntities(); |
33
|
|
|
$this->getRelationsGenerator()->setEntityHasRelationToEntity( |
34
|
|
|
$entityFqns[0], |
35
|
|
|
RelationsGenerator::HAS_ONE_TO_ONE, |
36
|
|
|
$entityFqns[1] |
37
|
|
|
); |
38
|
|
|
$this->setupCopiedWorkDir(); |
39
|
|
|
$command = $this->container->get(RemoveUnusedRelationsCommand::class); |
40
|
|
|
$tester = $this->getCommandTester($command); |
41
|
|
|
$tester->execute( |
42
|
|
|
[ |
43
|
|
|
'-' . RemoveUnusedRelationsCommand::OPT_PROJECT_ROOT_PATH_SHORT => $this->copiedWorkDir, |
44
|
|
|
'-' . RemoveUnusedRelationsCommand::OPT_PROJECT_ROOT_NAMESPACE_SHORT => $this->getCopiedNamespaceRoot(), |
45
|
|
|
] |
46
|
|
|
); |
47
|
|
|
$expectedFilesFoundCount = 10; |
48
|
|
|
$actualFilesFound = $this->finderToArrayOfPaths( |
49
|
|
|
$this->finder()->files()->in( |
50
|
|
|
$this->copiedWorkDir . '/src/Entity/Relations/' |
51
|
|
|
) |
52
|
|
|
); |
53
|
|
|
self::assertCount($expectedFilesFoundCount, $actualFilesFound); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function finderToArrayOfPaths(Finder $finder): array |
57
|
|
|
{ |
58
|
|
|
$return = []; |
59
|
|
|
foreach ($finder as $fileInfo) { |
60
|
|
|
$return[] = $fileInfo->getRealPath(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function finder(): Finder |
67
|
|
|
{ |
68
|
|
|
return new Finder(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|