示例#1
0
文件: TestCase.php 项目: b4nan/utils
 public function setUp()
 {
     if (static::$serial) {
         // serialize report test because of database connection
         Environment::lock('db', dirname(TEMP_DIR));
     }
 }
示例#2
0
 protected function setUp()
 {
     parent::setUp();
     try {
         $this->driver = $this->getDriver();
     } catch (PrerequisiteException $e) {
         Environment::skip($e->getMessage());
     }
 }
示例#3
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;
 }
示例#4
0
 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 = [];
 }
示例#5
0
 /** @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;
 }
示例#6
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();
 }
 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();
     }
 }
示例#8
0
 /** @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;
 }
示例#9
0
 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';
 }
示例#10
0
 /** @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);
 }
示例#12
0
 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");
     }
 }
示例#13
0
 protected function lock($name)
 {
     \Tester\Environment::lock($name, TEST_DIR_TEMP);
 }
示例#14
0
 private function lock()
 {
     Environment::lock('db', $this->context->getParameters()['tempDir']);
 }
示例#15
0
 private function lock()
 {
     Environment::lock('db', $this->tempDir);
 }
示例#16
0
 protected function setUp()
 {
     parent::setUp();
     Tester\Environment::lock('mysql_database', __DIR__ . '/../temporary');
     $this->database = $this->connection();
 }
示例#17
0
 /**
  * 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;
                 }
             }
         }
     }
 }
示例#18
0
    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)
{
示例#19
0
<?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);
}
示例#20
0
<?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
}
示例#21
0
文件: boostrap.php 项目: kravcik/core
<?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');