Store the module name along with event subscriptions
This commit is contained in:
@@ -39,7 +39,7 @@ class EventManagerTest extends ModelTestCase
|
||||
$em = new EventManager($this->getEntityManager());
|
||||
|
||||
$this->expectException(ClassNotFoundException::class);
|
||||
$em->subscribe("/test.event/", 'LotGD\Core\Tests\NoClassHere');
|
||||
$em->subscribe("/test.event/", 'LotGD\Core\Tests\NoClassHere', 'lotgd/tests');
|
||||
}
|
||||
|
||||
public function testSubscribeInvalidClass()
|
||||
@@ -47,7 +47,7 @@ class EventManagerTest extends ModelTestCase
|
||||
$em = new EventManager($this->getEntityManager());
|
||||
|
||||
$this->expectException(WrongTypeException::class);
|
||||
$em->subscribe("/test.event/", 'LotGD\Core\Tests\EventManagerTestInvalidSubscriber');
|
||||
$em->subscribe("/test.event/", 'LotGD\Core\Tests\EventManagerTestInvalidSubscriber', 'lotgd/tests');
|
||||
}
|
||||
|
||||
public function testSubscribeInvalidRegexp()
|
||||
@@ -55,7 +55,7 @@ class EventManagerTest extends ModelTestCase
|
||||
$em = new EventManager($this->getEntityManager());
|
||||
|
||||
$this->expectException(WrongTypeException::class);
|
||||
$em->subscribe("/test.event", 'LotGD\Core\Tests\EventManagerTestSubscriber');
|
||||
$em->subscribe("/test.event", 'LotGD\Core\Tests\EventManagerTestSubscriber', 'lotgd/tests');
|
||||
}
|
||||
|
||||
public function testGetSubscriptions()
|
||||
@@ -64,10 +64,12 @@ class EventManagerTest extends ModelTestCase
|
||||
|
||||
$pattern = "/test\\.foo.*/";
|
||||
$class = 'LotGD\\Core\\Tests\\EventManagerTestInstalledSubscriber';
|
||||
$library = 'lotgd/tests';
|
||||
|
||||
$sub = EventSubscription::create([
|
||||
'pattern' => $pattern,
|
||||
'class' => $class,
|
||||
'library' => $library
|
||||
]);
|
||||
|
||||
$subscriptions = $em->getSubscriptions();
|
||||
@@ -83,12 +85,14 @@ class EventManagerTest extends ModelTestCase
|
||||
|
||||
$pattern = "/test.event/";
|
||||
$class = 'LotGD\Core\Tests\EventManagerTestSubscriber';
|
||||
$library = 'lotgd/tests';
|
||||
|
||||
$em->subscribe($pattern, $class);
|
||||
$em->subscribe($pattern, $class, $library);
|
||||
|
||||
$sub = EventSubscription::create([
|
||||
'pattern' => $pattern,
|
||||
'class' => $class,
|
||||
'library' => $library
|
||||
]);
|
||||
|
||||
$subscriptions = $em->getSubscriptions();
|
||||
@@ -102,7 +106,7 @@ class EventManagerTest extends ModelTestCase
|
||||
{
|
||||
$em = new EventManager($this->getEntityManager());
|
||||
|
||||
$em->unsubscribe("/test\\.foo.*/", 'LotGD\Core\Tests\EventManagerTestInstalledSubscriber');
|
||||
$em->unsubscribe("/test\\.foo.*/", 'LotGD\Core\Tests\EventManagerTestInstalledSubscriber', 'lotgd/tests');
|
||||
|
||||
$subscriptions = $em->getSubscriptions();
|
||||
$this->assertEmpty($subscriptions);
|
||||
@@ -113,7 +117,7 @@ class EventManagerTest extends ModelTestCase
|
||||
$em = new EventManager($this->getEntityManager());
|
||||
|
||||
$this->expectException(SubscriptionNotFoundException::class);
|
||||
$em->unsubscribe("/notfound/", 'LotGD\Core\Tests\EventManagerTestInstalledSubscriber');
|
||||
$em->unsubscribe("/notfound/", 'LotGD\Core\Tests\EventManagerTestInstalledSubscriber', 'lotgd/tests');
|
||||
}
|
||||
|
||||
public function testPublish()
|
||||
|
||||
@@ -20,9 +20,9 @@ class ModuleTest extends ModelTestCase
|
||||
public function testGetters()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$scene = $em->getRepository(Module::class)->find('lotgd/test');
|
||||
$scene = $em->getRepository(Module::class)->find('lotgd/tests');
|
||||
|
||||
$this->assertEquals("lotgd/test", $scene->getLibrary());
|
||||
$this->assertEquals("lotgd/tests", $scene->getLibrary());
|
||||
$this->assertEquals(new \DateTime('2016-05-01'), $scene->getCreatedAt());
|
||||
|
||||
$em->flush();
|
||||
|
||||
+27
-17
@@ -40,7 +40,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
$this->expectException(ModuleAlreadyExistsException::class);
|
||||
$mm->register($game, 'lotgd/test', $package);
|
||||
$mm->register($game, 'lotgd/tests', $package);
|
||||
}
|
||||
|
||||
public function testGetModules()
|
||||
@@ -52,7 +52,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
|
||||
// This is a little fragile, but assertContains() doesn't seem to work.
|
||||
$this->assertEquals(new \DateTime('2016-05-01'), $modules[0]->getCreatedAt());
|
||||
$this->assertEquals('lotgd/test', $modules[0]->getLibrary());
|
||||
$this->assertEquals('lotgd/tests', $modules[0]->getLibrary());
|
||||
}
|
||||
|
||||
public function testModuleDoesNotExist()
|
||||
@@ -87,7 +87,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
$mm->unregister($game, 'lotgd/test', $package);
|
||||
$mm->unregister($game, 'lotgd/tests', $package);
|
||||
|
||||
$modules = $mm->getModules();
|
||||
$this->assertEmpty($modules);
|
||||
@@ -106,6 +106,8 @@ class ModuleManagerTest extends ModelTestCase
|
||||
),
|
||||
);
|
||||
|
||||
$library = 'lotgd/tests';
|
||||
|
||||
$package = $this->getMockForAbstractClass(PackageInterface::class);
|
||||
$package->method('getExtra')->willReturn(array(
|
||||
'subscriptions' => $subscriptions
|
||||
@@ -118,8 +120,8 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$eventManager->expects($this->exactly(2))
|
||||
->method('unsubscribe')
|
||||
->withConsecutive(
|
||||
array($this->equalTo($subscriptions[0]['pattern']), $this->equalTo($subscriptions[0]['class'])),
|
||||
array($this->equalTo($subscriptions[1]['pattern']), $this->equalTo($subscriptions[1]['class']))
|
||||
array($this->equalTo($subscriptions[0]['pattern']), $this->equalTo($subscriptions[0]['class']), $library),
|
||||
array($this->equalTo($subscriptions[1]['pattern']), $this->equalTo($subscriptions[1]['class']), $library)
|
||||
);
|
||||
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
@@ -130,7 +132,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
$mm->unregister($game, 'lotgd/test', $package);
|
||||
$mm->unregister($game, $library, $package);
|
||||
|
||||
$modules = $mm->getModules();
|
||||
$this->assertEmpty($modules);
|
||||
@@ -149,6 +151,8 @@ class ModuleManagerTest extends ModelTestCase
|
||||
),
|
||||
);
|
||||
|
||||
$library = 'lotgd/tests';
|
||||
|
||||
$package = $this->getMockForAbstractClass(PackageInterface::class);
|
||||
$package->method('getExtra')->willReturn(array(
|
||||
'subscriptions' => $subscriptions
|
||||
@@ -161,7 +165,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$eventManager->expects($this->exactly(1))
|
||||
->method('unsubscribe')
|
||||
->withConsecutive(
|
||||
array($this->equalTo($subscriptions[0]['pattern']), $this->equalTo($subscriptions[0]['class']))
|
||||
array($this->equalTo($subscriptions[0]['pattern']), $this->equalTo($subscriptions[0]['class']), $library)
|
||||
);
|
||||
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
@@ -172,7 +176,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
$mm->unregister($game, 'lotgd/test', $package);
|
||||
$mm->unregister($game, $library, $package);
|
||||
|
||||
$modules = $mm->getModules();
|
||||
$this->assertEmpty($modules);
|
||||
@@ -183,6 +187,8 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$package = $this->getMockForAbstractClass(PackageInterface::class);
|
||||
$package->method('getExtra')->willReturn(array());
|
||||
|
||||
$library = 'lotgd/tests2';
|
||||
|
||||
$eventManager = $this->getMockBuilder(EventManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@@ -195,7 +201,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
$mm->register($game, 'lotgd/test2', $package);
|
||||
$mm->register($game, $library, $package);
|
||||
|
||||
$modules = $mm->getModules();
|
||||
|
||||
@@ -203,7 +209,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$timeDiff = (new \DateTime())->getTimestamp() - $modules[1]->getCreatedAt()->getTimestamp();
|
||||
$this->assertLessThanOrEqual(5, $timeDiff);
|
||||
$this->assertGreaterThanOrEqual(-5, $timeDiff);
|
||||
$this->assertEquals('lotgd/test2', $modules[1]->getLibrary());
|
||||
$this->assertEquals($library, $modules[1]->getLibrary());
|
||||
}
|
||||
|
||||
public function testRegisterWithEvents()
|
||||
@@ -219,6 +225,8 @@ class ModuleManagerTest extends ModelTestCase
|
||||
),
|
||||
);
|
||||
|
||||
$library = 'lotgd/tests2';
|
||||
|
||||
$package = $this->getMockForAbstractClass(PackageInterface::class);
|
||||
$package->method('getExtra')->willReturn(array(
|
||||
'subscriptions' => $subscriptions
|
||||
@@ -231,8 +239,8 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$eventManager->expects($this->exactly(2))
|
||||
->method('subscribe')
|
||||
->withConsecutive(
|
||||
array($this->equalTo($subscriptions[0]['pattern']), $this->equalTo($subscriptions[0]['class'])),
|
||||
array($this->equalTo($subscriptions[1]['pattern']), $this->equalTo($subscriptions[1]['class']))
|
||||
array($this->equalTo($subscriptions[0]['pattern']), $this->equalTo($subscriptions[0]['class']), $library),
|
||||
array($this->equalTo($subscriptions[1]['pattern']), $this->equalTo($subscriptions[1]['class']), $library)
|
||||
);
|
||||
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
@@ -243,7 +251,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
$mm->register($game, 'lotgd/test2', $package);
|
||||
$mm->register($game, $library, $package);
|
||||
|
||||
$modules = $mm->getModules();
|
||||
|
||||
@@ -251,7 +259,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$timeDiff = (new \DateTime())->getTimestamp() - $modules[1]->getCreatedAt()->getTimestamp();
|
||||
$this->assertLessThanOrEqual(5, $timeDiff);
|
||||
$this->assertGreaterThanOrEqual(-5, $timeDiff);
|
||||
$this->assertEquals('lotgd/test2', $modules[1]->getLibrary());
|
||||
$this->assertEquals($library, $modules[1]->getLibrary());
|
||||
}
|
||||
|
||||
public function testRegisterWithInvalidEvents()
|
||||
@@ -267,6 +275,8 @@ class ModuleManagerTest extends ModelTestCase
|
||||
),
|
||||
);
|
||||
|
||||
$library = 'lotgd/tests2';
|
||||
|
||||
$package = $this->getMockForAbstractClass(PackageInterface::class);
|
||||
$package->method('getExtra')->willReturn(array(
|
||||
'subscriptions' => $subscriptions
|
||||
@@ -279,7 +289,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$eventManager->expects($this->exactly(1))
|
||||
->method('subscribe')
|
||||
->withConsecutive(
|
||||
array($this->equalTo($subscriptions[0]['pattern']), $this->equalTo($subscriptions[0]['class']))
|
||||
array($this->equalTo($subscriptions[0]['pattern']), $this->equalTo($subscriptions[0]['class']), $library)
|
||||
);
|
||||
|
||||
$game = $this->getMockBuilder(Game::class)
|
||||
@@ -290,7 +300,7 @@ class ModuleManagerTest extends ModelTestCase
|
||||
|
||||
$mm = new ModuleManager($this->getEntityManager());
|
||||
|
||||
$mm->register($game, 'lotgd/test2', $package);
|
||||
$mm->register($game, $library, $package);
|
||||
|
||||
$modules = $mm->getModules();
|
||||
|
||||
@@ -298,6 +308,6 @@ class ModuleManagerTest extends ModelTestCase
|
||||
$timeDiff = (new \DateTime())->getTimestamp() - $modules[1]->getCreatedAt()->getTimestamp();
|
||||
$this->assertLessThanOrEqual(5, $timeDiff);
|
||||
$this->assertGreaterThanOrEqual(-5, $timeDiff);
|
||||
$this->assertEquals('lotgd/test2', $modules[1]->getLibrary());
|
||||
$this->assertEquals($library, $modules[1]->getLibrary());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,3 +2,4 @@ event_subscriptions:
|
||||
-
|
||||
pattern: "/test\\.foo.*/"
|
||||
class: "LotGD\\Core\\Tests\\EventManagerTestInstalledSubscriber"
|
||||
library: "lotgd/tests"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
modules:
|
||||
-
|
||||
library: "lotgd/test"
|
||||
library: "lotgd/tests"
|
||||
createdAt: "2016-05-01"
|
||||
|
||||
Reference in New Issue
Block a user