Store the module name along with event subscriptions

This commit is contained in:
Austen McDonald
2016-05-30 13:56:08 -07:00
parent 0d0458c87b
commit 86426aacdb
8 changed files with 70 additions and 34 deletions
+10 -6
View File
@@ -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()
+2 -2
View File
@@ -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
View File
@@ -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());
}
}
+1
View File
@@ -2,3 +2,4 @@ event_subscriptions:
-
pattern: "/test\\.foo.*/"
class: "LotGD\\Core\\Tests\\EventManagerTestInstalledSubscriber"
library: "lotgd/tests"
+1 -1
View File
@@ -1,4 +1,4 @@
modules:
-
library: "lotgd/test"
library: "lotgd/tests"
createdAt: "2016-05-01"