Files
core/tests/BootstrapTest.php
T
Vassyli ae63c209e9 Clean-ups
Left overs to clean and changes from discussion.

Fixed config path finding
2016-07-29 11:57:24 +02:00

94 lines
3.4 KiB
PHP

<?php
declare(strict_types=1);
namespace LotGD\Core\Tests;
use Composer\Package\PackageInterface;
use Composer\Package\AliasPackage;
use Composer\Installer\InstallationManager;
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use LotGD\Core\Bootstrap;
use LotGD\Core\ComposerManager;
use LotGD\Core\Tests\FakeModule\Models\UserEntity;
class BootstrapTest extends \PHPUnit_Framework_TestCase
{
private $logger;
public function setUp()
{
$this->logger = new Logger('test');
$this->logger->pushHandler(new NullHandler());
}
public function testGame()
{
$g = Bootstrap::createGame();
$this->assertNotNull($g->getEntityManager());
$this->assertNotNull($g->getEventManager());
$this->assertNotNull($g->getLogger());
}
public function testBootstrapLoadsPackageModels()
{
$installationManager = $this->getMockBuilder(InstallationManager::class)
->disableOriginalConstructor()
->setMethods(["getInstallPath"])
->getMock();
$installationManager->method("getInstallPath")->willReturn(__DIR__ . "/FakeModule");
$composer = $this->getMockBuilder(\Composer\Composer::class)
->disableOriginalConstructor()
->setMethods(["getInstallationManager"])
->getMock();
$composer->method("getInstallationManager")->willReturn($installationManager);
$fakeModulePackage = $this->getMockBuilder(AliasPackage::class)
->disableOriginalConstructor()
->setMethods(["getType", "getAutoload"])
->getMock();
$fakeModulePackage->method("getType")->willReturn("lotgd-module");
$fakeModulePackage->method("getAutoload")->willReturn([
"psr-4" => [
"LotGD\\Core\\Tests\\FakeModule\\" => "FakeModule/"
]
]);
$composerManager = $this->getMockBuilder(ComposerManager::class)
->setMethods(["getPackages", "getComposer", "translateNamespaceToPath"])
->getMock();
$composerManager->method("getPackages")->willReturn([$fakeModulePackage]);
$composerManager->method("getComposer")->willReturn($composer);
$composerManager
->expects($this->exactly(1))
->method("translateNamespaceToPath")
->with("LotGD\\Core\\Tests\\FakeModule\\Models")
->willReturn(__DIR__ . "/FakeModule/Models");
$bootstrap = $this->getMockBuilder(Bootstrap::class)
->setMethods(["createComposerManager"])
->getMock();
$bootstrap->method("createComposerManager")->willReturn($composerManager);
// run tests
$game = $bootstrap->getGame();
$this->assertGreaterThanorEqual(3, $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());
}
}