setup() public static method

Configures testing environment.
public static setup ( ) : void
return void
示例#1
0
 /**
  * Prepares common test environment, not dependent on testing Nette application:
  *
  *      - sets fixed request time and timezone
  *      - purges _GET, _POST, _ENV
  *      - calls Tester\Environment::setup()
  *      - ensures tests temp directory exists
  *      - validates Mockery expectations on shutdown
  *
  * @param string $tempDir
  */
 public static function prepareTestEnvironment($tempDir = NULL)
 {
     if ($tempDir !== NULL) {
         static::$tempDir = $tempDir;
     }
     static::checkPreparedOnce();
     static::unifyConfiguration();
     Environment::setup();
     static::prepareTempDir();
     static::prepareMockery();
 }
示例#2
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;
 }
示例#3
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 = [];
 }
示例#4
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();
 }
示例#5
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';
 }
示例#6
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
}
示例#7
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);
}