123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- <?php
-
-
-
- if (version_compare(phpversion(), '5') >= 0) {
- require_once(dirname(__FILE__) . '/reflection_php5.php');
- } else {
- require_once(dirname(__FILE__) . '/reflection_php4.php');
- }
- require_once(dirname(__FILE__) . '/default_reporter.php');
- require_once(dirname(__FILE__) . '/compatibility.php');
-
-
-
- class SimpleTest {
-
-
-
- static function getVersion() {
- $content = file(dirname(__FILE__) . '/VERSION');
- return trim($content[0]);
- }
-
-
-
- static function ignore($class) {
- $registry = &SimpleTest::getRegistry();
- $registry['IgnoreList'][strtolower($class)] = true;
- }
-
-
-
- static function ignoreParentsIfIgnored($classes) {
- $registry = &SimpleTest::getRegistry();
- foreach ($classes as $class) {
- if (SimpleTest::isIgnored($class)) {
- $reflection = new SimpleReflection($class);
- if ($parent = $reflection->getParent()) {
- SimpleTest::ignore($parent);
- }
- }
- }
- }
-
-
-
- static function prefer($object) {
- $registry = &SimpleTest::getRegistry();
- $registry['Preferred'][] = $object;
- }
-
-
-
- static function preferred($classes) {
- if (! is_array($classes)) {
- $classes = array($classes);
- }
- $registry = &SimpleTest::getRegistry();
- for ($i = count($registry['Preferred']) - 1; $i >= 0; $i--) {
- foreach ($classes as $class) {
- if (SimpleTestCompatibility::isA($registry['Preferred'][$i], $class)) {
- return $registry['Preferred'][$i];
- }
- }
- }
- return null;
- }
-
-
-
- static function isIgnored($class) {
- $registry = &SimpleTest::getRegistry();
- return isset($registry['IgnoreList'][strtolower($class)]);
- }
-
-
-
- static function useProxy($proxy, $username = false, $password = false) {
- $registry = &SimpleTest::getRegistry();
- $registry['DefaultProxy'] = $proxy;
- $registry['DefaultProxyUsername'] = $username;
- $registry['DefaultProxyPassword'] = $password;
- }
-
-
-
- static function getDefaultProxy() {
- $registry = &SimpleTest::getRegistry();
- return $registry['DefaultProxy'];
- }
-
-
-
- static function getDefaultProxyUsername() {
- $registry = &SimpleTest::getRegistry();
- return $registry['DefaultProxyUsername'];
- }
-
-
-
- static function getDefaultProxyPassword() {
- $registry = &SimpleTest::getRegistry();
- return $registry['DefaultProxyPassword'];
- }
-
-
-
- protected static function &getRegistry() {
- static $registry = false;
- if (! $registry) {
- $registry = SimpleTest::getDefaults();
- }
- return $registry;
- }
-
-
-
- static function getContext() {
- static $context = false;
- if (! $context) {
- $context = new SimpleTestContext();
- }
- return $context;
- }
-
-
-
- protected static function getDefaults() {
- return array(
- 'MockBaseClass' => 'SimpleMock',
- 'IgnoreList' => array(),
- 'DefaultProxy' => false,
- 'DefaultProxyUsername' => false,
- 'DefaultProxyPassword' => false,
- 'Preferred' => array(new HtmlReporter(), new TextReporter(), new XmlReporter()));
- }
-
-
-
- static function setMockBaseClass($mock_base) {
- $registry = &SimpleTest::getRegistry();
- $registry['MockBaseClass'] = $mock_base;
- }
-
-
-
- static function getMockBaseClass() {
- $registry = &SimpleTest::getRegistry();
- return $registry['MockBaseClass'];
- }
- }
-
-
- class SimpleTestContext {
- private $test;
- private $reporter;
- private $resources;
-
-
-
- function clear() {
- $this->resources = array();
- }
-
-
-
- function setTest($test) {
- $this->clear();
- $this->test = $test;
- }
-
-
-
- function getTest() {
- return $this->test;
- }
-
-
-
- function setReporter($reporter) {
- $this->clear();
- $this->reporter = $reporter;
- }
-
-
-
- function getReporter() {
- return $this->reporter;
- }
-
-
-
- function get($resource) {
- if (! isset($this->resources[$resource])) {
- $this->resources[$resource] = new $resource();
- }
- return $this->resources[$resource];
- }
- }
-
-
- class SimpleStackTrace {
- private $prefixes;
-
-
-
- function __construct($prefixes) {
- $this->prefixes = $prefixes;
- }
-
-
-
- function traceMethod($stack = false) {
- $stack = $stack ? $stack : $this->captureTrace();
- foreach ($stack as $frame) {
- if ($this->frameLiesWithinSimpleTestFolder($frame)) {
- continue;
- }
- if ($this->frameMatchesPrefix($frame)) {
- return ' at [' . $frame['file'] . ' line ' . $frame['line'] . ']';
- }
- }
- return '';
- }
-
-
-
- protected function frameLiesWithinSimpleTestFolder($frame) {
- if (isset($frame['file'])) {
- $path = substr(SIMPLE_TEST, 0, -1);
- if (strpos($frame['file'], $path) === 0) {
- if (dirname($frame['file']) == $path) {
- return true;
- }
- }
- }
- return false;
- }
-
-
-
- protected function frameMatchesPrefix($frame) {
- foreach ($this->prefixes as $prefix) {
- if (strncmp($frame['function'], $prefix, strlen($prefix)) == 0) {
- return true;
- }
- }
- return false;
- }
-
-
-
- protected function captureTrace() {
- if (function_exists('debug_backtrace')) {
- return array_reverse(debug_backtrace());
- }
- return array();
- }
- }
- ?>
|