/** * It should automatically switch to the travis logger if the * CONTINUOUS_INTEGRATION environment variable is set. */ public function testTravisLogger() { putenv('CONTINUOUS_INTEGRATION=1'); $container = new Container(['PhpBench\\Extension\\CoreExtension'], ['path' => 'hello', 'config_path' => '/path/to/phpbench.json']); $container->init(); $this->assertEquals('travis', $container->getParameter('progress')); }
public function initUnoptimized() { $container = new Container(); $container->register('bicycle_factory', function ($c) { return new \PhpBench\Benchmarks\Container\Acme\BicycleFactory(); }); $this->container = $container; }
public function configure(Container $container) { $container->register('xdebug.command.profile', function (Container $container) { return new ProfileCommand($container->get('console.command.handler.runner')); }, array('console.command' => array())); $container->register('benchmark.executor.xdebug', function (Container $container) { return new XDebugExecutor($container->get('benchmark.remote.launcher')); }, array('benchmark_executor' => array('name' => 'xdebug'))); }
public static function run() { $config = self::loadConfig(); $container = new Container($config['extensions']); unset($config['extensions']); $container->configure(); $container->mergeParameters($config); $container->build(); $container->get('console.application')->run(); }
public static function run() { // Converts warnings to exceptions ErrorHandler::register(); $config = self::loadConfig(); $container = new Container($config['extensions']); unset($config['extensions']); $container->configure(); $container->mergeParameters($config); $container->build(); $container->get('console.application')->run(); }
private static function loadConfig(Container $container) { global $argv; $configPaths = array(); $bootstrapOverride = null; foreach ($argv as $arg) { if ($configFile = self::parseOption($arg, 'config')) { if (!file_exists($configFile)) { echo sprintf('Config file "%s" does not exist', $configFile) . PHP_EOL; exit(1); } $configPaths = array($configFile); } if ($value = self::parseOption($arg, 'bootstrap', 'b')) { $bootstrapOverride = $value; } } if (empty($configPaths)) { $configPaths = array(getcwd() . '/phpbench.json', getcwd() . '/phpbench.json.dist'); } foreach ($configPaths as $configPath) { if (!file_exists($configPath)) { continue; } $config = file_get_contents($configPath); try { $parser = new JsonParser(); $parser->parse($config); } catch (ParsingException $e) { echo 'Error parsing config file:' . PHP_EOL . PHP_EOL; echo $e->getMessage(); exit(1); } $config = json_decode($config, true); $config['config_path'] = $configPath; if (isset($config['bootstrap'])) { $config['bootstrap'] = self::getBootstrapPath(dirname($configPath), $config['bootstrap']); } $container->mergeParameters($config); } if ($bootstrapOverride) { $container->setParameter('bootstrap', self::getBootstrapPath(getcwd(), $bootstrapOverride)); } }
public static function run(ClassLoader $autoloader) { // Converts warnings to exceptions ErrorHandler::register(); $config = self::loadConfig(); if (isset($config['extension_autoloader']) && $config['extension_autoloader']) { $autoloadFile = $config['extension_autoloader']; if (!file_exists($autoloadFile)) { throw new \InvalidArgumentException(sprintf('Could not find extension autoload file "%s"', $autoloadFile)); } $autoloader->unregister(); include $autoloadFile; $autoloader->register(true); } $extensions = $config['extensions']; $extensions[] = 'PhpBench\\Extension\\CoreExtension'; unset($config['extensions']); $container = new Container($extensions, $config); $container->init(); $container->get('console.application')->run(); }
private function relativizeConfigPath(Container $container) { if (null === ($path = $container->getParameter('path'))) { return; } if (substr($path, 0, 1) === '/') { return; } $container->setParameter('path', sprintf('%s/%s', dirname($container->getParameter('config_path')), $path)); }
protected function getContainer() { $container = new Container($this->extensions, $this->config); $container->init(); return $container; }
public function load(Container $container) { $container->register('foobar', function ($container) { $stdClass = new \stdClass(); $stdClass->foobar = $container->getParameter('foo'); return $stdClass; }); }
public function load(Container $container) { if (!class_exists(Version::class)) { throw new \RuntimeException('The DBAL extension requires the "doctrine/dbal" package. Run `composer require --dev "doctrine/dbal"`'); } $container->register('storage.driver.dbal.connection', function (Container $container) { static $connection; if ($connection) { return $connection; } $params = $container->getParameter('storage.dbal.connection'); if (isset($params['path'])) { $params['path'] = PhpBench::normalizePath($params['path']); } $connection = DriverManager::getConnection($params); return $connection; }); $container->register('storage.driver.dbal.connection_manager', function (Container $container) { return new Storage\Driver\Dbal\ConnectionManager($container->get('storage.driver.dbal.connection')); }); $container->register('storage.driver.dbal', function (Container $container) { return new Storage\Driver\DbalDriver($container->get('storage.driver.dbal.loader'), $container->get('storage.driver.dbal.persister'), $container->get('storage.driver.dbal.repository')); }, ['storage_driver' => ['name' => 'dbal']]); $container->register('storage.driver.dbal.persister', function (Container $container) { return new Storage\Driver\Dbal\Persister($container->get('storage.driver.dbal.connection_manager')); }); $container->register('storage.driver.dbal.loader', function (Container $container) { return new Storage\Driver\Dbal\Loader($container->get('storage.driver.dbal.repository')); }); $container->register('storage.driver.dbal.visitor.token_value', function (Container $container) { return new Storage\Driver\Dbal\Visitor\TokenValueVisitor($container->get('storage.uuid_resolver')); }); $container->register('storage.driver.dbal.repository', function (Container $container) { return new Storage\Driver\Dbal\Repository($container->get('storage.driver.dbal.connection_manager'), $container->get('storage.driver.dbal.visitor.token_value')); }); $container->register('command.dbal.migrate', function (Container $container) { return new MigrateCommand($container->get('storage.driver.dbal.connection')); }, ['console.command' => []]); }
public function benchInitCoreExtension() { $container = new Container(['PhpBench\\Extension\\CoreExtension']); $container->init(); }
public function load(Container $container) { $container->register('xdebug.command.profile', function (Container $container) { return new ProfileCommand($container->get('console.command.handler.runner'), $container->get('xdebug.command.handler.output_dir')); }, ['console.command' => []]); $container->register('xdebug.command.trace', function (Container $container) { return new TraceCommand($container->get('console.command.handler.runner'), $container->get('xdebug.renderer.trace'), $container->get('xdebug.command.handler.output_dir')); }, ['console.command' => []]); $container->register('xdebug.command.handler.output_dir', function (Container $container) { return new OutputDirHandler($container->getParameter('xdebug.output_dir')); }); $container->register('benchmark.executor.xdebug_profile', function (Container $container) { return new ProfileExecutor($container->get('benchmark.remote.launcher')); }, ['benchmark_executor' => ['name' => 'xdebug_profile']]); $container->register('xdebug.executor.xdebug_trace', function (Container $container) { return new TraceExecutor($container->get('benchmark.remote.launcher')); }, ['benchmark_executor' => ['name' => 'xdebug_trace']]); $container->register('xdebug.renderer.trace', function (Container $container) { return new TraceRenderer($container->get('phpbench.formatter')); }); $container->mergeParameter('executors', require_once __DIR__ . '/config/executors.php'); $container->mergeParameter('reports', require_once __DIR__ . '/config/generators.php'); }