Skip to content

Commit 2dc123c

Browse files
committed
updating namespace so the autoloader finds things in the correct, final
location moving XML projects and other projects into different dir/namespace This avoids the metadata being cached in one test, then used in the next. These tests are a bit of a mess, this is more of a workaround.
1 parent 570f001 commit 2dc123c

33 files changed

+61
-59
lines changed

tests/Doctrine/EntityRegeneratorTest.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ public function testRegenerateEntities(string $expectedDirName, bool $overwrite)
3333
$this->doTestRegeneration(
3434
__DIR__.'/fixtures/source_project',
3535
$kernel,
36-
'Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity',
36+
'Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity',
3737
$expectedDirName,
38-
$overwrite
38+
$overwrite,
39+
'current_project'
3940
);
4041
}
4142

4243
public function getRegenerateEntitiesTests()
4344
{
44-
yield 'regnerate_no_overwrite' => [
45+
yield 'regenerate_no_overwrite' => [
4546
'expected_no_overwrite',
4647
false
4748
];
@@ -58,16 +59,17 @@ public function testXmlRegeneration()
5859
$this->doTestRegeneration(
5960
__DIR__.'/fixtures/xml_source_project',
6061
$kernel,
61-
'Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity',
62+
'Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Entity',
6263
'expected_xml',
63-
false
64+
false,
65+
'current_project_xml'
6466
);
6567
}
6668

67-
private function doTestRegeneration(string $sourceDir, Kernel $kernel, string $namespace, string $expectedDirName, bool $overwrite)
69+
private function doTestRegeneration(string $sourceDir, Kernel $kernel, string $namespace, string $expectedDirName, bool $overwrite, string $targetDirName)
6870
{
6971
$fs = new Filesystem();
70-
$tmpDir = __DIR__.'/../tmp/current_project';
72+
$tmpDir = __DIR__.'/../tmp/'.$targetDirName;
7173
$fs->remove($tmpDir);
7274

7375
// if traits (Timestampable, Teamable) gets copied into new project, tests will fail because of double exclusion
@@ -79,8 +81,8 @@ private function doTestRegeneration(string $sourceDir, Kernel $kernel, string $n
7981
$autoloaderUtil = $this->createMock(AutoloaderUtil::class);
8082
$autoloaderUtil->expects($this->any())
8183
->method('getPathForFutureClass')
82-
->willReturnCallback(function($className) use ($tmpDir) {
83-
$shortClassName = str_replace('Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\\', '', $className);
84+
->willReturnCallback(function($className) use ($tmpDir, $targetDirName) {
85+
$shortClassName = str_replace('Symfony\Bundle\MakerBundle\Tests\tmp\\'.$targetDirName.'\src\\', '', $className);
8486

8587
// strip the App\, change \ to / and add .php
8688
return $tmpDir.'/src/'.str_replace('\\', '/', $shortClassName).'.php';
@@ -152,7 +154,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
152154
'is_bundle' => false,
153155
'type' => 'annotation',
154156
'dir' => '%kernel.root_dir%/src/Entity',
155-
'prefix' => 'Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity',
157+
'prefix' => 'Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity',
156158
'alias' => 'EntityRegeneratorApp',
157159
]
158160
]
@@ -197,7 +199,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
197199
'is_bundle' => false,
198200
'type' => 'xml',
199201
'dir' => '%kernel.root_dir%/config/doctrine',
200-
'prefix' => 'Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity',
202+
'prefix' => 'Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Entity',
201203
'alias' => 'EntityRegeneratorApp',
202204
]
203205
]
@@ -207,13 +209,13 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
207209

208210
public function getRootDir()
209211
{
210-
return __DIR__.'/../tmp/current_project';
212+
return __DIR__.'/../tmp/current_project_xml';
211213
}
212214
}
213215

214216
class AllButTraitsIterator extends \RecursiveFilterIterator
215217
{
216218
public function accept() {
217-
return !in_array($this->current()->getFilename(), ['TeamTrait.php', 'TimestampableTrait.php']);
219+
return !in_array($this->current()->getFilename(), []);
218220
}
219221
}

tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/BaseClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\Common\Collections\ArrayCollection;
66
use Doctrine\Common\Collections\Collection;

tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/Embed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/Tag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\Common\Collections\ArrayCollection;
66
use Doctrine\Common\Collections\Collection;

tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/UserAvatar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/expected_no_overwrite/src/Entity/UserProfile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/expected_overwrite/src/Entity/BaseClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/expected_overwrite/src/Entity/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\Common\Collections\ArrayCollection;
66
use Doctrine\Common\Collections\Collection;

tests/Doctrine/fixtures/expected_overwrite/src/Entity/Embed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/expected_overwrite/src/Entity/Tag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/expected_overwrite/src/Entity/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\Common\Collections\ArrayCollection;
66
use Doctrine\Common\Collections\Collection;

tests/Doctrine/fixtures/expected_overwrite/src/Entity/UserAvatar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/expected_overwrite/src/Entity/UserProfile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/expected_xml/src/Entity/UserAvatar.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Entity;
44

55
class UserAvatar
66
{
@@ -13,12 +13,12 @@ public function getId(): ?int
1313
return $this->id;
1414
}
1515

16-
public function getUser(): ?User
16+
public function getUser(): ?UserXml
1717
{
1818
return $this->user;
1919
}
2020

21-
public function setUser(?User $user): self
21+
public function setUser(?UserXml $user): self
2222
{
2323
$this->user = $user;
2424

tests/Doctrine/fixtures/expected_xml/src/Entity/User.php renamed to tests/Doctrine/fixtures/expected_xml/src/Entity/UserXml.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Entity;
44

55
use Doctrine\Common\Collections\ArrayCollection;
66
use Doctrine\Common\Collections\Collection;
77

8-
class User
8+
class UserXml
99
{
1010
private $id;
1111

tests/Doctrine/fixtures/expected_xml/src/Entity/XOther.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Entity;
44

55
class XOther
66
{

tests/Doctrine/fixtures/expected_xml/src/Repository/UserRepository.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Repository;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Repository;
44

5-
use Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity\User;
5+
use Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Entity\UserXml;
66
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
77
use Symfony\Bridge\Doctrine\RegistryInterface;
88

99
/**
10-
* @method User|null find($id, $lockMode = null, $lockVersion = null)
11-
* @method User|null findOneBy(array $criteria, array $orderBy = null)
12-
* @method User[] findAll()
13-
* @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
10+
* @method UserXml|null find($id, $lockMode = null, $lockVersion = null)
11+
* @method UserXml|null findOneBy(array $criteria, array $orderBy = null)
12+
* @method UserXml[] findAll()
13+
* @method UserXml[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
1414
*/
1515
class UserRepository extends ServiceEntityRepository
1616
{
1717
public function __construct(RegistryInterface $registry)
1818
{
19-
parent::__construct($registry, User::class);
19+
parent::__construct($registry, UserXml::class);
2020
}
2121

2222
// /**
23-
// * @return User[] Returns an array of User objects
23+
// * @return UserXml[] Returns an array of UserXml objects
2424
// */
2525
/*
2626
public function findByExampleField($value)
@@ -37,7 +37,7 @@ public function findByExampleField($value)
3737
*/
3838

3939
/*
40-
public function findOneBySomeField($value): ?User
40+
public function findOneBySomeField($value): ?UserXml
4141
{
4242
return $this->createQueryBuilder('u')
4343
->andWhere('u.exampleField = :val')

tests/Doctrine/fixtures/expected_xml/src/Repository/XOtherRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Repository;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Repository;
44

5-
use Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity\XOther;
5+
use Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Entity\XOther;
66
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
77
use Symfony\Bridge\Doctrine\RegistryInterface;
88

tests/Doctrine/fixtures/source_project/src/Entity/BaseClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/source_project/src/Entity/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/source_project/src/Entity/Embed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/source_project/src/Entity/Tag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/source_project/src/Entity/TeamTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/source_project/src/Entity/TimestampableTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/source_project/src/Entity/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\Common\Collections\ArrayCollection;
66
use Doctrine\ORM\Mapping as ORM;

tests/Doctrine/fixtures/source_project/src/Entity/UserAvatar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/source_project/src/Entity/UserProfile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Symfony\Bundle\MakerBundle\Tests\Doctrine\fixtures\source_project\src\Entity;
3+
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity;
44

55
use Doctrine\ORM\Mapping as ORM;
66

tests/Doctrine/fixtures/xml_source_project/config/doctrine/UserAvatar.orm.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
44
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
55

6-
<entity name="Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity\UserAvatar">
6+
<entity name="Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Entity\UserAvatar">
77
<id name="id" type="integer">
88
<generator strategy="AUTO" />
99
</id>
10-
<many-to-one field="user" target-entity="User" inversed-by="avatars">
10+
<many-to-one field="user" target-entity="UserXml" inversed-by="avatars">
1111
<cascade>
1212
<cascade-persist/>
1313
<cascade-remove/>

tests/Doctrine/fixtures/xml_source_project/config/doctrine/User.orm.xml renamed to tests/Doctrine/fixtures/xml_source_project/config/doctrine/UserXml.orm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
44
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
55

6-
<entity name="Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Entity\User" repository-class="Symfony\Bundle\MakerBundle\Tests\tmp\current_project\src\Repository\UserRepository">
6+
<entity name="Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Entity\UserXml" repository-class="Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Repository\UserRepository">
77
<id name="id" type="integer">
88
<generator strategy="AUTO" />
99
</id>

0 commit comments

Comments
 (0)