Adds failing test
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace LotGD\Core\Tests\DefectiveModule;
|
||||
|
||||
use Exception;
|
||||
|
||||
use LotGD\Core\Game;
|
||||
use LotGD\Core\Events\EventContext;
|
||||
use LotGD\Core\Module as ModuleInterface;
|
||||
use LotGD\Core\Models\Module as ModuleModel;
|
||||
|
||||
class DefectiveModuleException extends Exception {}
|
||||
|
||||
class Module implements ModuleInterface {
|
||||
public static function handleEvent(Game $g, EventContext $context): EventContext
|
||||
{
|
||||
return $context;
|
||||
}
|
||||
|
||||
public static function onRegister(Game $g, ModuleModel $module)
|
||||
{
|
||||
throw new DefectiveModuleException("Exception");
|
||||
}
|
||||
|
||||
public static function onUnregister(Game $g, ModuleModel $module)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
entityNamespace: "LotGD\\Core\\Tests\\FakeModule\\Models\\"
|
||||
subscriptionPatterns:
|
||||
- "e/lotgd/core/tests/event"
|
||||
@@ -6,6 +6,7 @@ namespace LotGD\Core\Tests;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Composer;
|
||||
|
||||
use Doctrine\Common\Util\Debug;
|
||||
use LotGD\Core\Game;
|
||||
use LotGD\Core\ComposerManager;
|
||||
use LotGD\Core\EventHandler;
|
||||
@@ -18,6 +19,7 @@ use LotGD\Core\Exceptions\ModuleAlreadyExistsException;
|
||||
use LotGD\Core\Exceptions\ModuleDoesNotExistException;
|
||||
use LotGD\Core\Tests\CoreModelTestCase;
|
||||
use LotGD\Core\Tests\FakeModule\Module as FakeModule;
|
||||
use LotGD\Core\Tests\DefectiveModule\Module as DefectiveModule;
|
||||
|
||||
class ModuleManagerTest extends CoreModelTestCase
|
||||
{
|
||||
@@ -135,8 +137,7 @@ class ModuleManagerTest extends CoreModelTestCase
|
||||
{
|
||||
$class = FakeModule::class;
|
||||
$name = 'lotgd/tests2';
|
||||
$subscriptions = array(
|
||||
);
|
||||
$subscriptions = [];
|
||||
$library = $this->getMockBuilder(LibraryConfiguration::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@@ -199,4 +200,36 @@ class ModuleManagerTest extends CoreModelTestCase
|
||||
$this->assertGreaterThanOrEqual(-5, $timeDiff);
|
||||
$this->assertEquals($name, $modules[1]->getLibrary());
|
||||
}
|
||||
|
||||
public function testRegisteringDefectiveModule()
|
||||
{
|
||||
$class = DefectiveModule::class;
|
||||
$name = "lotgd/tests3";
|
||||
$subscriptions = [];
|
||||
$library = $this->getMockBuilder(LibraryConfiguration::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$library->method('getName')->willReturn($name);
|
||||
$library->method('getRootNamespace')->willReturn('LotGD\\Core\\Tests\\DefectiveModule\\');
|
||||
$library->method('getSubscriptionPatterns')->willReturn($subscriptions);
|
||||
|
||||
$eventManager = $this->getMockBuilder(EventManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->game->method('getEventManager')->willReturn($eventManager);
|
||||
$modulesBefore = $this->mm->getModules();
|
||||
try {
|
||||
// onRegister throws an exception. This exception needs to be captured and handled by mm->register without actually
|
||||
// registering a real module...
|
||||
$this->mm->register($library);
|
||||
$exceptionCaptured = false;
|
||||
} catch(\Exception $e) {
|
||||
$exceptionCaptured = true;
|
||||
}
|
||||
$modulesAfter = $this->mm->getModules();
|
||||
|
||||
$this->assertFalse($exceptionCaptured);
|
||||
$this->assertCount(count($modulesBefore), $modulesAfter);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user