public function testCreateFactory()
 {
     $serviceManager = \MalocherCqrsModuleTest\Bootstrap::getServiceManager();
     $defaultConfig = $serviceManager->get('config');
     $config = array('cqrs' => array('default_bus' => 'test-bus', 'adapters' => array('Malocher\\Cqrs\\Adapter\\ArrayMapAdapter' => array('buses' => array('MalocherCqrsModuleTest\\Mock\\TestBus' => array('MalocherCqrsModuleTest\\Mock\\TestCommand' => array('alias' => 'testcommandhandler', 'method' => 'handleTestCommand')))))));
     $config = \Zend\Stdlib\ArrayUtils::merge($defaultConfig, $config);
     $serviceManager->setAllowOverride(true);
     $serviceManager->setService('config', $config);
     $serviceManager->setService('testcommandhandler', new \MalocherCqrsModuleTest\Mock\TestCommandHandler());
     $gate = $serviceManager->get('malocher.cqrs.gate');
     $this->assertInstanceOf('Malocher\\Cqrs\\Gate', $gate);
     $this->assertEquals('test-bus', $gate->getBus()->getName());
     $command = new \MalocherCqrsModuleTest\Mock\TestCommand();
     $gate->getBus()->invokeCommand($command);
     $this->assertTrue($command->isInvoked());
 }
Example #2
0
    }
    protected static function initAutoloader()
    {
        $vendorPath = static::findParentPath('vendor');
        if (is_readable($vendorPath . '/autoload.php')) {
            $loader = (include $vendorPath . '/autoload.php');
        } else {
            $zf2Path = getenv('ZF2_PATH') ?: (defined('ZF2_PATH') ? ZF2_PATH : (is_dir($vendorPath . '/ZF2/library') ? $vendorPath . '/ZF2/library' : false));
            if (!$zf2Path) {
                throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.');
            }
            include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
        }
        AutoloaderFactory::factory(array('Zend\\Loader\\StandardAutoloader' => array('autoregister_zf' => true, 'namespaces' => array(__NAMESPACE__ => __DIR__ . '/' . __NAMESPACE__))));
    }
    protected static function findParentPath($path)
    {
        $dir = __DIR__;
        $previousDir = '.';
        while (!is_dir($dir . '/' . $path)) {
            $dir = dirname($dir);
            if ($previousDir === $dir) {
                return false;
            }
            $previousDir = $dir;
        }
        return $dir . '/' . $path;
    }
}
Bootstrap::init();