Overview

Namespaces

  • Budovy
  • Kdyby
    • BootstrapFormRenderer
      • DI
      • Latte
  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Config
        • Adapters
      • Diagnostics
      • Extensions
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
      • Diagnostics
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • PhpGenerator
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
  • NetteModule
  • Nextras
    • Datagrid
  • None
  • PHP
  • Tester
    • CodeCoverage
    • Runner
      • Output
  • Vodacek
    • Forms
      • Controls
  • WebLoader
    • Filter
    • Nette

Classes

  • Assert
  • DataProvider
  • DomQuery
  • Dumper
  • Environment
  • Helpers
  • TestCase

Exceptions

  • AssertException
  • TestCaseException
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Tester.
  5:  * Copyright (c) 2009 David Grudl (http://davidgrudl.com)
  6:  */
  7: 
  8: namespace Tester;
  9: 
 10: 
 11: /**
 12:  * Testing environment.
 13:  *
 14:  * @author     David Grudl
 15:  */
 16: class Environment
 17: {
 18:     /** Should Tester use console colors? */
 19:     const COLORS = 'NETTE_TESTER_COLORS';
 20: 
 21:     /** Test is runned by Runner */
 22:     const RUNNER = 'NETTE_TESTER_RUNNER';
 23: 
 24: 
 25:     /** @var bool  used for debugging Tester itself */
 26:     public static $debugMode = TRUE;
 27: 
 28:     /** @var bool */
 29:     public static $useColors;
 30: 
 31: 
 32:     /**
 33:      * Configures PHP environment.
 34:      * @return void
 35:      */
 36:     public static function setup()
 37:     {
 38:         self::$useColors = getenv(self::COLORS) !== FALSE
 39:             ? (bool) getenv(self::COLORS)
 40:             : (PHP_SAPI === 'cli' && ((function_exists('posix_isatty') && posix_isatty(STDOUT))
 41:                 || getenv('ConEmuANSI') === 'ON' || getenv('ANSICON') !== FALSE));
 42: 
 43:         class_exists('Tester\Runner\Job');
 44:         class_exists('Tester\Dumper');
 45:         class_exists('Tester\Assert');
 46: 
 47:         error_reporting(E_ALL | E_STRICT);
 48:         ini_set('display_errors', TRUE);
 49:         ini_set('html_errors', FALSE);
 50:         ini_set('log_errors', FALSE);
 51: 
 52:         set_exception_handler(array(__CLASS__, 'handleException'));
 53:         set_error_handler(function($severity, $message, $file, $line) {
 54:             if (in_array($severity, array(E_RECOVERABLE_ERROR, E_USER_ERROR)) || ($severity & error_reporting()) === $severity) {
 55:                 Environment::handleException(new \ErrorException($message, 0, $severity, $file, $line));
 56:             }
 57:             return FALSE;
 58:         });
 59: 
 60:         register_shutdown_function(function() {
 61:             Assert::$onFailure = array(__CLASS__, 'handleException'); // note that Runner is unable to catch this errors in CLI & PHP 5.4.0 - 5.4.6 due PHP bug #62725
 62: 
 63:             $error = error_get_last();
 64:             if (in_array($error['type'], array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE)) && ($error['type'] & error_reporting()) !== $error['type']) {
 65:                 register_shutdown_function(function() use ($error) {
 66:                     echo "\nFatal error: $error[message] in $error[file] on line $error[line]\n";
 67:                 });
 68:             }
 69:         });
 70: 
 71:         ob_start(function($s) {
 72:             return Environment::$useColors ? $s : Dumper::removeColors($s);
 73:         }, PHP_VERSION_ID < 50400 ? 2 : 1);
 74:     }
 75: 
 76: 
 77:     /** @internal */
 78:     public static function handleException($e)
 79:     {
 80:         echo self::$debugMode ? Dumper::dumpException($e) : "\nError: {$e->getMessage()}\n";
 81:         exit($e instanceof AssertException ? Runner\Job::CODE_FAIL : Runner\Job::CODE_ERROR);
 82:     }
 83: 
 84: 
 85:     /**
 86:      * Skips this test.
 87:      * @return void
 88:      */
 89:     public static function skip($message = '')
 90:     {
 91:         echo "\nSkipped:\n$message\n";
 92:         die(Runner\Job::CODE_SKIP);
 93:     }
 94: 
 95: 
 96:     /**
 97:      * locks the parallel tests.
 98:      * @return void
 99:      */
100:     public static function lock($name = '', $path = '')
101:     {
102:         static $lock;
103:         flock($lock = fopen($path . '/lock-' . md5($name), 'w'), LOCK_EX);
104:     }
105: 
106: }
107: 
API documentation generated by ApiGen 2.8.0