| 1 |
dc33f4
|
Seldaek |
<?php |
|
| 2 |
↓
|
Seldaek |
|
|
| 3 |
↓
|
Seldaek |
error_reporting(E_ALL|E_STRICT); |
|
| 4 |
1e2469
|
Seldaek |
if (!ini_get('date.timezone')) |
|
| 5 |
dc33f4
|
Seldaek |
date_default_timezone_set('CET'); |
|
| 6 |
19287d
|
Seldaek |
|
|
| 7 |
1c727d
|
Seldaek |
define('DWOO_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR.'cache'); |
|
| 8 |
↓
|
Seldaek |
define('DWOO_COMPILE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'temp'.DIRECTORY_SEPARATOR.'compiled'); |
|
| 9 |
↓
|
Seldaek |
|
|
| 10 |
9bc397
|
Seldaek |
require dirname(__FILE__) . '/'.DwooTests::getConfig('DWOO_PATH').'/dwooAutoload.php'; |
|
| 11 |
92faad
|
Seldaek |
//require dirname(__FILE__) . '/'.DwooTests::getConfig('DWOO_PATH').'/Dwoo.compiled.php'; |
|
| 12 |
↓
|
Seldaek |
//set_include_path(get_include_path().';'.DWOO_DIRECTORY); |
|
| 13 |
5b6806
|
Seldaek |
define('TEST_DIRECTORY', dirname(__FILE__)); |
|
| 14 |
dc33f4
|
Seldaek |
|
|
| 15 |
173403
|
Seldaek |
class DwooTests extends PHPUnit_Framework_TestSuite { |
|
| 16 |
↓
|
Seldaek |
|
|
| 17 |
9bc397
|
Seldaek |
protected static $cfg; |
|
| 18 |
↓
|
Seldaek |
|
|
| 19 |
↓
|
Seldaek |
public static function getConfig($var, $default=null) { |
|
| 20 |
↓
|
Seldaek |
if (self::$cfg == null) { |
|
| 21 |
↓
|
Seldaek |
self::$cfg = parse_ini_file(dirname(__FILE__) . '/config.ini'); |
|
| 22 |
↓
|
Seldaek |
} |
|
| 23 |
↓
|
Seldaek |
if (isset(self::$cfg[$var])) { |
|
| 24 |
↓
|
Seldaek |
return self::$cfg[$var]; |
|
| 25 |
↓
|
Seldaek |
} |
|
| 26 |
↓
|
Seldaek |
return $default; |
|
| 27 |
↓
|
Seldaek |
} |
|
| 28 |
↓
|
Seldaek |
|
|
| 29 |
dc33f4
|
Seldaek |
public static function suite() { |
|
| 30 |
↓
|
Seldaek |
PHPUnit_Util_Filter::addDirectoryToWhitelist(DWOO_DIRECTORY.'plugins/builtin'); |
|
| 31 |
9cf6ad
|
Seldaek |
PHPUnit_Util_Filter::addDirectoryToWhitelist(DWOO_DIRECTORY.'Dwoo'); |
|
| 32 |
00ff62
|
Seldaek |
PHPUnit_Util_Filter::removeDirectoryFromWhitelist(DWOO_DIRECTORY.'Dwoo/Adapters'); |
|
| 33 |
dc33f4
|
Seldaek |
|
|
| 34 |
173403
|
Seldaek |
$suite = new self('Dwoo - Unit Tests Report'); |
|
| 35 |
dc33f4
|
Seldaek |
|
|
| 36 |
1e2469
|
Seldaek |
foreach (new DirectoryIterator(dirname(__FILE__)) as $file) { |
|
| 37 |
19287d
|
Seldaek |
if (!$file->isDir() && substr((string) $file, -4) == '.php' && (string) $file !== 'DwooTests.php' && (string) $file !== 'run-tests.php' && substr((string) $file, -4) === '.php') { |
|
| 38 |
dc33f4
|
Seldaek |
require_once $file->getPathname(); |
|
| 39 |
9bc397
|
Seldaek |
$class = basename($file, '.php'); |
|
| 40 |
↓
|
Seldaek |
// to have an optional test suite, it should implement a public static function isRunnable |
|
| 41 |
↓
|
Seldaek |
// that returns true only if all the conditions are met to run it successfully, for example |
|
| 42 |
↓
|
Seldaek |
// it can check that an external library is present |
|
| 43 |
↓
|
Seldaek |
if (!method_exists($file, 'isRunnable') || call_user_func(array($file, 'isRunnable'))) { |
|
| 44 |
↓
|
Seldaek |
$suite->addTestSuite($class); |
|
| 45 |
↓
|
Seldaek |
} |
|
| 46 |
dc33f4
|
Seldaek |
} |
|
| 47 |
↓
|
Seldaek |
} |
|
| 48 |
↓
|
Seldaek |
|
|
| 49 |
↓
|
Seldaek |
return $suite; |
|
| 50 |
↓
|
Seldaek |
} |
|
| 51 |
173403
|
Seldaek |
|
|
| 52 |
5fc482
|
Seldaek |
protected function tearDown() { |
|
| 53 |
37cb06
|
Seldaek |
$this->clearDir(TEST_DIRECTORY.'/temp/cache', true); |
|
| 54 |
5fc482
|
Seldaek |
$this->clearDir(TEST_DIRECTORY.'/temp/compiled', true); |
|
| 55 |
b07616
|
Seldaek |
} |
|
| 56 |
↓
|
Seldaek |
|
|
| 57 |
↓
|
Seldaek |
protected function clearDir($path, $emptyOnly=false) |
|
| 58 |
↓
|
Seldaek |
{ |
|
| 59 |
5fc482
|
Seldaek |
if (is_dir($path)) { |
|
| 60 |
↓
|
Seldaek |
foreach (glob($path.'/*') as $f) { |
|
| 61 |
↓
|
Seldaek |
$this->clearDir($f); |
|
| 62 |
↓
|
Seldaek |
} |
|
| 63 |
↓
|
Seldaek |
if (!$emptyOnly) { |
|
| 64 |
↓
|
Seldaek |
rmdir($path); |
|
| 65 |
↓
|
Seldaek |
} |
|
| 66 |
↓
|
Seldaek |
} else { |
|
| 67 |
↓
|
Seldaek |
unlink($path); |
|
| 68 |
↓
|
Seldaek |
} |
|
| 69 |
b07616
|
Seldaek |
} |
|
| 70 |
dc33f4
|
Seldaek |
} |
|
| 71 |
2f0eff
|
Seldaek |
|
|
| 72 |
↓
|
Seldaek |
// Evaluates two strings and ignores differences in line endings (\r\n == \n == \r) |
|
| 73 |
↓
|
Seldaek |
class DwooConstraintStringEquals extends PHPUnit_Framework_Constraint |
|
| 74 |
↓
|
Seldaek |
{ |
|
| 75 |
↓
|
Seldaek |
protected $target; |
|
| 76 |
↓
|
Seldaek |
|
|
| 77 |
↓
|
Seldaek |
public function __construct($target) |
|
| 78 |
↓
|
Seldaek |
{ |
|
| 79 |
↓
|
Seldaek |
$this->target = preg_replace('#(\r\n|\r)#', "\n", $target); |
|
| 80 |
↓
|
Seldaek |
} |
|
| 81 |
↓
|
Seldaek |
|
|
| 82 |
↓
|
Seldaek |
public function evaluate($other) |
|
| 83 |
↓
|
Seldaek |
{ |
|
| 84 |
↓
|
Seldaek |
$this->other = preg_replace('#(\r\n|\r)#', "\n", $other); |
|
| 85 |
↓
|
Seldaek |
return $this->target == $this->other; |
|
| 86 |
↓
|
Seldaek |
} |
|
| 87 |
↓
|
Seldaek |
|
|
| 88 |
↓
|
Seldaek |
public function toString() |
|
| 89 |
↓
|
Seldaek |
{ |
|
| 90 |
c6133a
|
Seldaek |
return 'equals expected value.'.PHP_EOL.'Expected:'.PHP_EOL.$this->target.PHP_EOL.'Received:'.PHP_EOL.$this->other.PHP_EOL; |
|
| 91 |
2f0eff
|
Seldaek |
} |
|
| 92 |
↓
|
Seldaek |
} |
|
| 93 |
5fc482
|
Seldaek |
|
|
| 94 |
↓
|
Seldaek |
class DwooConstraintPathEquals extends PHPUnit_Framework_Constraint |
|
| 95 |
↓
|
Seldaek |
{ |
|
| 96 |
↓
|
Seldaek |
protected $target; |
|
| 97 |
↓
|
Seldaek |
|
|
| 98 |
↓
|
Seldaek |
public function __construct($target) |
|
| 99 |
↓
|
Seldaek |
{ |
|
| 100 |
↓
|
Seldaek |
$this->target = preg_replace('#([\\\\/]{1,2})#', '/', $target); |
|
| 101 |
↓
|
Seldaek |
} |
|
| 102 |
↓
|
Seldaek |
|
|
| 103 |
↓
|
Seldaek |
public function evaluate($other) |
|
| 104 |
↓
|
Seldaek |
{ |
|
| 105 |
↓
|
Seldaek |
$this->other = preg_replace('#([\\\\/]{1,2})#', '/', $other); |
|
| 106 |
↓
|
Seldaek |
return $this->target == $this->other; |
|
| 107 |
↓
|
Seldaek |
} |
|
| 108 |
↓
|
Seldaek |
|
|
| 109 |
↓
|
Seldaek |
public function toString() |
|
| 110 |
↓
|
Seldaek |
{ |
|
| 111 |
↓
|
Seldaek |
return 'equals expected value.'.PHP_EOL.'Expected:'.PHP_EOL.$this->target.PHP_EOL.'Received:'.PHP_EOL.$this->other.PHP_EOL; |
|
| 112 |
↓
|
Seldaek |
} |
|
| 113 |
↓
|
Seldaek |
} |
|