Changes implemented to pass test.

This commit is contained in:
Vassyli
2017-04-24 20:52:34 +02:00
parent 1eeca4ef9e
commit 7e58c72526
3 changed files with 12 additions and 10 deletions
+9 -6
View File
@@ -3,11 +3,9 @@ declare (strict_types=1);
namespace LotGD\Core;
use Composer\Package\PackageInterface;
use Doctrine\ORM\EntityManagerInterface;
use Throwable;
use LotGD\Core\PackageConfiguration;
use LotGD\Core\Exceptions\KeyNotFoundException;
use LotGD\Core\Exceptions\ModuleAlreadyExistsException;
use LotGD\Core\Exceptions\ModuleDoesNotExistException;
use LotGD\Core\Models\Module as ModuleModel;
@@ -52,7 +50,6 @@ class ModuleManager
// TODO: handle error cases here.
$this->g->getLogger()->debug("Creating module model for {$name}");
$m = new ModuleModel($name);
$m->save($this->g->getEntityManager());
$class = $library->getRootNamespace() . 'Module';
try {
@@ -77,8 +74,14 @@ class ModuleManager
// Run the module's onRegister handler.
$this->g->getLogger()->debug("Calling {$class}::onRegister");
$class::onRegister($this->g, $m);
$m->save($this->g->getEntityManager());
try {
$class::onRegister($this->g, $m);
$m->save($this->g->getEntityManager());
} catch (Throwable $e) {
$this->g->getLogger()->debug("Calling {$class}::onRegister failed with exception: {$e->getMessage()}");
unset($m);
}
}
}
+2 -3
View File
@@ -2,14 +2,13 @@
namespace LotGD\Core\Tests\DefectiveModule;
use Exception;
use LotGD\Core\Exceptions\CoreException;
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 DefectiveModuleException extends CoreException {}
class Module implements ModuleInterface {
public static function handleEvent(Game $g, EventContext $context): EventContext
+1 -1
View File
@@ -224,7 +224,7 @@ class ModuleManagerTest extends CoreModelTestCase
// registering a real module...
$this->mm->register($library);
$exceptionCaptured = false;
} catch(\Exception $e) {
} catch(\Throwable $e) {
$exceptionCaptured = true;
}
$modulesAfter = $this->mm->getModules();