Updated bootstrap to call packages Bootstrap

The bootstrap procedure has been updated to search through all packages to get the ones with an lotgd-namespace extra field. These are then tested if they have or have not a bootstrap class implementing BootstrapInterface. If yes, they get added to a stack used to modify the bootstrap procedure. For know, bootstrap supports additional entity directories.
This commit is contained in:
Vassyli
2016-07-26 15:41:48 +02:00
parent 86b5f075fa
commit 58147ed14b
7 changed files with 257 additions and 66 deletions
+23 -15
View File
@@ -10,7 +10,7 @@ use Monolog\Handler\NullHandler;
use LotGD\Core\Bootstrap;
use LotGD\Core\ComposerManager;
use LotGD\Core\Tests\FakeModule\UserEntity;
use LotGD\Core\Tests\FakeModule\Models\UserEntity;
class BootstrapTest extends \PHPUnit_Framework_TestCase
{
@@ -42,19 +42,27 @@ class BootstrapTest extends \PHPUnit_Framework_TestCase
'lotgd-namespace' => 'LotGD\\Core\\Tests\\FakeModule\\',
));
$composerManager->method('getPackages')->willReturn(array($package));
$expected = __DIR__ . DIRECTORY_SEPARATOR . 'FakeModule';
$composerManager->method('translateNamespaceToPath')->willReturn($expected);
$result = Bootstrap::generateAnnotationDirectories($this->logger, $composerManager);
$string = implode(', ', $result);
$found = false;
foreach ($result as $r) {
if (realpath($r) == $expected) {
$found = true;
}
}
$this->assertTrue($found, "Annotation directories [{$string}] does not contain {$expected}.");
$bootstrap = $this->getMockBuilder(Bootstrap::class)
->setMethods(["createComposer"])
->getMock();
$bootstrap->method("createComposer")->willReturn($composerManager);
$game = $bootstrap->getGame();
$this->assertGreaterThanOrEqual(2, $bootstrap->getReadAnnotationDirectories());
$user = new UserEntity();
$user->setName("Monthy");
$game->getEntityManager()->persist($user);
$game->getEntityManager()->flush();
$id = $user->getId();
$this->assertInternalType("int", $id);
$game->getEntityManager()->clear();
$user = $game->getEntityManager()->getRepository(UserEntity::class)->find($id);
$this->assertInternalType("int", $user->getId());
$this->assertInternalType("string", $user->getName());
$this->assertSame("Monthy", $user->getName());
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace LotGD\Core\Tests\FakeModule;
use LotGD\Core\BootstrapInterface;
class Bootstrap implements BootstrapInterface
{
public function hasEntityPath(): bool
{
return true;
}
public function getEntityPath(): string
{
return __DIR__ . "/Models";
}
}
+34
View File
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace LotGD\Core\Tests\FakeModule\Models;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Table;
/**
* @Entity
* @Table(name="Users")
*/
class UserEntity
{
/** @Id @Column(type="integer") @GeneratedValue */
private $id;
/** @Column(type="string", length=50); */
private $name;
public function getId(): int
{
return $this->id;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name)
{
$this->name = $name;
}
}