a tiny mvc framework for php using php-activerecord
at master 76 lines 2.3 kB view raw
1<?php 2/** 3 * In order to run these unit tests, you need to install: 4 * - PHPUnit 5 * - PEAR Log (otherwise logging SQL queries will be disabled) 6 * - Memcache (otherwise Caching tests will not be executed) 7 * 8 * To run all tests : phpunit AllTests.php --slow-tests 9 * To run a specific test : phpunit ????Test.php 10 */ 11 12@include_once 'Log.php'; 13@include_once 'Log/file.php'; 14require_once 'PHPUnit/Framework/TestCase.php'; 15require_once 'SnakeCase_PHPUnit_Framework_TestCase.php'; 16require_once 'DatabaseTest.php'; 17require_once 'AdapterTest.php'; 18require_once __DIR__ . '/../../ActiveRecord.php'; 19 20// whether or not to run the slow non-crucial tests 21$GLOBALS['slow_tests'] = false; 22 23// whether or not to show warnings when Log or Memcache is missing 24$GLOBALS['show_warnings'] = true; 25 26 27if (getenv('LOG') !== 'false') 28 DatabaseTest::$log = true; 29 30ActiveRecord\Config::initialize(function($cfg) 31{ 32 $cfg->set_model_directory(realpath(__DIR__ . '/../models')); 33 $cfg->set_connections(array( 34 'mysql' => getenv('PHPAR_MYSQL') ?: 'mysql://test:test@127.0.0.1/test', 35 'pgsql' => getenv('PHPAR_PGSQL') ?: 'pgsql://test:test@127.0.0.1/test', 36 'oci' => getenv('PHPAR_OCI') ?: 'oci://test:test@127.0.0.1/dev', 37 'sqlite' => getenv('PHPAR_SQLITE') ?: 'sqlite://test.db')); 38 39 $cfg->set_default_connection('mysql'); 40 41 for ($i=0; $i<count($GLOBALS['argv']); ++$i) 42 { 43 if ($GLOBALS['argv'][$i] == '--adapter') 44 $cfg->set_default_connection($GLOBALS['argv'][$i+1]); 45 elseif ($GLOBALS['argv'][$i] == '--slow-tests') 46 $GLOBALS['slow_tests'] = true; 47 } 48 49 if (class_exists('Log_file')) // PEAR Log installed 50 { 51 $logger = new Log_file(dirname(__FILE__) . '/../log/query.log','ident',array('mode' => 0664, 'timeFormat' => '%Y-%m-%d %H:%M:%S')); 52 53 $cfg->set_logging(true); 54 $cfg->set_logger($logger); 55 } 56 else 57 { 58 if ($GLOBALS['show_warnings'] && !isset($GLOBALS['show_warnings_done'])) 59 echo "(Logging SQL queries disabled, PEAR::Log not found.)\n"; 60 61 DatabaseTest::$log = false; 62 } 63 64 if ($GLOBALS['show_warnings'] && !isset($GLOBALS['show_warnings_done'])) 65 { 66 if (!extension_loaded('memcache')) 67 echo "(Cache Tests will be skipped, Memcache not found.)\n"; 68 } 69 70 date_default_timezone_set('UTC'); 71 72 $GLOBALS['show_warnings_done'] = true; 73}); 74 75error_reporting(E_ALL | E_STRICT); 76?>