Esempio n. 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'];
 }
Esempio n. 2
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;
 }
Esempio n. 3
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');
         }
     }
 }
Esempio n. 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)));
 }
 /**
  * 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);
 }
<?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);
 public function setUp()
 {
     $this->basicServiceLocator = $this->getMock('Zend\\ServiceManager\\ServiceLocatorInterface');
     $this->basicServiceManager = Bootstrap::getServiceManager();
     $this->basicFactory = new BasicAuthenticationAdapterFactory($this->basicServiceManager->get('Config'));
 }
<?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();
Esempio n. 9
0
 public function testAnnotationBuilder()
 {
     $formGeneretor = $this->sm->get('formGenerator');
     $formGeneretor->setClass(get_class(new Post()))->getForm();
     $this->assertInstanceOf(get_class($formGeneretor), $formGeneretor);
 }
        });
        $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);
Esempio n. 11
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();
 public function setUp()
 {
     $this->digestServiceLocator = $this->prophesize('Zend\\ServiceManager\\ServiceLocatorInterface');
     $this->digestServiceManager = Bootstrap::getServiceManager();
     $this->digestFactory = new DigestAuthenticationAdapterFactory($this->digestServiceManager->get('Config'));
 }
<?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);
Esempio n. 14
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));
         }
     }
 }