Author: David Grudl
示例#1
0
文件: Job.php 项目: nette/tester
 /**
  * Runs single test.
  * @param  int RUN_ASYNC | RUN_COLLECT_ERRORS
  * @return void
  */
 public function run($flags = NULL)
 {
     foreach ($this->envVars as $name => $value) {
         putenv("{$name}={$value}");
     }
     $this->proc = proc_open($this->interpreter->getCommandLine() . ' -d register_argc_argv=on ' . Helpers::escapeArg($this->file) . ' ' . implode(' ', $this->args), [['pipe', 'r'], ['pipe', 'w'], ['pipe', 'w']], $pipes, dirname($this->file), NULL, ['bypass_shell' => TRUE]);
     foreach (array_keys($this->envVars) as $name) {
         putenv($name);
     }
     list($stdin, $this->stdout, $stderr) = $pipes;
     fclose($stdin);
     if ($flags & self::RUN_COLLECT_ERRORS) {
         $this->stderr = $stderr;
     } else {
         fclose($stderr);
     }
     if ($flags & self::RUN_ASYNC) {
         stream_set_blocking($this->stdout, 0);
         // on Windows does not work with proc_open()
         if ($this->stderr) {
             stream_set_blocking($this->stderr, 0);
         }
     } else {
         while ($this->isRunning()) {
             usleep(self::RUN_USLEEP);
             // stream_select() doesn't work with proc_open()
         }
     }
 }
示例#2
0
文件: Job.php 项目: jave007/test
 /**
  * Runs single test.
  * @param  int RUN_ASYNC | RUN_COLLECT_ERRORS
  * @return void
  */
 public function run($flags = NULL)
 {
     putenv(Environment::RUNNER . '=1');
     putenv(Environment::COLORS . '=' . (int) Environment::$useColors);
     $this->proc = proc_open($this->interpreter->getCommandLine() . ' -n -d register_argc_argv=on ' . \Tester\Helpers::escapeArg($this->file) . ' ' . implode(' ', $this->args), array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, dirname($this->file), NULL, array('bypass_shell' => TRUE));
     list($stdin, $this->stdout, $stderr) = $pipes;
     fclose($stdin);
     if ($flags & self::RUN_COLLECT_ERRORS) {
         $this->stderr = $stderr;
     } else {
         fclose($stderr);
     }
     if ($flags & self::RUN_ASYNC) {
         stream_set_blocking($this->stdout, 0);
         // on Windows does not work with proc_open()
         if ($this->stderr) {
             stream_set_blocking($this->stderr, 0);
         }
     } else {
         while ($this->isRunning()) {
             usleep(self::RUN_USLEEP);
             // stream_select() doesn't work with proc_open()
         }
     }
 }
示例#3
0
 protected function createWeb()
 {
     Helpers::purge($this->wwwDir);
     Helpers::purge($this->wwwDir . '/images');
     $image = Image::fromBlank(500, 500);
     $image->save($this->wwwDir . '/images/image.jpg');
 }
示例#4
0
 /**
  * Setup database
  */
 protected function setUp()
 {
     parent::setUp();
     \Tester\Helpers::lock('db', dirname(TEMP_DIR));
     $this->connection = $this->getConnection();
     $this->selectionFactory = $this->getSelectionFactory();
     $this->connection->beginTransaction();
     $this->emptyDatabase();
     $this->createDatabase();
     $this->connection->commit();
 }
示例#5
0
 /**
  * @param string $outDir Where to store images
  * @param string $rootDir Root directory of tests, to shorten filenames
  */
 public function __construct($outDir, $rootDir)
 {
     $this->enabled = (bool) getenv('MAKE_SCREENSHOTS');
     // false - not set, i.e. default
     if (!$this->enabled) {
         return;
     }
     if (!is_dir($outDir)) {
         mkdir($outDir, 0777, TRUE);
     }
     Tester\Helpers::purge($outDir);
     $this->outDir = $outDir;
     $this->rootDir = $rootDir;
 }
示例#6
0
 /**
  * Setup testing environment
  * @param string $rootDir absolute path to the root of the project
  * @global string $_GLOBALS['TEMP_DIR'] TEMP_DIR is defined here
  */
 public static function setup($rootDir)
 {
     // configure environment
     umask(0);
     Environment::setup();
     class_alias('Tester\\Assert', 'Assert');
     date_default_timezone_set('Europe/Prague');
     // create temporary directory
     $uniqueName = isset($_SERVER['argv']) ? md5(serialize($_SERVER['argv'])) : getmypid();
     define('TEMP_DIR', $rootDir . '/tmp/' . $uniqueName);
     Helpers::purge(TEMP_DIR);
     @chmod(TEMP_DIR, 0777);
     // intentional silencer
     Debugger::$logDirectory = TEMP_DIR;
 }
 public function __construct($path, $args = NULL)
 {
     $this->path = \Tester\Helpers::escapeArg($path);
     $proc = @proc_open("{$this->path} -n {$args} -v", array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, NULL, NULL, array('bypass_shell' => TRUE));
     $output = stream_get_contents($pipes[1]);
     $error = stream_get_contents($pipes[2]);
     if (proc_close($proc)) {
         throw new \Exception("Unable to run '{$path}': " . preg_replace('#[\\r\\n ]+#', ' ', $error));
     } elseif (!preg_match('#^PHP (\\S+).*c(g|l)i#i', $output, $matches)) {
         throw new \Exception("Unable to detect PHP version (output: {$output}).");
     }
     $this->version = $matches[1];
     $this->cgi = strcasecmp($matches[2], 'g') === 0;
     $this->xdebug = strpos($output, 'Xdebug') > 0;
     $this->arguments = $args;
 }
 public function __construct($path, $args = NULL)
 {
     $this->path = Helpers::escapeArg($path);
     $proc = proc_open("{$this->path} -n {$args} -V", array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, NULL, NULL, array('bypass_shell' => TRUE));
     $output = stream_get_contents($pipes[1]);
     $this->error = trim(stream_get_contents($pipes[2]));
     if (proc_close($proc)) {
         throw new \Exception("Unable to run '{$path}': " . preg_replace('#[\\r\\n ]+#', ' ', $this->error));
     } elseif (!preg_match('#^PHP ([\\w.-]+)#im', $output, $matches)) {
         throw new \Exception("Unable to detect PHP version (output: {$output}).");
     } elseif (version_compare($matches[1], '7.0.0', '<')) {
         throw new \Exception('Unable to use phpdbg on PHP < 7.0.0.');
     }
     $this->version = $matches[1];
     $this->arguments = $args;
 }
示例#9
0
文件: Job.php 项目: xnovk/test
 /**
  * Runs single test.
  * @param  bool  wait till process ends
  * @return void
  */
 public function run($blocking = TRUE)
 {
     putenv(Environment::RUNNER . '=1');
     putenv(Environment::COLORS . '=' . (int) Environment::$useColors);
     $this->proc = proc_open($this->php->getCommandLine() . ' -n -d register_argc_argv=on ' . \Tester\Helpers::escapeArg($this->file) . ' ' . $this->args, array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, dirname($this->file), NULL, array('bypass_shell' => TRUE));
     list($stdin, $this->stdout, $stderr) = $pipes;
     fclose($stdin);
     fclose($stderr);
     if ($blocking) {
         while ($this->isRunning()) {
             usleep(self::RUN_USLEEP);
             // stream_select() doesn't work with proc_open()
         }
     } else {
         stream_set_blocking($this->stdout, 0);
     }
 }
 public function __construct($path, $args = NULL)
 {
     $this->path = Helpers::escapeArg($path);
     $proc = proc_open("{$this->path} -n {$args} -v", array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, NULL, NULL, array('bypass_shell' => TRUE));
     $output = stream_get_contents($pipes[1]);
     $this->error = trim(stream_get_contents($pipes[2]));
     if (proc_close($proc)) {
         throw new \Exception("Unable to run '{$path}': " . preg_replace('#[\\r\\n ]+#', ' ', $this->error));
     } elseif (!preg_match('#^PHP (\\S+).*c(g|l)i#i', $output, $matches)) {
         throw new \Exception("Unable to detect PHP version (output: {$output}).");
     }
     $this->version = $matches[1];
     $this->cgi = strcasecmp($matches[2], 'g') === 0;
     $this->arguments = $args;
     $job = new Job(__DIR__ . '/info.php', $this, array('xdebug'));
     $job->run();
     $this->xdebug = !$job->getExitCode();
 }
示例#11
0
 public static function setup($rootDir)
 {
     // configure environment
     umask(0);
     Tester\Environment::setup();
     class_alias('Tester\\Assert', 'Assert');
     date_default_timezone_set('Europe/Prague');
     // create temporary directory
     define('TEMP_DIR', $rootDir . '/tmp/' . (isset($_SERVER['argv']) ? md5(serialize($_SERVER['argv'])) : getmypid()));
     Tester\Helpers::purge(TEMP_DIR);
     @chmod(TEMP_DIR, 0777);
     Tracy\Debugger::$logDirectory = TEMP_DIR;
     //		$_SERVER = array_intersect_key($_SERVER, array_flip(array(
     //			'PHP_SELF', 'SCRIPT_NAME', 'SERVER_ADDR', 'SERVER_SOFTWARE', 'HTTP_HOST', 'DOCUMENT_ROOT', 'OS', 'argc', 'argv'
     //		)));
     $_SERVER['REQUEST_TIME'] = 1234567890;
     $_ENV = $_GET = $_POST = $_FILES = array();
 }
示例#12
0
 public function __construct($path, $args = NULL)
 {
     $this->path = Helpers::escapeArg($path);
     $proc = @proc_open("{$this->path} --php {$args} -r " . Helpers::escapeArg('echo HHVM_VERSION . "|" . PHP_VERSION;'), array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, NULL, NULL, array('bypass_shell' => TRUE));
     $output = stream_get_contents($pipes[1]);
     $error = stream_get_contents($pipes[2]);
     if (proc_close($proc)) {
         throw new \Exception("Unable to run '{$path}': " . preg_replace('#[\\r\\n ]+#', ' ', $error));
     } elseif (count($tmp = explode('|', $output)) !== 2) {
         throw new \Exception("Unable to detect HHVM version (output: {$output}).");
     }
     list($this->version, $this->phpVersion) = $tmp;
     if (version_compare($this->version, '3.3.0', '<')) {
         throw new \Exception('HHVM below version 3.3.0 is not supported.');
     }
     $this->arguments = '--php -d hhvm.log.always_log_unhandled_exceptions=false ' . ($args ? " {$args}" : '');
     // HHVM issue #3019
 }
示例#13
0
 /**
  * @param null|string $configFile
  * @param bool $defaultConfig
  * @return Nette\DI\Container|\SystemContainer
  */
 public static function createContainer($configFile = NULL, $defaultConfig = TRUE)
 {
     // create temporary directory
     $tempDir = __DIR__ . '/../temp/' . (isset($_SERVER['argv']) ? md5(serialize($_SERVER['argv'])) : getmypid()) . Nette\Utils\Random::generate();
     Tester\Helpers::purge($tempDir);
     $configurator = new Nette\Configurator();
     $configurator->setTempDirectory($tempDir);
     $configurator->addParameters(array('container' => array('class' => 'SystemContainer_' . md5(time())), 'fixturesDir' => FIXTURES_DIR, 'tempDir' => $tempDir, 'wwwDir' => $tempDir));
     $configurator->addConfig(__DIR__ . '/../nette-reset.neon');
     if ($defaultConfig === TRUE) {
         $configurator->addConfig(__DIR__ . '/../config.neon');
     }
     if ($configFile !== NULL) {
         $configurator->addConfig($configFile);
     }
     $container = $configurator->createContainer();
     /** @var Nette\Http\IRequest $httpRequest */
     $httpRequest = $container->getByType('Nette\\Http\\IRequest');
     $httpRequest->getUrl()->setHost('localhost');
     // with empty host not work properly
     $ems = $container->findByType('Doctrine\\ORM\\EntityManager');
     if (count($ems) === 1) {
         /** @var EntityManager $em */
         $em = $container->getService($ems[0]);
         $schemaTool = new SchemaTool($em);
         $schemaTool->createSchema($em->getMetadataFactory()->getAllMetadata());
     }
     $dms = $container->findByType('Doctrine\\ODM\\MongoDB\\DocumentManager');
     if (count($dms) === 1) {
         /** @var DocumentManager $dm */
         $dm = $container->getService($dms[0]);
         $dm->getSchemaManager()->createDatabases();
         $dm->getSchemaManager()->createCollections();
     }
     return $container;
 }
示例#14
0
 public function boot(Nette\DI\Container $container, $databaseName)
 {
     $this->windows = array();
     $this->waitForSeleniumSlot();
     $this->serviceLocator = $container;
     TesterHelpers::setup();
     // ensure error & exception helpers are registered
     $this->httpServer = new HttpServer();
     $env = (array) $this->options[self::OPTION_ENV_VARIABLES] + array($this->options[self::OPTION_ENV_PREFIX] . '_DEBUG' => '0', $this->options[self::OPTION_ENV_PREFIX] . '_SELENIUM' => '1', $this->options[self::OPTION_ENV_PREFIX] . '_DATABASE' => $databaseName, $this->options[self::OPTION_ENV_PREFIX] . '_LOG_DIR' => TEMP_DIR, $this->options[self::OPTION_ENV_PREFIX] . '_TEMP_DIR' => TEMP_DIR);
     $this->httpServer->start($this->serviceLocator->expand($this->options[self::OPTION_ROUTER]), $env);
     $httpRequest = new Nette\Http\Request($this->httpServer->getUrl(), array(), array(), array(), array(), array(), 'GET');
     $this->serviceLocator->removeService('httpRequest');
     $this->serviceLocator->addService('httpRequest', $httpRequest);
     $this->sessionFactory = new SessionFactory($this->serviceLocator, $this->httpServer, $this->options);
     $this->currentSession = $this->sessionFactory->create();
     $this->currentSession->setContext($this);
     $this->windows[] = $this->currentSession;
     if ($this->options[self::OPTION_VIDEO_ENABLE]) {
         $this->videoRecorder = new VideoRecorder(TEMP_DIR);
         $this->videoRecorder->start();
     }
 }
示例#15
0
 /** @return void */
 private function createPhpInterpreter()
 {
     $args = '';
     if ($this->options['-c']) {
         $args .= ' -c ' . Helpers::escapeArg($this->options['-c']);
     } elseif (!$this->options['--info']) {
         echo "Note: No php.ini is used.\n";
     }
     foreach ($this->options['-d'] as $item) {
         $args .= ' -d ' . Helpers::escapeArg($item);
     }
     // Is the executable Zend PHP or HHVM?
     $proc = @proc_open($this->options['-p'] . ' --version', array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, NULL, NULL, array('bypass_shell' => TRUE));
     $output = stream_get_contents($pipes[1]);
     $error = stream_get_contents($pipes[2]);
     if (proc_close($proc)) {
         throw new \Exception("Unable to run '{$this->options['-p']}': " . preg_replace('#[\\r\\n ]+#', ' ', $error));
     }
     if (preg_match('#HipHop VM#', $output)) {
         $this->interpreter = new HhvmPhpInterpreter($this->options['-p'], $args);
     } else {
         $this->interpreter = new ZendPhpInterpreter($this->options['-p'], $args);
     }
 }
示例#16
0
 /** @return void */
 private function createPhpInterpreter()
 {
     $args = '';
     if ($this->options['-c']) {
         $args .= ' -c ' . Helpers::escapeArg($this->options['-c']);
     } elseif (!$this->options['--info']) {
         echo "Note: No php.ini is used.\n";
     }
     if (in_array($this->options['-o'], array('tap', 'junit'))) {
         $args .= ' -d html_errors=off';
     }
     foreach ($this->options['-d'] as $item) {
         $args .= ' -d ' . Helpers::escapeArg($item);
     }
     // Is the executable Zend PHP or HHVM?
     $proc = @proc_open($this->options['-p'] . ' --version', array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, NULL, NULL, array('bypass_shell' => TRUE));
     if ($proc === FALSE) {
         throw new \Exception('Cannot run PHP interpreter ' . $this->options['-p'] . '. Use -p option.');
     }
     $output = stream_get_contents($pipes[1]);
     $error = stream_get_contents($pipes[2]);
     if (proc_close($proc)) {
         throw new \Exception("Unable to run '{$this->options['-p']}': " . preg_replace('#[\\r\\n ]+#', ' ', $error));
     }
     if (preg_match('#HipHop VM#', $output)) {
         $this->interpreter = new HhvmPhpInterpreter($this->options['-p'], $args);
     } else {
         $this->interpreter = new ZendPhpInterpreter($this->options['-p'], $args);
     }
     if ($this->interpreter->getErrorOutput()) {
         echo Dumper::color('red', 'PHP startup error: ' . $this->interpreter->getErrorOutput()) . "\n";
         if ($this->interpreter->isCgi()) {
             echo "(note that PHP CLI generates better error messages)\n";
         }
     }
 }
示例#17
0
 private function getAnnotations($file)
 {
     $annotations = Helpers::parseDocComment(file_get_contents($file));
     $testName = (isset($annotations[0]) ? preg_replace('#^TEST:\\s*#i', '', $annotations[0]) . ' | ' : '') . implode(DIRECTORY_SEPARATOR, array_slice(explode(DIRECTORY_SEPARATOR, $file), -3));
     return array($annotations, $testName);
 }
 public function lockDb()
 {
     Tester\Helpers::lock('db', dirname(TEMP_DIR));
 }
示例#19
0
 /**
  * @param  string
  * @param  string
  */
 public function addPhpIniOption($name, $value = NULL)
 {
     $this->commandLine .= ' -d ' . Helpers::escapeArg($name . ($value === NULL ? '' : "={$value}"));
 }
示例#20
0
<?php

require __DIR__ . '/../../../vendor/autoload.php';
Tester\Environment::setup();
date_default_timezone_set('Europe/Prague');
$configurator = new Nette\Configurator();
//$configurator->enableDebugger(__DIR__ . '/log');
$configurator->setTempDirectory(__DIR__ . '/temp');
$configurator->createRobotLoader()->addDirectory(__DIR__ . '/../app')->addDirectory(__DIR__ . '/../libs')->register();
$configurator->addConfig(__DIR__ . '/../app/config/config.neon');
$configurator->addConfig(__DIR__ . '/config.test.local.neon');
$container = $configurator->createContainer();
\Tester\Helpers::purge(__DIR__ . '/log');
class EntityResuscitator extends \Nette\Object
{
    /**
     * @var \LeanMapper\IMapper
     */
    private $mapper;
    /**
     * @var \LeanMapper\Connection
     */
    private $connection;
    /**
     * @var \LeanMapper\IEntityFactory
     */
    private $entityFactory;
    public function __construct(\LeanMapper\IMapper $mapper, \LeanMapper\Connection $connection, \LeanMapper\IEntityFactory $entityFactory)
    {
        $this->mapper = $mapper;
        $this->connection = $connection;
示例#21
0
<?php

require __DIR__ . '/../vendor/autoload.php';
if (!class_exists('Tester\\Assert')) {
    echo "Install Nette Tester using `composer update --dev`\n";
    exit(1);
}
Tester\Environment::setup();
\Tester\Helpers::purge(__DIR__ . '/temp');
$configurator = new Nette\Configurator();
$configurator->setDebugMode(FALSE);
$configurator->setTempDirectory(__DIR__ . '/temp');
$configurator->createRobotLoader()->addDirectory(__DIR__ . '/../src')->register();
$configurator->addConfig(__DIR__ . '/config.neon');
return $configurator->createContainer();
示例#22
0
<?php

if (@(!(include __DIR__ . '/../vendor/autoload.php'))) {
    echo 'Install Nette Tester using `composer update --dev`';
    exit(1);
}
// configure environment
Tester\Environment::setup();
class_alias('Tester\\Assert', 'Assert');
date_default_timezone_set('Europe/Prague');
// create temporary directory
define('TEMP_DIR', __DIR__ . '/tmp/test' . getmypid());
@mkdir(dirname(TEMP_DIR));
// @ - directory may already exist
\Tester\Helpers::purge(TEMP_DIR);
$_SERVER = array_intersect_key($_SERVER, array_flip(array('PHP_SELF', 'SCRIPT_NAME', 'SERVER_ADDR', 'SERVER_SOFTWARE', 'HTTP_HOST', 'DOCUMENT_ROOT', 'OS', 'argc', 'argv')));
$_SERVER['REQUEST_TIME'] = 1234567890;
$_ENV = $_GET = $_POST = array();
function id($val)
{
    return $val;
}
function run(Tester\TestCase $testCase)
{
    $testCase->run(isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : NULL);
}
示例#23
0
文件: bootstrap.php 项目: h4kuna/menu
<?php

use Tester\Environment;
use Tester\Helpers;
use Tracy\Debugger;
if (@(!(include __DIR__ . '/vendor/autoload.php'))) {
    echo 'Install Nette Tester using `composer update --dev`';
    exit(1);
}
require_once './functions.php';
Debugger::enable(FALSE);
// configure environment
Environment::setup();
date_default_timezone_set('Europe/Prague');
// create temporary directory
define('TEMP_DIR', __DIR__ . '/temp/');
Helpers::purge(TEMP_DIR);
ini_set('session.save_path', TEMP_DIR);
示例#24
0
文件: setup.php 项目: bitbang/http
use Bitbang\Http\Tests;
use Tester\Helpers;
require __DIR__ . '/server/BackgroundProcess.php';
echo "\n";
if (defined('HHVM_VERSION')) {
    echo "# HTTP server cannot start under HHVM, run Tester by Zend PHP.\n";
} else {
    @mkdir(__DIR__ . '/temp');
    # @ = directory may already exist
    $config = parse_ini_file(__DIR__ . '/server.ini', TRUE)['listen'];
    echo "# Starting HTTP server for tests on {$config['address']}:{$config['port']}... ";
    $server = new Tests\BackgroundProcess();
    $server->start(Helpers::escapeArg(PHP_BINARY) . " -S {$config['address']}:{$config['port']} -d always_populate_raw_post_data=-1" . Helpers::escapeArg(__DIR__ . '/server/index.php'), __DIR__ . '/temp/http.log', __DIR__ . '/temp/http.log');
    echo "done\n";
    putenv("TESTS_HTTP_LISTEN={$config['address']}:{$config['port']}");
    echo "# Starting SSL wrapper for tests on {$config['address']}:{$config['port_ssl']}... ";
    $wrapper = new Tests\BackgroundProcess();
    $wrapper->start(Helpers::escapeArg(PHP_BINARY) . ' ' . Helpers::escapeArg(__DIR__ . '/server/ssl-wrapper.php'), __DIR__ . '/temp/ssl-wrapper.log', __DIR__ . '/temp/ssl-wrapper.log');
    echo "done\n";
    putenv("TESTS_HTTPS_LISTEN={$config['address']}:{$config['port_ssl']}");
    register_shutdown_function(function () use($server, $wrapper) {
        echo "\n";
        echo '# Shutting down SSL wrapper... ';
        $wrapper->terminate();
        echo "done\n";
        echo '# Shutting down HTTP server... ';
        $server->terminate();
        echo "done\n";
    });
}
echo "\n";