2008-11-07 11:33:13 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* TestManagerTest file
|
2008-11-07 11:33:13 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2010-01-14 04:47:14 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc.
|
2008-11-07 11:33:13 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-03-19 21:10:13 +00:00
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-11-07 11:33:13 +00:00
|
|
|
*/
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-05-04 22:55:15 +00:00
|
|
|
class TestTestManager extends TestManager {
|
|
|
|
|
|
|
|
public function setTestSuite($testSuite) {
|
|
|
|
$this->_testSuite = $testSuite;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* TestManagerTest class
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
*/
|
2008-11-07 11:33:13 +00:00
|
|
|
class TestManagerTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-05-04 22:55:15 +00:00
|
|
|
/**
|
|
|
|
* Number of times the funcion PHPUnit_Framework_TestSuite::addTestFile() has been called
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
*/
|
|
|
|
protected $_countFiles = 0;
|
|
|
|
|
2008-11-07 11:47:59 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* setUp method
|
2008-11-07 11:47:59 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function setUp() {
|
2010-05-04 22:55:15 +00:00
|
|
|
$this->_countFiles = 0;
|
|
|
|
$this->TestManager = new TestTestManager();
|
2010-05-05 01:21:58 +00:00
|
|
|
$this->testSuiteStub = $this->getMock('PHPUnit_Framework_TestSuite');
|
2010-05-05 04:26:40 +00:00
|
|
|
|
2010-05-05 01:21:58 +00:00
|
|
|
$this->testSuiteStub
|
2010-05-04 22:55:15 +00:00
|
|
|
->expects($this->any())
|
|
|
|
->method('addTestFile')
|
|
|
|
->will($this->returnCallback(array(&$this, '_countIncludedTestFiles')));
|
2010-05-05 04:26:40 +00:00
|
|
|
|
|
|
|
$this->testSuiteStub
|
|
|
|
->expects($this->any())
|
|
|
|
->method('addTestSuite')
|
|
|
|
->will($this->returnCallback(array(&$this, '_countIncludedTestFiles')));
|
|
|
|
|
2010-05-05 01:21:58 +00:00
|
|
|
$this->TestManager->setTestSuite($this->testSuiteStub);
|
2010-05-04 22:55:15 +00:00
|
|
|
$this->Reporter = $this->getMock('CakeHtmlReporter');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method to count the number of times the
|
|
|
|
* function PHPUnit_Framework_TestSuite::addTestFile() has been called
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function _countIncludedTestFiles() {
|
|
|
|
$this->_countFiles++;
|
2008-11-07 11:47:59 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-05-05 04:26:40 +00:00
|
|
|
protected function _getAllTestFiles($directory = CORE_TEST_CASES, $type = 'test') {
|
|
|
|
$folder = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
|
|
|
|
$extension = str_replace('.', '\.', $this->TestManager->getExtension($type));
|
2010-05-04 22:55:15 +00:00
|
|
|
$out = new RegexIterator($folder, '#^.+'.$extension.'$#i', RecursiveRegexIterator::GET_MATCH);
|
|
|
|
|
|
|
|
$files = array();
|
|
|
|
foreach ($out as $testFile) {
|
|
|
|
$files[] = $testFile[0];
|
|
|
|
}
|
2010-05-05 01:21:58 +00:00
|
|
|
return $files;
|
|
|
|
}
|
2008-11-07 11:33:13 +00:00
|
|
|
|
2010-05-05 01:21:58 +00:00
|
|
|
/**
|
|
|
|
* testRunAllTests method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRunAllTests() {
|
|
|
|
$files = $this->_getAllTestFiles();
|
2010-05-04 22:55:15 +00:00
|
|
|
$result = $this->TestManager->runAllTests($this->Reporter, true);
|
2008-11-07 11:33:13 +00:00
|
|
|
|
2010-05-05 01:21:58 +00:00
|
|
|
$this->assertEquals(count($files), $this->_countFiles);
|
2010-05-04 22:55:15 +00:00
|
|
|
$this->assertType('PHPUnit_Framework_TestResult', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that trying to run an unexistent file throws an exception
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testRunUnexistentCase() {
|
|
|
|
$file = md5(time());
|
|
|
|
$result = $this->TestManager->runTestCase($file, $this->Reporter);
|
2008-11-07 11:33:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-07 11:33:13 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* testRunTestCase method
|
2008-11-07 11:33:13 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testRunTestCase() {
|
2008-11-07 11:47:59 +00:00
|
|
|
$file = str_replace(CORE_TEST_CASES, '', __FILE__);
|
2010-01-10 17:39:21 +00:00
|
|
|
$result = $this->TestManager->runTestCase($file, $this->Reporter, true);
|
2010-05-05 01:21:58 +00:00
|
|
|
$this->assertEquals(1, $this->_countFiles);
|
2010-05-04 22:55:15 +00:00
|
|
|
$this->assertType('PHPUnit_Framework_TestResult', $result);
|
2008-11-07 11:33:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-07 11:33:13 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* testRunGroupTest method
|
2008-11-07 11:33:13 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testRunGroupTest() {
|
2010-05-05 04:26:40 +00:00
|
|
|
$groups = $this->_getAllTestFiles(CORE_TEST_GROUPS, 'group');
|
|
|
|
if (empty($groups)) {
|
|
|
|
$this->markTestSkipped('No test group files');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
list($groupFile,) = explode('.', array_pop($groups), 2);
|
|
|
|
$result = $this->TestManager->runGroupTest(basename($groupFile), $this->Reporter);
|
|
|
|
$this->assertGreaterThan(0, $this->_countFiles);
|
|
|
|
$this->assertType('PHPUnit_Framework_TestResult', $result);
|
2008-11-07 11:33:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-07 11:33:13 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* testAddTestCasesFromDirectory method
|
2008-11-07 11:33:13 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testAddTestCasesFromDirectory() {
|
2010-05-05 01:21:58 +00:00
|
|
|
$this->TestManager->addTestCasesFromDirectory($this->testSuiteStub, CORE_TEST_CASES);
|
|
|
|
$this->assertEquals(count($this->_getAllTestFiles()), $this->_countFiles);
|
2008-11-07 11:33:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-07 11:33:13 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* testAddTestFile method
|
2008-11-07 11:33:13 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testAddTestFile() {
|
2010-05-05 01:21:58 +00:00
|
|
|
$file = str_replace(CORE_TEST_CASES, '', __FILE__);
|
|
|
|
$this->TestManager->addTestFile($this->testSuiteStub, $file);
|
|
|
|
$this->assertEquals(1, $this->_countFiles);
|
2008-11-07 11:33:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-07 11:33:13 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* testGetTestCaseList method
|
2008-11-07 11:33:13 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetTestCaseList() {
|
2008-11-07 11:33:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-07 11:33:13 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* testGetGroupTestList method
|
2008-11-07 11:33:13 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetGroupTestList() {
|
2008-11-07 11:33:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|