-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1089 from encoder32/EntityRepositoryGeneratorDefa…
…ultRepository EntityRepositoryGenerator default repository
- Loading branch information
Showing
9 changed files
with
511 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
tests/Doctrine/Tests/Models/DDC3231/DDC3231EntityRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\DDC3231; | ||
|
||
class DDC3231EntityRepository extends \Doctrine\ORM\EntityRepository | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\DDC3231; | ||
|
||
/** | ||
* @Entity(repositoryClass="DDC3231User1Repository") | ||
* @Table(name="users") | ||
*/ | ||
class DDC3231User1 | ||
{ | ||
/** | ||
* @Id | ||
* @Column(type="integer") | ||
* @GeneratedValue(strategy="AUTO") | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @Column(type="string", length=255) | ||
*/ | ||
protected $name; | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
tests/Doctrine/Tests/Models/DDC3231/DDC3231User1NoNamespace.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/** | ||
* @Entity(repositoryClass="DDC3231User1NoNamespaceRepository") | ||
* @Table(name="no_namespace_users") | ||
*/ | ||
class DDC3231User1NoNamespace | ||
{ | ||
/** | ||
* @Id | ||
* @Column(type="integer") | ||
* @GeneratedValue(strategy="AUTO") | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @Column(type="string", length=255) | ||
*/ | ||
protected $name; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Models\DDC3231; | ||
|
||
/** | ||
* @Entity(repositoryClass="DDC3231User2Repository") | ||
* @Table(name="users2") | ||
*/ | ||
class DDC3231User2 | ||
{ | ||
/** | ||
* @Id | ||
* @Column(type="integer") | ||
* @GeneratedValue(strategy="AUTO") | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @Column(type="string", length=255) | ||
*/ | ||
protected $name; | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
tests/Doctrine/Tests/Models/DDC3231/DDC3231User2NoNamespace.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/** | ||
* @Entity(repositoryClass="DDC3231User2NoNamespaceRepository") | ||
* @Table(name="no_namespace_users2") | ||
*/ | ||
class DDC3231User2NoNamespace | ||
{ | ||
/** | ||
* @Id | ||
* @Column(type="integer") | ||
* @GeneratedValue(strategy="AUTO") | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @Column(type="string", length=255) | ||
*/ | ||
protected $name; | ||
|
||
} |
143 changes: 143 additions & 0 deletions
143
tests/Doctrine/Tests/ORM/Tools/Console/Command/GenerateRepositoriesCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\ORM\Tools\Console\Command; | ||
|
||
use Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand; | ||
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Symfony\Component\Console\Helper\HelperSet; | ||
use Symfony\Component\Console\Application; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
/** | ||
* GenerateRepositoriesCommandTest | ||
*/ | ||
class GenerateRepositoriesCommandTest extends OrmFunctionalTestCase | ||
{ | ||
/** | ||
* @var \Symfony\Component\Console\Application | ||
*/ | ||
private $application; | ||
|
||
private $path; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->path = \sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('doctrine_'); | ||
|
||
\mkdir($this->path); | ||
|
||
|
||
$metadataDriver = $this->_em->getConfiguration()->getMetadataDriverImpl(); | ||
|
||
$metadataDriver->addPaths(array( | ||
__DIR__ . '/../../../../Models/DDC3231/' | ||
)); | ||
|
||
$this->application = new Application(); | ||
|
||
$this->application->setHelperSet(new HelperSet(array( | ||
'em' => new EntityManagerHelper($this->_em) | ||
))); | ||
|
||
$this->application->add(new GenerateRepositoriesCommand()); | ||
|
||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function tearDown() | ||
{ | ||
$dirs = array(); | ||
|
||
$ri = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->path)); | ||
foreach ($ri AS $file) { | ||
/* @var $file \SplFileInfo */ | ||
if ($file->isFile()) { | ||
\unlink($file->getPathname()); | ||
} elseif ($file->getBasename() === '.') { | ||
$dirs[] = $file->getRealpath(); | ||
} | ||
} | ||
|
||
arsort($dirs); | ||
|
||
foreach ($dirs as $dir) { | ||
\rmdir($dir); | ||
} | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
public function testGenerateRepositories() | ||
{ | ||
$this->generateRepositories('DDC3231User1'); | ||
|
||
$cname = 'Doctrine\Tests\Models\DDC3231\DDC3231User1Repository'; | ||
$fname = str_replace('\\', DIRECTORY_SEPARATOR, $cname) . '.php'; | ||
|
||
$this->assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname); | ||
$this->assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User1NoNamespaceRepository.php'); | ||
|
||
require $this->path . DIRECTORY_SEPARATOR . $fname; | ||
require $this->path . DIRECTORY_SEPARATOR . 'DDC3231User1NoNamespaceRepository.php'; | ||
|
||
$this->assertTrue(class_exists($cname)); | ||
$this->assertTrue(class_exists('DDC3231User1NoNamespaceRepository')); | ||
|
||
$repo1 = new \ReflectionClass($cname); | ||
$repo2 = new \ReflectionClass('DDC3231User1NoNamespaceRepository'); | ||
|
||
$this->assertSame('Doctrine\ORM\EntityRepository', $repo1->getParentClass()->getName()); | ||
$this->assertSame('Doctrine\ORM\EntityRepository', $repo2->getParentClass()->getName()); | ||
} | ||
|
||
public function testGenerateRepositoriesCustomDefaultRepository() | ||
{ | ||
$this->generateRepositories('DDC3231User2', 'Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository'); | ||
|
||
$cname = 'Doctrine\Tests\Models\DDC3231\DDC3231User2Repository'; | ||
$fname = str_replace('\\', DIRECTORY_SEPARATOR, $cname) . '.php'; | ||
|
||
$this->assertFileExists($this->path . DIRECTORY_SEPARATOR . $fname); | ||
$this->assertFileExists($this->path . DIRECTORY_SEPARATOR . 'DDC3231User2NoNamespaceRepository.php'); | ||
|
||
require $this->path . DIRECTORY_SEPARATOR . $fname; | ||
require $this->path . DIRECTORY_SEPARATOR . 'DDC3231User2NoNamespaceRepository.php'; | ||
|
||
$this->assertTrue(class_exists($cname)); | ||
$this->assertTrue(class_exists('DDC3231User2NoNamespaceRepository')); | ||
|
||
$repo1 = new \ReflectionClass($cname); | ||
$repo2 = new \ReflectionClass('DDC3231User2NoNamespaceRepository'); | ||
|
||
$this->assertSame('Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository', $repo1->getParentClass()->getName()); | ||
$this->assertSame('Doctrine\Tests\Models\DDC3231\DDC3231EntityRepository', $repo2->getParentClass()->getName()); | ||
} | ||
|
||
/** | ||
* @param string $filter | ||
* @param string $defaultRepository | ||
*/ | ||
private function generateRepositories($filter, $defaultRepository = null) | ||
{ | ||
if ($defaultRepository) { | ||
$this->_em->getConfiguration()->setDefaultRepositoryClassName($defaultRepository); | ||
} | ||
|
||
$command = $this->application->find('orm:generate-repositories'); | ||
$tester = new CommandTester($command); | ||
$tester->execute(array( | ||
'command' => $command->getName(), | ||
'dest-path' => $this->path, | ||
'--filter' => $filter, | ||
)); | ||
} | ||
|
||
} |
Oops, something went wrong.