Skip to content

Commit

Permalink
Migrating TestManager test to phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
José Lorenzo Rodríguez Urdaneta authored and José Lorenzo Rodríguez Urdaneta committed Jun 11, 2010
1 parent bfb023f commit 4021095
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions cake/tests/cases/libs/test_manager.test.php
Expand Up @@ -50,7 +50,7 @@ class TestManagerTest extends CakeTestCase {
public function setUp() {
$this->_countFiles = 0;
$this->TestManager = new TestTestManager();
$this->testSuiteStub = $this->getMock('PHPUnit_Framework_TestSuite');
$this->testSuiteStub = $this->getMock('CakeTestSuite');

$this->testSuiteStub
->expects($this->any())
Expand Down Expand Up @@ -93,6 +93,7 @@ protected function _getAllTestFiles($directory = CORE_TEST_CASES, $type = 'test'
* @return void
*/
public function testRunAllTests() {
$this->Reporter->params = array('show' => 'cases');
$files = $this->_getAllTestFiles();
$result = $this->TestManager->runAllTests($this->Reporter, true);

Expand All @@ -115,7 +116,7 @@ public function testRunUnexistentCase() {
* @return void
*/
public function testRunTestCase() {
$file = str_replace(CORE_TEST_CASES, '', __FILE__);
$file = __FILE__;
$result = $this->TestManager->runTestCase($file, $this->Reporter, true);
$this->assertEquals(1, $this->_countFiles);
$this->assertType('PHPUnit_Framework_TestResult', $result);
Expand All @@ -133,7 +134,7 @@ public function testRunGroupTest() {
return;
}
list($groupFile,) = explode('.', array_pop($groups), 2);
$result = $this->TestManager->runGroupTest(basename($groupFile), $this->Reporter);
$result = $this->TestManager->runGroupTest($groupFile, $this->Reporter);
$this->assertGreaterThan(0, $this->_countFiles);
$this->assertType('PHPUnit_Framework_TestResult', $result);
}
Expand Down
14 changes: 8 additions & 6 deletions cake/tests/lib/test_manager.php
Expand Up @@ -87,7 +87,7 @@ class TestManager {
*
* @return void
*/
public function __construct($params) {
public function __construct($params = array()) {
require_once(CAKE_TESTS_LIB . 'cake_test_case.php');
if (isset($params['app'])) {
$this->appTest = true;
Expand All @@ -111,7 +111,7 @@ public function __construct($params) {
* @return mixed
*/
public function runAllTests(&$reporter) {
$testCases = $this->_getTestFileList($this->_getTestsPath());
$testCases = $this->_getTestFileList($this->_getTestsPath($reporter->params));

if ($this->appTest) {
$test = $this->getTestSuite(__('All App Tests', true));
Expand Down Expand Up @@ -157,7 +157,7 @@ public function runTestCase($testCaseFile, PHPUnit_Framework_TestListener $repor
* @return mixed Results of group test being run.
*/
public function runGroupTest($groupTestName, $reporter, $codeCoverage = false) {
$filePath = $this->_getTestsPath($reporter->params) . DS . strtolower($groupTestName) . $this->getExtension('group');
$filePath = $this->_getTestsPath($reporter->params) . strtolower($groupTestName) . $this->getExtension('group');

if (!file_exists($filePath) || strpos($filePath, '..')) {
throw new InvalidArgumentException(sprintf(
Expand All @@ -169,8 +169,9 @@ public function runGroupTest($groupTestName, $reporter, $codeCoverage = false) {
}

require_once $filePath;
$suite = $this->getTestSuite(sprintf(__('%s group test', true), $groupTestName));
$groupClassName = Inflector::classify($groupTestName) . 'GroupTest';
$class = basename($groupTestName);
$suite = $this->getTestSuite(sprintf(__('%s group test', true), $class));
$groupClassName = Inflector::classify($class) . 'GroupTest';
$group = new $groupClassName();
$suite->addTestSuite($group);
if (isset($group->label)) {
Expand Down Expand Up @@ -361,6 +362,7 @@ protected static function _hasExpectedExtension($file, $extension) {
* @static
*/
protected static function _getTestsPath($params) {
$result = null;
if (!empty($params['app'])) {
if ($params['show'] == 'cases' || !empty($params['case'])) {
$result = APP_TEST_CASES;
Expand All @@ -374,7 +376,7 @@ protected static function _getTestsPath($params) {
$_pluginBasePath = $pluginPath . DS . 'tests';
}
$result = $_pluginBasePath . DS . $type;
} else {
} elseif (!empty($params['show'])) {
if ($params['show'] == 'cases' || !empty($params['case'])) {
$result = CORE_TEST_CASES;
} else if ($params['show'] == 'groups') {
Expand Down

0 comments on commit 4021095

Please sign in to comment.