Unit tests are used to check a small unit of functionality, such as if a method returns an expected result for a known input, or whether an adapter can successfully open a connection. Available assertions are (see assert methods for details): Equal, False, Identical, NoPattern, NotEqual, Null, Pattern, Tags, True. If an assertion is expected to produce an exception, the expectException method should be called before it.
상속: extends lithium\core\Object
예제 #1
0
 protected function _init()
 {
     parent::_init();
     $this->_timestamp = time();
     $this->_tmp_dir = 'li3_fs_' . $this->_timestamp . '_ftp_test';
     $this->_adapter = Locations::get('li3-fs-ftp-test');
 }
예제 #2
0
파일: RedisTest.php 프로젝트: niel/lithium
	public function __construct(array $config = array()) {
		$defaults = array(
			'host' => '127.0.0.1',
			'port' => 6379
		);
		parent::__construct($config + $defaults);
	}
예제 #3
0
 /**
  * Convenience wrapping for /lithium/console/Command and 
  * lihtium\test\Unit class for easy assertions and
  * command-line input/output and formatting.
  *
  * @param string $name 
  * @param string $arguments 
  * @return mixed
  */
 public function __call($name, $arguments)
 {
     if (method_exists($this->_command, $name)) {
         return $this->_command->invokeMethod($name, $arguments);
     } else {
         return $this->_unit->invokeMethod($name, $arguments);
     }
 }
예제 #4
0
 protected function _init()
 {
     parent::_init();
     $this->_timestamp = time();
     $this->_tmp_dir = sys_get_temp_dir() . '/li3_fs_' . $this->_timestamp . '_test-2';
     Locations::add('test-2', array('adapter' => 'Filesystem', 'url' => 'http://example.com/tmp/', 'location' => $this->_tmp_dir));
     $this->_adapter = Locations::get('test');
 }
예제 #5
0
 protected function _init()
 {
     parent::_init();
     $this->_timestamp = time();
     $this->_tmp_dir = Libraries::path('li3_filemanager\\', array('dirs' => true));
     $this->_tmp_dir .= "/resources/tmp/{$this->_timestamp}_test";
     Locations::add('test', array('adapter' => 'FileSystem', 'url' => 'http://example.com/tmp', 'location' => $this->_tmp_dir));
     $this->_location = Locations::get('test');
 }
 /**
  * Auto init for applying Integration filter to this test class.
  *
  * @return void
  */
 protected function _init()
 {
     parent::_init();
     $this->applyFilter('run', function ($self, $params, $chain) {
         $before = $self->results();
         $chain->next($self, $params, $chain);
         $after = $self->results();
         while (count($after) > count($before)) {
             $result = array_pop($after);
             if ($result['result'] === 'fail') {
                 return false;
             }
         }
     });
 }
예제 #7
0
 /**
  * This hack is a necessary optimization until these tests are properly mocked out.
  *
  * @param array $options Options for the parent class' method.
  */
 public function run(array $options = array())
 {
     $this->_results = array();
     try {
         $this->skip();
     } catch (Exception $e) {
         $this->_handleException($e);
         return $this->_results;
     }
     $this->_configs = Connections::config();
     $result = parent::run($options);
     Connections::get('lithium_mongo_test')->dropDB('lithium_test');
     Connections::reset();
     Connections::config($this->_configs);
     return $result;
 }
예제 #8
0
 /**
  * Takes an instance of an object (usually a Collection object) containing test
  * instances. Adds affected tests to the test collection.
  *
  * @param object $report Instance of Report which is calling apply.
  * @param array $tests The test to apply this filter on
  * @param array $options Not used.
  * @return object Returns the instance of `$tests`.
  */
 public static function apply($report, $tests, array $options = array())
 {
     $affected = array();
     $testsClasses = $tests->map('get_class', array('collect' => false));
     foreach ($tests as $test) {
         $affected = array_merge($affected, self::_affected($test->subject()));
     }
     $affected = array_unique($affected);
     foreach ($affected as $class) {
         $test = Unit::get($class);
         if ($test && !in_array($test, $testsClasses)) {
             $tests[] = new $test();
         }
         $report->collect(__CLASS__, array($class => $test));
     }
     return $tests;
 }
예제 #9
0
 /**
  * Runs tests given a path to a directory or file containing tests. The path to the
  * test(s) may be absolute or relative to the current working directory.
  *
  * {{{
  * li3 test lithium/tests/cases/core/ObjectTest.php
  * li3 test lithium/tests/cases/core
  * }}}
  *
  * If you are in the working directory of an application or plugin and wish to run all tests,
  * simply execute the following:
  *
  * {{{
  * li3 test tests/cases
  * }}}
  *
  * If you are in the working directory of an application and wish to run a plugin, execute one
  * of the following:
  *
  * {{{
  * li3 test libraries/<plugin>/tests/cases
  * li3 test <plugin>/tests/cases
  * }}}
  *
  *
  * This will run `<library>/tests/cases/<package>/<class>Test.php`:
  *
  * {{{
  * li3 test <library>/<package>/<class>.php
  * }}}
  *
  * @param string $path Absolute or relative path to tests or a file which
  *                     corresponding test should be run.
  * @return boolean Will exit with status `1` if one or more tests failed otherwise with `0`.
  */
 public function run($path = null)
 {
     if (!($path = $this->_path($path))) {
         return false;
     }
     if (!preg_match('/(tests|Test\\.php)/', $path)) {
         if (!($path = Unit::get($path))) {
             $this->error('Cannot map path to test path.');
             return static::EXIT_NO_TEST;
         }
     }
     $handlers = $this->_handlers;
     if (!isset($handlers[$this->format]) || !is_callable($handlers[$this->format])) {
         $this->error(sprintf('No handler for format `%s`... ', $this->format));
         return false;
     }
     $filters = $this->filters ? array_map('trim', explode(',', $this->filters)) : array();
     $params = compact('filters') + array('format' => $this->format);
     $runner = function ($options = array()) use($path, $params) {
         error_reporting(E_ALL | E_STRICT | E_DEPRECATED);
         return Dispatcher::run($path, $params + $options);
     };
     $report = $handlers[$this->format]($runner, $path);
     $stats = $report->stats();
     return $stats['success'];
 }
예제 #10
0
 public function handleException($exception, $lineFlag = null)
 {
     return parent::_handleException($exception, $lineFlag);
 }
예제 #11
0
 protected function _init()
 {
     parent::_init();
     $this->_timestamp = time();
     $this->_tmp_dir = "{$this->_timestamp}_test";
 }