public function setUp() { if (static::$serial) { // serialize report test because of database connection Environment::lock('db', dirname(TEMP_DIR)); } }
protected function setUp() { parent::setUp(); try { $this->driver = $this->getDriver(); } catch (PrerequisiteException $e) { Environment::skip($e->getMessage()); } }
/** * 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 static function setup($tempDir, $callback = NULL) { if (!class_exists('Tester\\Assert')) { echo "Install Nette Tester using `composer update --dev`\n"; exit(1); } self::$tempDir = $tempDir; self::$onBeforeContainerCreate = $callback; umask(0); \Tester\Environment::setup(); date_default_timezone_set('Europe/Prague'); if (class_exists('Tracy\\Debugger')) { \Tracy\Debugger::$logDirectory = self::$tempDir; } $_ENV = $_GET = $_POST = $_FILES = []; }
/** @return int|NULL */ public function run() { Environment::setupColors(); Environment::setupErrors(); ob_start(); $cmd = $this->loadOptions(); Environment::$debugMode = (bool) $this->options['--debug']; if (isset($this->options['--colors'])) { Environment::$useColors = (bool) $this->options['--colors']; } elseif (in_array($this->options['-o'], ['tap', 'junit'])) { Environment::$useColors = FALSE; } if ($cmd->isEmpty() || $this->options['--help']) { $cmd->help(); return; } $this->createPhpInterpreter(); if ($this->options['--info']) { $job = new Job(__DIR__ . '/info.php', $this->interpreter); $job->run(); echo $job->getOutput(); return; } if ($this->options['--coverage']) { $coverageFile = $this->prepareCodeCoverage(); } $runner = $this->createRunner(); $runner->setEnvironmentVariable(Environment::RUNNER, 1); $runner->setEnvironmentVariable(Environment::COLORS, (int) Environment::$useColors); if (isset($coverageFile)) { $runner->setEnvironmentVariable(Environment::COVERAGE, $coverageFile); } if ($this->options['-o'] !== NULL) { ob_clean(); } ob_end_flush(); if ($this->options['--watch']) { $this->watch($runner); return; } $result = $runner->run(); if (isset($coverageFile) && preg_match('#\\.(?:html?|xml)\\z#', $coverageFile)) { $this->finishCodeCoverage($coverageFile); } return $result ? 0 : 1; }
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(); }
protected function setUp() { parent::setUp(); if (!$this->prepared) { try { $this->databaseTester->prepareDatabaseTest(); } catch (DBALException $ex) { if (preg_match('~unknown database|access denied|2002|no such file~i', $ex->getMessage())) { Environment::skip('No test SQL database available'); } else { throw $ex; } } $this->prepared = TRUE; } else { $this->databaseTester->clearDatabase(); } }
/** @return int|NULL */ public function run() { Environment::setupColors(); Environment::setupErrors(); ob_start(); $cmd = $this->loadOptions(); Environment::$debugMode = (bool) $this->options['--debug']; if (isset($this->options['--colors'])) { Environment::$useColors = (bool) $this->options['--colors']; } elseif ($this->options['-o'] === 'tap') { Environment::$useColors = FALSE; } if ($cmd->isEmpty() || $this->options['--help']) { $cmd->help(); return; } $this->createPhpInterpreter(); if ($this->options['--info']) { $job = new Job(__DIR__ . '/info.php', $this->interpreter); $job->run(); echo $job->getOutput(); return; } if ($this->options['--coverage']) { $coverageFile = $this->prepareCodeCoverage(); } $runner = $this->createRunner(); if ($this->options['-o'] !== NULL) { ob_clean(); } ob_end_flush(); if ($this->options['--watch']) { $this->watch($runner); return; } $result = $runner->run(); if (isset($coverageFile)) { $this->finishCodeCoverage($coverageFile); } return $result ? 0 : 1; }
public static function setup($tempDir, $callback = NULL) { if (!class_exists('Tester\\Assert')) { echo "Install Nette Tester using `composer update --dev`\n"; exit(1); } self::$tempDir = $tempDir; self::$onBeforeContainerCreate = $callback; umask(0); if (!ob_get_level() > 0) { //\Tester\Environment::setup already called \Tester\Environment::setup(); } date_default_timezone_set('Europe/Prague'); if (class_exists('Tracy\\Debugger')) { \Tracy\Debugger::$logDirectory = self::$tempDir; } $_ENV = $_GET = $_POST = $_FILES = []; $_SERVER['HTTP_USER_AGENT'] = 'Awesome Browser'; $_SERVER['REMOTE_ADDR'] = '11.22.33.44'; $_SERVER['HTTP_HOST'] = $_SERVER['SERVER_NAME'] = 'test.bench'; }
/** @internal */ private function __testbench_createContainer() { if (!class_exists('Doctrine\\DBAL\\Connection')) { \Tester\Environment::skip('TDoctrine trait supports only Doctrine at this moment.'); } $container = \Testbench\ContainerFactory::create(FALSE); /** @var ConnectionMock $db */ $db = $container->getByType('Doctrine\\DBAL\\Connection'); if (!$db instanceof ConnectionMock) { $serviceNames = $container->findByType('Doctrine\\DBAL\\Connection'); throw new \LogicException(sprintf('The service %s should be instance of Ant\\Tests\\ConnectionMock, to allow lazy schema initialization.', reset($serviceNames))); } $db->onConnect[] = function (ConnectionMock $db) use($container) { if ($this->__testbench_databaseName !== NULL) { return; } try { $this->setupDatabase($db, $container); } catch (\Exception $e) { \Tester\Assert::fail($e->getMessage()); } }; return $container; }
protected function createConnection($params = []) { $options = array_merge(['user' => NULL, 'password' => NULL, 'sqlMode' => 'TRADITIONAL'], Environment::loadData(), $params); return new Connection($options); }
protected function changeRunLevel($testSpeed = \Testbench::FINE) { if ((int) getenv('RUNLEVEL') < $testSpeed) { \Tester\Environment::skip("Required runlevel '{$testSpeed}' but current runlevel is '" . (int) getenv('RUNLEVEL') . "' (higher runlevel means slower tests)\n" . "You can run this test with environment variable: 'RUNLEVEL={$testSpeed} vendor/bin/run-tests ...'\n"); } }
protected function lock($name) { \Tester\Environment::lock($name, TEST_DIR_TEMP); }
private function lock() { Environment::lock('db', $this->context->getParameters()['tempDir']); }
private function lock() { Environment::lock('db', $this->tempDir); }
protected function setUp() { parent::setUp(); Tester\Environment::lock('mysql_database', __DIR__ . '/../temporary'); $this->database = $this->connection(); }
/** * Do not check assertions were executed when there are constrainted mocks */ protected static function ignoreAssertionsWhenExpectations() { /** @var Mock $mock */ foreach (\Mockery::getContainer()->getMocks() as $mock) { /** @var ExpectationDirector $expectationDirector */ foreach ($mock->mockery_getExpectations() as $expectationDirector) { $expectations = $expectationDirector->getExpectations(); if (method_exists($expectationDirector, 'getDefaultExpectations')) { //mockery <=0.9.5 compatibility $expectations = array_merge($expectations, $expectationDirector->getDefaultExpectations()); } /** @var Expectation $expectation */ foreach ($expectations as $expectation) { if ($expectation->isCallCountConstrained()) { Environment::$checkAssertions = FALSE; return; } } } } }
exit(1); } $autoload->add('TestCases', __DIR__ . '/TestCases'); // configure environment Tester\Environment::setup(); class_alias('Tester\\Assert', 'Assert'); date_default_timezone_set('Europe/Prague'); // create temporary directory define('TEMP_DIR', __DIR__ . '/temp/' . time()); 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(); // load connection try { $config = \Tester\Environment::loadData(); } catch (\Exception $e) { $config = parse_ini_file(__DIR__ . '/databases.ini', TRUE); $config = reset($config); } $config['lazy'] = true; if (extension_loaded('xdebug')) { xdebug_disable(); Tester\CodeCoverage\Collector::start(__DIR__ . '/coverage.dat'); } function id($val) { return $val; } function run(Tester\TestCase $testCase) {
<?php require __DIR__ . '/../vendor/autoload.php'; if (!class_exists('Tester\\Assert')) { echo 'Install Nette Tester using "composer update --dev"', PHP_EOL; exit(1); } define('TEMP_DIR', __DIR__ . '/temp'); if (!file_exists(TEMP_DIR)) { echo 'Create directory for temporary testing files in path "' . TEMP_DIR . '".', PHP_EOL; exit(1); } if (!is_readable(TEMP_DIR) || !is_writable(TEMP_DIR)) { echo 'Set permissions for directory "' . TEMP_DIR . '" to full read and write.', PHP_EOL; exit(1); } \Tester\Environment::setup(); function clearTemp($directory = TEMP_DIR) { $files = \Nette\Utils\Finder::find('*')->exclude('.*')->in($directory); foreach ($files as $path => $file) { if ($file->isDir()) { clearTemp($path); @rmdir($path); } else { @unlink($path); } } @rmdir($directory); }
<?php namespace KhanovaSkola\Tests\Cislo; use Tester\Environment; if (@(!(include __DIR__ . '/../vendor/autoload.php'))) { echo "Install Nette Tester using `composer update`\n"; exit(1); } define('TEMP_DIR', __DIR__ . '/temp'); date_default_timezone_set('Europe/Prague'); Environment::setup(); if (getenv(Environment::RUNNER)) { # Runner header('Content-type: text/plain'); putenv('ANSICON=TRUE'); } elseif (PHP_SAPI === 'cli') { # CLI } else { # Browser }
<?php require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../src/Core/Entity.php'; require __DIR__ . '/../src/Core/Repository.php'; require __DIR__ . '/../src/Core/StoreManager/StoreManager.php'; require __DIR__ . '/models/AnimalEntity.php'; require __DIR__ . '/models/ZooEntity.php'; require __DIR__ . '/models/AnimalRepository.php'; require __DIR__ . '/models/Service.php'; \Tester\Environment::setup(); date_default_timezone_set('UTC'); \Tester\Environment::lock('core', __DIR__ . '/../temp');