Exemple #1
0
 protected function getRouterConfig()
 {
     $serviceManager = new \Zend\ServiceManager\ServiceManager(new \Zend\Mvc\Service\ServiceManagerConfig(array()));
     $serviceManager->setService('ApplicationConfig', include 'config/application.config.php');
     $serviceManager->get('ModuleManager')->loadModules();
     return $serviceManager->get('Config')['router']['routes'];
 }
 public function providesClassWithConstructionParameters()
 {
     $serviceManager = new \Zend\ServiceManager\ServiceManager();
     $serviceManager->setService('EventManager', new \Zend\EventManager\EventManager());
     $serviceManager->setService('Request', new \stdClass());
     $serviceManager->setService('Response', new \stdClass());
     return array(array('Zend\\Config\\Config', array('array' => array())), array('Zend\\Db\\Adapter\\Adapter', array('driver' => array('driver' => 'Pdo_Sqlite'))), array('Zend\\Mvc\\Application', array('configuration' => array(), 'serviceManager' => $serviceManager)));
 }
Exemple #3
0
function getServiceLocator()
{
    $config = Zend\Config\Factory::fromFile(findParentPath('config') . "/module.config.php");
    $serviceManagerConfig = new \Zend\ServiceManager\Config($config['service_manager']);
    $serviceManager = new \Zend\ServiceManager\ServiceManager($serviceManagerConfig);
    $serviceManager->setService('config', $config);
    return $serviceManager;
}
Exemple #4
0
 /**
  * @dataProvider servicesProvider
  */
 public function testServices($service, $class)
 {
     // Create temporary service manager with identical configuration.
     $config = static::$_serviceManager->get('config');
     $serviceManager = new \Zend\ServiceManager\ServiceManager($config['service_manager']);
     $serviceManager->setService('config', $config);
     $serviceManager->setService('Db', $this->createMock('Zend\\Db\\Adapter\\Adapter'));
     $this->assertEquals($class, get_class($serviceManager->get($service)));
 }
 public function testCreateServiceWithConfiguration()
 {
     $serviceManager = new \Zend\ServiceManager\ServiceManager();
     $serviceManager->setService('Config', array('ldc-user-profile' => array('url_path' => '/foo/bar')));
     $factory = new \LdcUserProfile\Options\ModuleOptionsFactory();
     $svc = $factory->createService($serviceManager);
     $this->assertInstanceOf('LdcUserProfile\\Options\\ModuleOptions', $svc);
     $this->assertEquals('/foo/bar', $svc->getUrlPath());
 }
 /**
  * Call
  */
 public function call()
 {
     //print_r('--middlewareServiceManager call()--');
     $serviceManagerUtillConfigObject = new \Utill\Service\Manager\config();
     $this->serviceManagerConfig = new \Zend\ServiceManager\Config($serviceManagerUtillConfigObject->getConfig());
     $serviceManager = new \Zend\ServiceManager\ServiceManager($this->serviceManagerConfig);
     $serviceManager->setService('slimApp', $this->app);
     $this->app->setServiceManager($serviceManager);
     $this->next->call();
 }
Exemple #7
0
 /**
  * @return EntityManager
  */
 protected function setupDoctrine()
 {
     $serviceManager = new \Zend\ServiceManager\ServiceManager(new \Zend\Mvc\Service\ServiceManagerConfig(array()));
     $serviceManager->setService('ApplicationConfig', $this->getTestConfig());
     $serviceManager->get('ModuleManager')->loadModules();
     $serviceManager->get('Application')->bootstrap();
     $this->em = $serviceManager->get('doctrine.entitymanager.orm_default');
     self::createDbSchema($this->em);
     return $this->em;
 }
 public function testCreateService()
 {
     $mockOptions = new \ZfcUser\Options\ModuleOptions();
     $mockMapper = \Mockery::mock('ZfcUser\\Mapper\\UserInterface');
     $serviceManager = new \Zend\ServiceManager\ServiceManager();
     $serviceManager->setService('zfcuser_module_options', $mockOptions);
     $serviceManager->setService('zfcuser_user_mapper', $mockMapper);
     $factory = new \LdcUserProfile\Extensions\ZfcUser\ZfcUserInputFilterFactory();
     $svc = $factory->createService($serviceManager);
     $this->assertInstanceOf('LdcUserProfile\\Extensions\\ZfcUser\\ZfcUserInputFilter', $svc);
 }
Exemple #9
0
 public function preDispatch()
 {
     $controller = $this->getActionController();
     $controllerName = get_class($controller);
     if ($this->serviceManager->has($controllerName)) {
         $this->serviceManager->setService('controller', $controller);
         if (!$this->serviceManager->get($controllerName)) {
             throw new \Exception('Invalid Controller');
         }
     }
 }
 public function testCreateService()
 {
     $mockOptions = new \ZfcUser\Options\ModuleOptions();
     $mockOptions->setUserEntityClass('ArrayObject');
     $mockHydrator = \Mockery::mock('Zend\\Stdlib\\Hydrator\\HydratorInterface');
     $serviceManager = new \Zend\ServiceManager\ServiceManager();
     $serviceManager->setService('zfcuser_module_options', $mockOptions);
     $serviceManager->setService('zfcuser_user_hydrator', $mockHydrator);
     $factory = new \LdcUserProfile\Extensions\ZfcUser\ZfcUserFieldsetFactory();
     $svc = $factory->createService($serviceManager);
     $this->assertInstanceOf('LdcUserProfile\\Extensions\\ZfcUser\\ZfcUserFieldset', $svc);
     $this->assertSame($mockHydrator, $svc->getHydrator());
     $this->assertInstanceOf('ArrayObject', $svc->getObject());
 }
 public function testCreateServiceWithUnregisterExtension()
 {
     $moduleOptions = new ModuleOptions();
     $moduleOptions->setRegisteredExtensions(array('foo' => false));
     $mockExtension = \Mockery::mock('LdcUserProfile\\Extensions\\AbstractExtension');
     $mockExtension->shouldReceive('getName')->andReturn('foo');
     $serviceManager = new \Zend\ServiceManager\ServiceManager();
     $serviceManager->setService('ldc-user-profile_module_options', $moduleOptions);
     //$serviceManager->setService('foo', $mockExtension);
     $factory = new \LdcUserProfile\Service\ProfileServiceFactory();
     $svc = $factory->createService($serviceManager);
     $this->assertInstanceOf('LdcUserProfile\\Service\\ProfileService', $svc);
     $this->assertFalse($svc->hasExtension('foo'));
     $this->assertFalse($svc->hasExtension($mockExtension));
 }
 public function testCreateService()
 {
     $mockUserService = \Mockery::mock('ZfcUser\\Service\\User');
     $mockFieldset = \Mockery::mock('Zend\\Form\\FieldsetInterface');
     $mockInputFilter = \Mockery::mock('Zend\\InputFilter\\InputFilterInterface');
     $serviceManager = new \Zend\ServiceManager\ServiceManager();
     $serviceManager->setService('zfcuser_user_service', $mockUserService);
     $serviceManager->setService('ldc-user-profile_extension_zfcuser_fieldset', $mockFieldset);
     $serviceManager->setService('ldc-user-profile_extension_zfcuser_inputfilter', $mockInputFilter);
     $factory = new \LdcUserProfile\Extensions\ZfcUser\ZfcUserExtensionFactory();
     $svc = $factory->createService($serviceManager);
     $this->assertInstanceOf('LdcUserProfile\\Extensions\\ZfcUser\\ZfcUserExtension', $svc);
     $this->assertSame($mockUserService, $svc->getUserService());
     $this->assertSame($mockFieldset, $svc->getFieldset());
     $this->assertSame($mockInputFilter, $svc->getInputFilter());
 }
 /**
  * Truncate all tables in database
  * 
  * @access public
  */
 public function truncateDatabase()
 {
     $entityManager = $this->serviceManager->get('doctrine.entitymanager.orm_default');
     $connection = $entityManager->getConnection();
     if (empty(self::$truncateQuery)) {
         $schemaManager = $connection->getSchemaManager();
         $tables = $schemaManager->listTables();
         $query = '';
         $query .= 'set foreign_key_checks=0;';
         foreach ($tables as $table) {
             $name = $table->getName();
             $query .= 'DELETE FROM ' . $name . ';VACUUM;';
         }
         $query .= 'set foreign_key_checks=1;';
         self::$truncateQuery = $query;
     }
     $connection->executeQuery(self::$truncateQuery);
 }
 public function setUp()
 {
     $this->basicServiceLocator = $this->getMock('Zend\\ServiceManager\\ServiceLocatorInterface');
     $this->basicServiceManager = Bootstrap::getServiceManager();
     $this->basicFactory = new BasicAuthenticationAdapterFactory($this->basicServiceManager->get('Config'));
 }
 public function setup()
 {
     $sm = new \Zend\ServiceManager\ServiceManager();
     $sm->setService('MongoDb', new MongoDbMock());
     $this->_sm = $sm;
 }
Exemple #16
0
 /**
  * Get mock backend manager
  *
  * @return BackendManager
  */
 protected function getBackendManagerWithMockSolr()
 {
     $sm = new \Zend\ServiceManager\ServiceManager();
     $pm = new BackendManager($sm);
     $mockBackend = $this->getMockBuilder('VuFindSearch\\Backend\\Solr\\Backend')->disableOriginalConstructor()->getMock();
     $mockConnector = $this->getMockBuilder('VuFindSearch\\Backend\\Solr\\Connector')->disableOriginalConstructor()->setMethods(['getUrl', 'getTimeout', 'setTimeout', 'write'])->getMock();
     $mockBackend->expects($this->any())->method('getConnector')->will($this->returnValue($mockConnector));
     $mockConnector->expects($this->any())->method('getTimeout')->will($this->returnValue(30));
     $mockConnector->expects($this->any())->method('getUrl')->will($this->returnValue('http://localhost:8080/solr/biblio'));
     $sm->setService('Solr', $mockBackend);
     return $pm;
 }
<?php

class ServiceConfiguration extends \Zend\ServiceManager\Config
{
    public function configureServiceManager(\Zend\ServiceManager\ServiceManager $serviceManager)
    {
        $serviceManager->setFactory('A', function () {
            return new A();
        });
        $serviceManager->setShared('A', false);
    }
}
$config = new ServiceConfiguration();
$serviceManager = new \Zend\ServiceManager\ServiceManager($config);
//trigger autoloaders
$a = $serviceManager->get('A');
unset($a);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
    $a = $serviceManager->get('A');
}
$t2 = microtime(true);
$results = ['time' => $t2 - $t1, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024];
echo json_encode($results);
Exemple #18
0
 public function testAnnotationBuilder()
 {
     $formGeneretor = $this->sm->get('formGenerator');
     $formGeneretor->setClass(get_class(new Post()))->getForm();
     $this->assertInstanceOf(get_class($formGeneretor), $formGeneretor);
 }
<?php

class ServiceConfiguration extends \Zend\ServiceManager\Config
{
    public function configureServiceManager(\Zend\ServiceManager\ServiceManager $serviceManager)
    {
        $serviceManager->setFactory('A', function () {
            return new A();
        });
        $serviceManager->setShared('A', true);
        $serviceManager->setFactory('B', function ($serviceManager) {
            return new B($serviceManager->get('A'));
        });
        $serviceManager->setShared('B', false);
    }
}
$config = new ServiceConfiguration();
$serviceManager = new \Zend\ServiceManager\ServiceManager($config);
//trigger autoloaders
$j = $serviceManager->get('B');
unset($a);
$t1 = microtime(true);
for ($i = 0; $i < 10000; $i++) {
    $j = $serviceManager->get('B');
}
$t2 = microtime(true);
$results = ['time' => $t2 - $t1, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024];
echo json_encode($results);
Exemple #20
0
 /**
  * Get new model instance via service manager
  *
  * This method allows temporarily overriding services with manually supplied
  * instances. This is useful for injecting mock objects which will be passed
  * to the model's constructor by a factory. A clone of the service manager is
  * used to avoid interference with other tests.
  *
  * @param array $overrideServices Optional associative array (name => instance) with services to override
  * @return object Model instance
  */
 protected function _getModel(array $overrideServices = array())
 {
     if (empty($overrideServices)) {
         $serviceManager = static::$serviceManager;
     } else {
         // Create temporary service manager with identical configuration.
         $config = static::$serviceManager->get('config');
         $serviceManager = new \Zend\ServiceManager\ServiceManager($config['service_manager']);
         // Clone 'config' service
         $serviceManager->setService('config', $config);
         // If not explicitly overridden, copy database services to avoid
         // expensive reconnect or table setup which has already been done.
         if (!isset($overrideServices['Db'])) {
             $serviceManager->setService('Db', static::$serviceManager->get('Db'));
         }
         if (!isset($overrideServices['Database\\Nada'])) {
             $serviceManager->setService('Database\\Nada', static::$serviceManager->get('Database\\Nada'));
         }
         // Override specified services
         foreach ($overrideServices as $name => $service) {
             $serviceManager->setService($name, $service);
         }
     }
     // Always build a new instance.
     return $serviceManager->build($this->_getClass());
 }
        });
        $serviceManager->setShared('E', false);
        $serviceManager->setFactory('F', function ($serviceManager) {
            return new F($serviceManager->get('E'));
        });
        $serviceManager->setShared('F', false);
        $serviceManager->setFactory('G', function ($serviceManager) {
            return new G($serviceManager->get('F'));
        });
        $serviceManager->setShared('G', false);
        $serviceManager->setFactory('H', function ($serviceManager) {
            return new H($serviceManager->get('G'));
        });
        $serviceManager->setShared('H', false);
        $serviceManager->setFactory('I', function ($serviceManager) {
            return new I($serviceManager->get('H'));
        });
        $serviceManager->setShared('I', false);
        $serviceManager->setFactory('J', function ($serviceManager) {
            return new J($serviceManager->get('I'));
        });
        $serviceManager->setShared('J', false);
    }
}
$config = new ServiceConfiguration();
$serviceManager = new \Zend\ServiceManager\ServiceManager($config);
for ($i = 0; $i < $argv[1]; $i++) {
    $j = $serviceManager->get('J');
}
$results = ['time' => 0, 'files' => count(get_included_files()), 'memory' => memory_get_peak_usage() / 1024 / 1024];
echo json_encode($results);
Exemple #22
0
<?php

// load configuration
$config = (require 'config.php');
// build container
$container = new \Zend\ServiceManager\ServiceManager(new \Zend\ServiceManager\Config($config['dependencies']));
// create config service
$container->setService('config', $config);
return $container;
Exemple #23
0
 /**
  * Method applied from ServiceLocatorAwareInterface, required to retreive service locator object
  *
  * @return Zend\ServiceManager\ServiceManager
  */
 public function getServiceLocator()
 {
     return $this->serviceLocator->getServiceLocator();
 }
Exemple #24
0
 /**
  * Boot Rails.
  *
  * It requires at least paths to libraries and/or Composer Autoloader
  * to autoload classes. An instance of Rails\Loader\Loader can also be
  * passed instead.
  *
  * @param array $config
  */
 public static function boot(array $config)
 {
     if (self::$booted) {
         return;
     }
     /**
      * Loader.
      */
     if (!isset($config['loader'])) {
         throw new BadMethodCallException('Requires at least loader instance or configuration');
     } else {
         if (is_array($config['loader'])) {
             // require_once __DIR__ . '/Rails/Loader/Loader.php';
             $loader = new Rails\Loader\Loader();
             if (isset($config['loader']['paths'])) {
                 $loader->addPaths($config['loader']['paths']);
             }
             if (isset($config['loader']['composerAutoloader'])) {
                 $loader->setComposerAutoloader($config['loader']['composerAutoloader']);
             } else {
                 $loader->addPath(__DIR__ . '/Rails');
             }
             $loader->register();
         } elseif ($config['loader'] instanceof Rails\Loader\Loader) {
             $loader = $config['loader'];
         } else {
             throw new InvalidArgumentException(sprintf('Loader must be either array or instance of Rails\\Loader\\Loader, %s passed', gettype($config['loader'])));
         }
     }
     /**
      * Service Manager.
      */
     $sm = new Zend\ServiceManager\ServiceManager();
     self::$serviceManager = $sm;
     $sm->setService('loader', $loader);
     /**
      * Global configuration.
      */
     $sm->setService('rails.config', new Rails\ActiveSupport\ArrayObject(['use_cache' => false]));
     /**
      * Inflector.
      */
     $sm->setFactory('inflector', function () {
         return new Rails\ActiveSupport\Inflector\Inflector(new Rails\ActiveSupport\Inflector\Inflections\EnglishInflections(), 'en');
     });
     /**
      * Translator.
      */
     $sm->setFactory('i18n', function () {
         $tr = new Rails\I18n\LoadingTranslator();
         $tr->setDefaultLocale('en');
         $tr->setLoader(new Rails\I18n\Loader());
         # Add Rails' locales paths to i18n loader
         $tr->loader()->addPaths([__DIR__ . '/Rails/ActiveSupport/Carbon/locales', __DIR__ . '/Rails/I18n/locales']);
         return $tr;
     });
     self::$booted = true;
 }
<?php

/**
 * Sample Zend Expressive Application for php[architect]
 *
 * This file is subject to the terms and conditions defined in
 * file 'LICENSE', which is part of this source code package.
 *
 * @link      https://github.com/dragonmantank/phparch-zend-expressive for the canonical source repository
 * @copyright Copyright (c) 2015 Chris Tankersley
 * @license   See LICENSE
 */
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
$config = (require 'config.php');
$serviceManagerConfig = new Zend\ServiceManager\Config($config['dependencies']);
$container = new Zend\ServiceManager\ServiceManager($serviceManagerConfig);
$container->setService('config', $config);
$app = $container->get('Zend\\Expressive\\Application');
$app->run();
 public function setUp()
 {
     $this->digestServiceLocator = $this->prophesize('Zend\\ServiceManager\\ServiceLocatorInterface');
     $this->digestServiceManager = Bootstrap::getServiceManager();
     $this->digestFactory = new DigestAuthenticationAdapterFactory($this->digestServiceManager->get('Config'));
 }
<?php

require dirname(__DIR__) . '/vendor/autoload.php';
use Zend\Diactoros;
use ExpressiveAsync\Server;
use React\EventLoop\Factory;
use React\Socket\Server as SocketServer;
use ExpressiveAsync\Application;
use React\Promise\Deferred;
$serviceManager = new \Zend\ServiceManager\ServiceManager();
$eventLoop = Factory::create();
$socketServer = new SocketServer($eventLoop);
$httpServer = new Server($socketServer);
$serviceManager->setFactory('EventLoop', function () use($eventLoop) {
    return $eventLoop;
});
$serviceManager->setInvokableClass('Zend\\Expressive\\Router\\RouterInterface', 'Zend\\Expressive\\Router\\FastRouteRouter');
$router = new \Zend\Expressive\Router\FastRouteRouter();
$router->addRoute(new \Zend\Expressive\Router\Route('/', function ($request, $response) use($eventLoop) {
    echo 'Home executed' . PHP_EOL;
    return new Diactoros\Response\HtmlResponse('Hello World.');
}, ['GET'], 'home'));
$router->addRoute(new \Zend\Expressive\Router\Route('/deferred', function ($request, $response) use($eventLoop) {
    // create a request, wait 1-5 seconds and then return a response.
    $deferred = new Deferred();
    $eventLoop->addTimer(rand(1, 5), function () use($deferred) {
        echo 'Timer executed' . PHP_EOL;
        $deferred->resolve(new Diactoros\Response\HtmlResponse('Deferred response.'));
    });
    return new \ExpressiveAsync\DeferredResponse($deferred->promise());
}, ['GET'], 'deferred'));
Exemple #28
0
    public function test()
    {
        /*
        $viewConfigExample = [
            'some-view' => [ // view name
                'template' => 'some-template', // html template
                //--- not required options
                'viewModel' => 'some-view-model|\Some\ViewModel::class', // Instance of ViewModel
                'extend' => 'parent-view', // extended view
                'capture' => 'some-capture', // for grouping views
                'children' => [
                    'child-view'// array of views
                ],
                'childrenDynamicLists' => [ // will be generated by list from one of child
                    'child-view' => 'listVar' // every entry in listVar will be setted to genereted child
                ],
                'data' => [ // required data
                    'fromGlobal' => 'varName', // // will be set as variables from global data
                    'fromParent' => 'varName', // will be set as variables by calling getVariable('varName') from parent
                    'static' => [ // will be set as variables
                        'key' => 'value'
                    ],
                ],
            ],
        ];
        */
        $renderer = new PhpRenderer();
        $resolver = new Resolver\AggregateResolver();
        $map = new Resolver\TemplateMapResolver(array('page' => __DIR__ . '/view/page.phtml', 'comments-list' => __DIR__ . '/view/comments-list.phtml', 'comment' => __DIR__ . '/view/comment.phtml', 'user' => __DIR__ . '/view/user.phtml'));
        $stack = new Resolver\TemplatePathStack(array('script_paths' => array(__DIR__ . '/view')));
        $resolver->attach($map)->attach($stack)->attach(new Resolver\RelativeFallbackResolver($map))->attach(new Resolver\RelativeFallbackResolver($stack));
        $renderer->setResolver($resolver);
        $view = new View();
        $response = new Response();
        $view->setResponse($response);
        $strategy = new PhpRendererStrategy($renderer);
        $strategy->attach($view->getEventManager());
        $viewConfig = ['layouts' => ['layout' => ['template' => 'layout']], 'contents' => ['page' => ['layout' => 'layout', 'template' => 'page', 'children' => ['comments-list' => ['extend' => 'comments-list', 'template' => 'comments-list'], 'comment-create' => ['template' => 'comment-create', 'children' => ['myself-info' => ['viewModel' => \Sebaks\ViewTest\MyselfViewModel::class, 'template' => 'user'], 'comment-create-form' => ['template' => 'form', 'children' => ['form-element-textarea' => ['capture' => 'form-element', 'template' => 'form-element-textarea'], 'form-element-button' => ['capture' => 'form-element', 'template' => 'form-element-button']]]]], 'users-table' => ['template' => 'table', 'children' => ['table-head-rows' => ['template' => 'table-tr', 'data' => ['fromParent' => 'rows'], 'children' => ['table-th' => ['template' => 'table-th', 'capture' => 'table-td', 'data' => ['fromParent' => 'value']]], 'childrenDynamicLists' => ['table-th' => 'rows']], 'table-body-rows' => ['template' => 'table-tr', 'data' => ['fromParent' => 'rows'], 'children' => ['table-td' => ['template' => 'table-td', 'data' => ['fromParent' => 'value']]], 'childrenDynamicLists' => ['table-td' => 'rows']]], 'childrenDynamicLists' => ['table-body-rows' => 'bodyRows', 'table-head-rows' => 'headRows'], 'data' => ['static' => ['headRows' => [['Id', 'Name']], 'bodyRows' => [['1', 'John'], ['2', 'Helen']]]]]]]], 'blocks' => ['comments-list' => ['children' => ['comment' => ['viewModel' => \Sebaks\ViewTest\CommentViewModel::class, 'template' => 'comment', 'children' => ['user' => ['viewModel' => \Sebaks\ViewTest\UserViewModel::class, 'template' => 'user', 'data' => ['fromParent' => 'userId', 'static' => ['class' => 'user']], 'children' => ['location' => ['viewModel' => \Sebaks\ViewTest\LocationViewModel::class, 'template' => 'location', 'data' => ['fromParent' => 'countryId']]]]], 'data' => ['fromParent' => ['foo' => 'bar', 'comment' => 'comment']]]], 'childrenDynamicLists' => ['comment' => 'comments'], 'data' => ['fromGlobal' => ['foo' => 'bar', 'result' => 'comments']]]]];
        $data = ['result' => [['id' => 'c1', 'userId' => 'u1', 'text' => 'text of c1'], ['id' => 'c2', 'userId' => 'u2', 'text' => 'text of c2']]];
        $serviceLocator = new \Zend\ServiceManager\ServiceManager();
        $serviceLocator->setInvokableClass(\Sebaks\ViewTest\CommentViewModel::class, \Sebaks\ViewTest\CommentViewModel::class, false);
        $serviceLocator->setInvokableClass(\Sebaks\ViewTest\UserViewModel::class, \Sebaks\ViewTest\UserViewModel::class, false);
        $serviceLocator->setInvokableClass(\Sebaks\ViewTest\LocationViewModel::class, \Sebaks\ViewTest\LocationViewModel::class, false);
        $serviceLocator->setInvokableClass(\Sebaks\ViewTest\MyselfViewModel::class, \Sebaks\ViewTest\MyselfViewModel::class, false);
        /////////////////////
        $config = ['sebaks-view' => $viewConfig];
        $serviceLocator->setService('config', $config);
        $serviceLocator->setService('EventManager', new EventManager());
        $request = new Request();
        $serviceLocator->setService('Request', $request);
        //$response = new Response();
        $serviceLocator->setService('Response', $response);
        $e = new MvcEvent();
        $e->setRequest($request);
        $e->setResponse($response);
        $dispatchResult = new ViewModel();
        $dispatchResult->setVariables($data);
        $e->setResult($dispatchResult);
        $routeMatch = new RouteMatch([]);
        $routeMatch->setMatchedRouteName('page');
        $e->setRouteMatch($routeMatch);
        $application = new Application([], $serviceLocator);
        $e->setApplication($application);
        /////////////////////
        $viewBuilder = new BuildViewListener();
        $viewBuilder->injectLayout($e);
        $pageViewModel = $e->getViewModel();
        $view->render($pageViewModel);
        $result = $response->getBody();
        $expected = '<body><ul><li>text of c1
<div class="user">John<span class="location">Ukraine</span></div></li><li>text of c2
<div class="user">Helen<span class="location">United States</span></div></li></ul>
<div class="">Me</div><form><textarea></textarea><button type="submit">Submit</button></form><table>
    <thead>
        <tr><th>Id</th><th>Name</th></tr>    </thead>
    <tbody>
        <tr><td>1</td><td>John</td></tr><tr><td>2</td><td>Helen</td></tr>    </tbody>
</table></body>';
        $this->assertEquals($expected, $result);
    }
Exemple #29
0
 /**
  * Bootstrap the tests.
  * 
  * @return void
  */
 public static function init()
 {
     // Module root directory path.
     $modulePath = dirname(__DIR__);
     // Module tests directory path.
     $testPath = __DIR__;
     // Application configuration.
     $configuration = [];
     // If a developer configuration file exists.
     if (is_file($configurationFile = $testPath . '/Configuration.php')) {
         // Retrieve the developer configuration.
         $configuration = (include $configurationFile);
     } else {
         if (is_file($configurationFile = $testPath . '/Configuration.php.dist')) {
             // Retrieve the distributed configuration.
             $configuration = (include $configurationFile);
         } else {
             // We cannot continue without a configuration file.
             throw new RuntimeException('Unable to locate a configuration file.');
         }
     }
     // If a module autoload file exists.
     if (is_file($autoloadFile = $modulePath . '/vendor/autoload.php')) {
         // Retrieve the module autoloader
         $loader = (include $autoloadFile);
     } else {
         if (is_file($autoloadFile = $modulePath . '/../../vendor/autoload.php')) {
             // Retrieve the application autoloader.
             $loader = (include $autoloadFile);
         } else {
             // We cannot continue without a composer autoload file.
             throw new RuntimeException('Unable to locate a composer autoload file.');
         }
     }
     // If additional autoload options are defined.
     if (isset($configuration['autoload'])) {
         // Define the additional autoload types and corresponding methods.
         $autoloadTypes = ['psr-0' => 'add', 'psr-4' => 'addPsr4'];
         // Iterate over each of the autoload types.
         foreach ($autoloadTypes as $type => $method) {
             // If the autoload type is defined in the application configuration.
             if (isset($configuration['autoload'][$type])) {
                 // Iterate over each of the autoload type options.
                 foreach ($configuration['autoload'][$type] as $name => $paths) {
                     // Cast the path to an array encase a single path is given.
                     $paths = (array) $paths;
                     // Iterate over each of the paths.
                     foreach ($paths as $index => $path) {
                         // Set the path as the parent directory's absolute path.
                         $paths[$index] = dirname($path);
                     }
                     // Register a set of paths for a given name.
                     $loader->{$method}($name, $paths);
                 }
             }
         }
     }
     // If we are unable to locate the Zend MVC Application class.
     if (!class_exists('Zend\\Mvc\\Application')) {
         // We cannot continue without the dependencies being loaded.
         throw new RuntimeException('Unable to load the Zend framework. Install dependencies using Composer.');
     }
     // Create a service manager config object.
     $serviceManagerConfig = new Zend\Mvc\Service\ServiceManagerConfig();
     // Create a server manager object and inject the configuration.
     $serviceManager = new Zend\ServiceManager\ServiceManager($serviceManagerConfig);
     // Set the configuration used when initializing the application.
     $serviceManager->setService('ApplicationConfig', $configuration);
     // Retrieve the module manager.
     $moduleManager = $serviceManager->get('ModuleManager');
     // Load available modules.
     $moduleManager->loadModules();
     // If a test case class is defined.
     if (isset($configuration['module_test_case_class'])) {
         // Retrieve the test case class.
         $moduleTestCaseClass = $configuration['module_test_case_class'];
         // If the test case class has a method named setServiceManager.
         if (method_exists($moduleTestCaseClass, 'setConfiguration')) {
             // Pass the configuration to the test case class.
             call_user_func_array($moduleTestCaseClass . '::setConfiguration', array($configuration));
         }
         // If the test case class has a method named setServiceManager.
         if (method_exists($moduleTestCaseClass, 'setServiceManager')) {
             // Pass an instance of the service manager to the test case class.
             call_user_func_array($moduleTestCaseClass . '::setServiceManager', array($serviceManager));
         }
     }
 }
Exemple #30
0
<?php

/* Check PHP */
if (version_compare(PHP_VERSION, '5.4.0') < 0) {
    throw new RuntimeException('PHP 5.4+ is required (currently running PHP ' . PHP_VERSION . ')');
}
/* Setup PHP */
ini_set('error_reporting', E_ALL | E_STRICT);
ini_set('default_charset', 'UTF-8');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 0);
ini_set('date.timezone', 'Europe/Berlin');
chdir(dirname(dirname(dirname(__DIR__))));
/* Setup constants */
define('EP3_BS_DEV', true);
/* Setup autoloader */
$autoloaderFile = 'vendor/autoload.php';
if (!is_readable($autoloaderFile)) {
    throw new RuntimeException('Composer autoloader is required.');
}
$autoloader = (require $autoloaderFile);
/* Setup modules */
$moduleConfig = array('module_listener_options' => array('module_paths' => array('module', 'vendor')), 'modules' => array('User'));
$serviceManager = new Zend\ServiceManager\ServiceManager(new Zend\Mvc\Service\ServiceManagerConfig());
$serviceManager->setService('ApplicationConfig', $moduleConfig);
$serviceManager->get('ModuleManager')->loadModules();