...
 
Commits (3)
{
"name": "narrator/narrator-bundle",
"description": "Event library bundle",
"tags": [
"mleko",
"narrator",
"event",
"bundle",
"symfony"
],
"type": "library",
"require": {
"narrator/narrator": "^0.4",
"symfony/http-kernel": "^2.3|^3.0",
"symfony/config": "^2.3|^3.0",
"symfony/dependency-injection": "^2.3|^3.0"
},
"license": "MIT",
"authors": [
{
"name": "Daniel Król",
"email": "daniel@krol.me"
"name": "narrator/narrator-bundle",
"description": "Event library bundle",
"type": "library",
"keywords": [
"mleko",
"narrator",
"event",
"bundle",
"symfony"
],
"license": "MIT",
"authors": [
{
"name": "Daniel Król",
"email": "daniel@krol.me"
}
],
"require": {
"narrator/narrator": "^0.4",
"symfony/config": "^2.3|^3.0",
"symfony/dependency-injection": "^2.3|^3.0",
"symfony/http-kernel": "^2.3|^3.0"
},
"require-dev": {
"mikey179/vfsStream": "^1.6",
"phpunit/phpunit": "^5.6",
"symfony/expression-language": "^3.1",
"symfony/http-kernel": "^3.3"
},
"autoload": {
"psr-4": {
"Mleko\\Narrator\\Bundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Mleko\\Narrator\\Bundle\\Tests\\": "tests/"
}
},
"scripts": {
"test": "phpunit"
}
],
"autoload": {
"psr-4": {
"Mleko\\Narrator\\Bundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Mleko\\Narrator\\Bundle\\Tests\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^5.6",
"symfony/expression-language": "^3.1"
}
}
<?php
namespace Mleko\Narrator\Bundle\Tests\Integration;
use Mleko\Narrator\Bundle\Tests\Integration\TestApp\AppKernel;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\TestCase;
abstract class IntegrationTest extends TestCase
{
/**
* @var AppKernel
*/
protected $kernel;
/**
* @var vfsStreamDirectory
*/
protected $root;
protected function setUp()
{
/* force reload of ContainerClass */
$this->setRunTestInSeparateProcess(true);
$this->setPreserveGlobalState(false);
$this->root = vfsStream::setup('testRoot');
$cacheDir = vfsStream::newDirectory("cache", 0777);
$this->root->addChild($cacheDir);
$logDir = vfsStream::newDirectory("logs", 0777);
$this->root->addChild($logDir);
$this->kernel = new AppKernel("test", true);
$this->kernel->getContainerBuilder()->setParameter("kernel.secret", "secretChangeIt");
$this->kernel->setCacheDir($cacheDir->url());
$this->kernel->setLogDir($logDir->url());
$config = vfsStream::newFile("config.yml");
$this->root->addChild($config);
$this->kernel->setConfigPath($config->url());
}
}
<?php
namespace Mleko\Narrator\Bundle\Tests\Integration;
use Mleko\Narrator\EventEmitter;
use org\bovigo\vfs\vfsStream;
/**
* @runTestsInSeparateProcesses
*/
class SimpleEventListenerTest extends IntegrationTest
{
public function testDefaultEventBus()
{
$servicesConfig = vfsStream::newFile("services.xml");
$servicesConfig->setContent(<<<'EOF'
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service class="Mleko\Narrator\Bundle\Tests\Integration\TestApp\Counter" id="narrator.listener.counter">
<tag name="narrator.listener" event="stdClass"/>
</service>
</services>
</container>
EOF
);
$this->root->addChild($servicesConfig);
$this->kernel->setConfigPath($servicesConfig->url());
$this->kernel->boot();
$container = $this->kernel->getContainer();
$this->assertTrue($container->has("narrator.event_bus.default"));
$this->assertTrue($container->has("narrator.listener.counter"));
$container->get("narrator.event_bus.default")->emit(new \stdClass());
$this->assertEquals(1, $container->get("narrator.listener.counter")->getCount());
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
* @expectedExceptionMessageRegExp "You have requested a non-existent service \"narrator.event_bus.invalid\"\."
*/
public function testMissingEventBus()
{
$this->kernel->boot();
$container = $this->kernel->getContainer();
$container->get("narrator.event_bus.invalid");
}
public function testCustomEventBus()
{
$servicesConfig = vfsStream::newFile("config.yml");
$servicesConfig->setContent(<<<'EOF'
narrator:
event_bus:
default: ~
inheritance:
resolver:
type: instanceof
EOF
);
$this->root->addChild($servicesConfig);
$this->kernel->setConfigPath($servicesConfig->url());
$this->kernel->boot();
$container = $this->kernel->getContainer();
$this->assertTrue($container->has("narrator.event_bus.inheritance"));
/** @var EventEmitter $eventEmitter */
$this->assertNotNull($container->get("narrator.event_bus.inheritance"));
}
}
<?php
namespace Mleko\Narrator\Bundle\Tests\Integration\TestApp;
use Mleko\Narrator\Bundle\NarratorBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;
class AppKernel extends Kernel
{
private $cacheDir;
private $configPath;
private $logDir;
public function registerBundles()
{
return [
new NarratorBundle()
];
}
public function setConfigPath($configPath)
{
$this->configPath = $configPath;
}
public function getLogDir()
{
return $this->logDir;
}
public function setLogDir($logDir)
{
$this->logDir = $logDir;
}
public function getCacheDir()
{
return $this->cacheDir;
}
public function setCacheDir($dir)
{
$this->cacheDir = $dir;
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->configPath);
}
public function getContainerBuilder()
{
return parent::getContainerBuilder();
}
}
<?php
namespace Mleko\Narrator\Bundle\Tests\Integration\TestApp;
class Counter
{
private $count = 0;
private $lastEvent;
public function handle($event)
{
$this->count++;
$this->lastEvent = $event;
}
public function getCount()
{
return $this->count;
}
public function getLastEvent()
{
return $this->lastEvent;
}
}
......@@ -26,7 +26,7 @@ class ListenerServiceTest extends \PHPUnit_Framework_TestCase
$listener = new \Mleko\Narrator\Bundle\Listener\ListenerService('mock.listener', $this->container);
$event = new \stdClass();
$meta = new \Mleko\Narrator\Meta($event, 'strClass', 'stdClass', $this->getMockBuilder(\Mleko\Narrator\EventSource::class)->getMockForAbstractClass());
$meta = new \Mleko\Narrator\Meta($event, \stdClass::class, \stdClass::class, $this->getMockBuilder(\Mleko\Narrator\EventSource::class)->getMockForAbstractClass());
$listener->handle($event, $meta);
}
}