Total Complexity | 11 |
Total Lines | 155 |
Duplicated Lines | 42.58 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
17 | class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase |
||
18 | { |
||
19 | /** |
||
20 | * @var \Symfony\Component\Console\Application |
||
21 | */ |
||
22 | private $application; |
||
23 | |||
24 | private $path; |
||
25 | |||
26 | /** |
||
27 | * @inheritdoc |
||
28 | */ |
||
29 | protected function setUp() |
||
30 | { |
||
31 | parent::setUp(); |
||
32 | |||
33 | $this->path = \sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('doctrine_'); |
||
34 | |||
35 | \mkdir($this->path); |
||
36 | |||
37 | $metadataDriver = $this->_em->getConfiguration()->getMetadataDriverImpl(); |
||
38 | $metadataDriver->addPaths([__DIR__ . '/../../../../Models/DDC3231/']); |
||
1 ignored issue
–
show
|
|||
39 | |||
40 | $this->application = new Application(); |
||
41 | $this->application->setHelperSet(new HelperSet(['em' => new EntityManagerHelper($this->_em)])); |
||
42 | $this->application->add(new GenerateRepositoriesCommand()); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @inheritdoc |
||
47 | */ |
||
48 | View Code Duplication | public function tearDown() |
|
69 | } |
||
70 | |||
71 | View Code Duplication | public function testGenerateRepositories() |
|
72 | { |
||
73 | $this->generateRepositories('DDC3231User1'); |
||
74 | |||
75 | $cname = 'Doctrine\Tests\Models\DDC3231\DDC3231User1Repository'; |
||
76 | $fname = str_replace('\\', DIRECTORY_SEPARATOR, $cname) . '.php'; |
||
77 | |||
78 | self::assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname); |
||
79 | self::assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User1NoNamespaceRepository.php'); |
||
80 | |||
81 | require $this->path . DIRECTORY_SEPARATOR . $fname; |
||
82 | require $this->path . DIRECTORY_SEPARATOR . 'DDC3231User1NoNamespaceRepository.php'; |
||
83 | |||
84 | self::assertTrue(class_exists($cname)); |
||
85 | self::assertTrue(class_exists('DDC3231User1NoNamespaceRepository')); |
||
86 | |||
87 | $repo1 = new \ReflectionClass($cname); |
||
88 | $repo2 = new \ReflectionClass('DDC3231User1NoNamespaceRepository'); |
||
89 | |||
90 | self::assertSame(EntityRepository::class, $repo1->getParentClass()->getName()); |
||
91 | self::assertSame(EntityRepository::class, $repo2->getParentClass()->getName()); |
||
92 | } |
||
93 | |||
94 | View Code Duplication | public function testGenerateRepositoriesCustomDefaultRepository() |
|
115 | } |
||
116 | |||
117 | /** |
||
118 | * @param string $filter |
||
119 | * @param string $defaultRepository |
||
120 | */ |
||
121 | private function generateRepositories($filter, $defaultRepository = null) |
||
122 | { |
||
123 | if ($defaultRepository) { |
||
124 | $this->_em->getConfiguration()->setDefaultRepositoryClassName($defaultRepository); |
||
125 | } |
||
126 | |||
127 | $command = $this->application->find('orm:generate-repositories'); |
||
128 | $tester = new CommandTester($command); |
||
129 | |||
130 | $tester->execute( |
||
131 | [ |
||
132 | 'command' => $command->getName(), |
||
133 | 'dest-path' => $this->path, |
||
134 | '--filter' => $filter, |
||
135 | ] |
||
136 | ); |
||
137 | } |
||
138 | |||
139 | public function testNoMetadataClassesToProcess() : void |
||
172 | } |
||
173 | } |
||
174 |