Permalink
Browse files

Making all test cases pass

  • Loading branch information...
1 parent 8bba981 commit 9189e88a1e61cfedd37394b4baa75836a2b14c1f @lorenzo lorenzo committed Sep 30, 2011
@@ -233,8 +233,9 @@ protected function config() {
$this->hr();
$path = null;
+
while($path == null && $path != 'q') {
- $path = $this->in('Enter the path to the codebase.', '', $this->params['working']);
+ $path = $this->in('Enter the path to the codebase.', '', APP);
if ($path[0] != '/' && $path[1] != ':') {
$path = $this->params['working'] . DS . $path;
}
@@ -291,7 +292,7 @@ protected function config() {
$regex = null;
while($regex == null && $regex != 'n') {
- $regex = $this->in('Regex for matching files', '', '[a-z_\-0-9]+');
+ $regex = $this->in('Regex for matching files', '', '[A-Za-z_\-0-9]+');
if ($regex != 'n') {
$config['file']['regex'] = $regex;
}
View
@@ -44,7 +44,7 @@ public function __construct() {
if (file_exists(APP . 'Config' . DS . 'api_config.ini')) {
$this->path = APP . 'Config' . DS . 'api_config.ini';
} else {
- $this->path = dirname(dirname(__FILE__)) . DS . 'config' . DS . 'api_config.ini';
+ $this->path = dirname(dirname(__FILE__)) . DS . 'Config' . DS . 'api_config.ini';
}
}
/**
@@ -202,7 +202,7 @@ public function makeAbsolute($path, $roots = array()) {
if (Folder::isAbsolute($path)) {
return $path;
}
- $coreFile = CAKE_CORE_INCLUDE_PATH . DS . $path;
+ $coreFile = CAKE . $path;
if (file_exists($coreFile)) {
return $coreFile;
}
View
@@ -354,6 +354,11 @@ protected function _parseClassNamesInFile($fileName, $getParents = false) {
$foundClasses = array_merge($foundClasses, explode(', ', $className[2]));
}
}
+ foreach ($foundClasses as $i => $class) {
+ if (strpos($fileContent, "App::uses('$class'") !== false) {
+ unset($foundClasses[$i]);
+ }
+ }
return $foundClasses;
}
/**
@@ -19,6 +19,8 @@
* @since ApiGenerator 0.1
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
**/
+App::uses('AppModel', 'Model');
+
class ApiGeneratorAppModel extends AppModel {
/**
* Inflect a slashed path to url safe path. Trims ApiGenerator.filePath off as well.
@@ -48,8 +48,6 @@ public function bestFunction($one, $two, $three) {
}
}
-Mock::generate('DocBlockRule', 'MockDocBlockRule');
-
class DocBlockAnalyzerTestCase extends CakeTestCase {
/**
* test construction and rule building.
@@ -84,9 +82,10 @@ function testSourceSetting() {
**/
function testAnalyze() {
//test that rules get called properly
+ $this->getMock('DocBlockRule', array(), array(), 'MockDocBlockRule');
$analyze = new DocBlockAnalyzer(array('Mock'));
- $analyze->rules['Mock']->expectCallCount('setSubject', 7);
- $analyze->rules['Mock']->expectCallCount('score', 7);
+ $analyze->rules['Mock']->expects($this->exactly(7))->method('setSubject');
+ $analyze->rules['Mock']->expects($this->exactly(7))->method('score');
$reflection = new ClassDocumentor('TestSubjectOne');
$result = $analyze->analyze($reflection);
@@ -2,6 +2,8 @@
App::import('Lib', 'ApiGenerator.DocMarkdown');
App::import('Lib', 'ApiGenerator.ApiLinkGenerator');
+App::uses('View', 'View');
+App::uses('Controller', 'Controller');
class DocMarkdownTestCase extends CakeTestCase {
@@ -641,7 +643,7 @@ function testMixedList() {
* @return void
*/
function testClassLinks() {
- $generator = new ApiLinkGenerator();
+ $generator = new ApiLinkGenerator(new View(new Controller));
$generator->setClassIndex(array('model' => 'Model'));
$this->Parser->setLinkGenerator($generator);
$text = <<<TEXT
@@ -661,7 +663,7 @@ function testClassLinks() {
* @return void
*/
function testPropertyLinks() {
- $generator = new ApiLinkGenerator();
+ $generator = new ApiLinkGenerator(new View(new Controller));
$generator->setClassIndex(array('model' => 'Model'));
$this->Parser->setLinkGenerator($generator);
$text = <<<TEXT
@@ -99,7 +99,7 @@ class ApiClassTestCase extends CakeTestCase {
**/
function setUp() {
parent::setUp();
- $this->_path = App::pluginPath('api_generator');
+ $this->_path = CakePlugin::path('ApiGenerator');
$this->_testAppPath = dirname(dirname(dirname(__FILE__))) . DS . 'test_app' . DS;
Configure::write('ApiGenerator.filePath', $this->_path);
@@ -124,7 +124,7 @@ function testSaveClassDocs() {
$docs = new ClassDocumentor('ApiClassSampleClass');
$result = $this->ApiClass->saveClassDocs($docs);
- $this->assertTrue($result);
+ $this->assertFalse(empty($result));
$result = $this->ApiClass->read();
$now = date('Y-m-d H:i:s');
@@ -147,7 +147,7 @@ function testSaveClassDocs() {
$docs = new ClassDocumentor('ApiClassSampleClassChild');
$result = $this->ApiClass->saveClassDocs($docs);
- $this->assertTrue($result);
+ $this->assertFalse(empty($result));
$result = $this->ApiClass->read();
$now = date('Y-m-d H:i:s');
$expected = array(
@@ -173,12 +173,12 @@ function testSaveClassDocs() {
* @return void
**/
function testSavePseudoClassDocs() {
- $file = TEST_CAKE_CORE_INCLUDE_PATH . 'basics.php';
+ $file = CAKE . 'basics.php';
$ApiFile = ClassRegistry::init('ApiGenerator.ApiFile');
$docs = $ApiFile->loadFile($file);
$result = $this->ApiClass->savePseudoClassDocs($docs['function'], $file);
- $this->assertTrue($result);
+ $this->assertFalse(empty($result));
}
/**
* test the search implementation
@@ -204,12 +204,12 @@ function testSearch() {
//test by partial method match
$result = $this->ApiClass->search('missing');
$this->assertEqual(count($result), 1);
- $this->assertEqual(array_keys($result), array('ErrorHandler'));
+ $this->assertEqual(array_keys($result), array('ConsoleErrorHandler'));
//test relevance in find
$result = $this->ApiClass->search('acl');
- $this->assertEqual(count($result), 4);
- $this->assertEqual(array_keys($result), array('AclComponent', 'DbAcl', 'AclBase', 'IniAcl'));
+ $this->assertEqual(count($result), 2);
+ $this->assertEqual(array_keys($result), array('AclComponent', 'IniAcl'));
//test searching of global functions
$result = $this->ApiClass->search('debug');
@@ -248,11 +248,11 @@ function testClearIndex() {
**/
function testGetClassIndex() {
$results = $this->ApiClass->getClassIndex();
- $this->assertEqual(count($results), 8);
+ $this->assertEqual(count($results), 6);
$this->assertFalse(in_array('basics.php', $results));
$results = $this->ApiClass->getClassIndex(true);
- $this->assertEqual(count($results), 9);
+ $this->assertEqual(count($results), 7);
$this->assertTrue(in_array('basics.php', $results));
}
/**
@@ -262,15 +262,15 @@ function testGetClassIndex() {
**/
function testAnalyzeCoverage() {
//dispatcher class
- $apiClass = $this->ApiClass->read(null, '498cee77-ddbc-4f12-b457-80ed87460ad7');
+ $apiClass = $this->ApiClass->read(null, '498cee77-68c4-4eb7-ba8b-80ed87460ad7');
$result = $this->ApiClass->analyzeCoverage($apiClass);
$this->assertTrue(isset($result['sectionTotals']['properties']));
$this->assertTrue(isset($result['sectionTotals']['methods']));
$this->assertTrue(isset($result['sectionTotals']['classInfo']));
$this->ApiClass->cacheQueries = false;
- $apiClass = $this->ApiClass->read(null, '498cee77-ddbc-4f12-b457-80ed87460ad7');
+ $apiClass = $this->ApiClass->read(null, '498cee77-68c4-4eb7-ba8b-80ed87460ad7');
$this->assertTrue(is_numeric($apiClass['ApiClass']['coverage_cache']));
// try with pseudo class file.
@@ -70,10 +70,9 @@ function endTest() {
* @return void
*/
function testMakeAbosolute() {
- $path = 'view/helpers/xml.php';
- $roots = Configure::corePaths();
- $result = $this->ApiConfig->makeAbsolute($path, $roots['libs']);
- $this->assertEqual($result, $roots['libs'][0] . $path);
+ $path = 'View/Helper/HtmlHelper.php';
+ $result = $this->ApiConfig->makeAbsolute($path);
+ $this->assertEquals(CAKE . $path, $result);
}
/**
@@ -71,24 +71,24 @@ function testLoadExtractor() {
* @return void
**/
function testRead() {
- $result = $this->ApiFile->read($this->_path . DS . 'models');
+ $result = $this->ApiFile->read($this->_path . DS . 'Model');
$this->assertTrue(empty($result[0]));
- $expected = array('api_config.php', 'api_class.php', 'api_file.php', 'api_package.php');
+ $expected = array('ApiConfig.php', 'ApiClass.php', 'ApiFile.php', 'ApiPackage.php', 'ApiGeneratorAppModel.php');
sort($result[1]);
sort($expected);
- $this->assertEqual($result[1], $expected);
+ $this->assertEquals($expected, $result[1]);
$this->ApiFile->allowedExtensions = array('php', 'ctp');
- $result = $this->ApiFile->read($this->_path . DS . 'models');
+ $result = $this->ApiFile->read($this->_path . DS . 'Model');
$this->assertTrue(empty($result[0]));
- $expected = array('api_config.php', 'api_class.php', 'api_file.php', 'api_package.php');
+ $expected = array('ApiConfig.php', 'ApiClass.php', 'ApiFile.php', 'ApiPackage.php', 'ApiGeneratorAppModel.php');
sort($result[1]);
sort($expected);
$this->assertEqual($result[1], $expected);
- $this->ApiFile->excludeFiles[] = 'api_class.php';
- $result = $this->ApiFile->read($this->_path . DS . 'models');
- $expected = array('api_config.php', 'api_file.php', 'api_package.php');
+ $this->ApiFile->excludeFiles[] = 'ApiClass.php';
+ $result = $this->ApiFile->read($this->_path . DS . 'Model');
+ $expected = array('ApiConfig.php', 'ApiFile.php', 'ApiGeneratorAppModel.php', 'ApiPackage.php');
$this->assertEqual($result[1], $expected);
$this->ApiFile->excludeDirectories = array('models', 'controllers');
@@ -97,7 +97,7 @@ function testRead() {
$this->assertFalse(in_array('models', $result[0]));
$this->ApiFile->allowedExtensions = array('css');
- $this->ApiFile->excludeDirectories = array('models');
+ $this->ApiFile->excludeDirectories = array('Model');
$result = $this->ApiFile->read($this->_path);
$this->assertTrue(empty($result[1]), 'file with not allowed extension found. %s');
$this->assertFalse(in_array('models', $result[0]), 'file in ignored folder found %s');
@@ -116,35 +116,33 @@ function testRead() {
* @return void
**/
function testGetFileList() {
- $this->ApiFile->excludeDirectories = array('config', 'webroot');
+ $this->ApiFile->excludeDirectories = array('Config', 'webroot');
$result = $this->ApiFile->fileList(APP);
- $core = CONFIGS . 'core.php';
- $vendorJs = WWW_ROOT . 'js' . DS . 'vendors.php';
+ $core = APP . 'Config' . DS . 'core.php';
+ $index = WWW_ROOT . 'index.php';
$this->assertFalse(in_array($core, $result));
- $this->assertFalse(in_array($vendorJs, $result));
+ $this->assertFalse(in_array($index, $result));
$this->ApiFile->excludeDirectories = array();
$this->ApiFile->allowedExtensions = array('css');
$result = $this->ApiFile->fileList(APP);
- $core = CONFIGS . 'core.php';
- $vendorJs = WWW_ROOT . 'js' . DS . 'vendors.php';
+ $core = APP . 'Config' . DS . 'core.php';
$this->assertFalse(in_array($core, $result));
- $this->assertFalse(in_array($vendorJs, $result));
+ $this->assertFalse(in_array($index, $result));
$this->ApiFile->excludeDirectories = array();
$this->ApiFile->allowedExtensions = array('css');
$result = $this->ApiFile->fileList(APP);
- $core = CONFIGS . 'core.php';
- $vendorJs = WWW_ROOT . 'js' . DS . 'vendors.php';
+ $core = APP . 'Config' . DS . 'core.php';
$this->assertFalse(in_array($core, $result));
- $this->assertFalse(in_array($vendorJs, $result));
+ $this->assertFalse(in_array($index, $result));
$this->ApiFile->excludeDirectories = array();
$this->ApiFile->allowedExtensions = array('php');
$this->ApiFile->excludeFiles = array('index.php');
$this->ApiFile->fileRegExp = '[a-z_0-9]+';
$result = $this->ApiFile->fileList(APP);
- $core = CONFIGS . 'core.php';
+ $core = APP . 'Config' . DS . 'core.php';
$index = APP . 'index.php';
$this->assertTrue(in_array($core, $result));
$this->assertFalse(in_array($index, $result));
@@ -176,7 +174,7 @@ function testLoadFileOnAlreadyIncludedFile() {
$this->assertTrue(isset($result['function']));
$this->assertTrue($result['class'][__CLASS__] instanceof ClassDocumentor);
- $result = $this->ApiFile->loadFile($this->_path . DS . 'models' . DS . 'api_class.php');
+ $result = $this->ApiFile->loadFile($this->_path . DS . 'Model' . DS . 'ApiClass.php');
$this->assertTrue(isset($result['class']));
$this->assertTrue(isset($result['function']));
$this->assertTrue($result['class']['ApiClass'] instanceof ClassDocumentor);
@@ -187,7 +185,7 @@ function testLoadFileOnAlreadyIncludedFile() {
* @return void
**/
function testLoadingEvilPath() {
- $result = $this->ApiFile->loadFile($this->_path . '../../../config/database.php');
+ $result = $this->ApiFile->loadFile($this->_path . '../../../Config/database.php');
$this->assertEqual($result, array('class' => array(), 'function' => array()));
}
/**
@@ -248,7 +246,7 @@ function testExceptionThrowing() {
* @return void
**/
function testLoadingFileWithAmbiguousFunction() {
- $cacheFile = LIBS . 'cache.php';
+ $cacheFile = CAKE . 'Cache' . DS . 'Cache.php';
$this->assertTrue(function_exists('config'));
$results = $this->ApiFile->loadFile($cacheFile);
$this->assertEqual($results['function'], array());
@@ -17,7 +17,7 @@
* @since ApiGenerator 0.1
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
**/
-App::import('Model', 'ApiGenerator.AppModel');
+App::uses('ApiGeneratorAppModel', 'ApiGenerator.Model');
class ApiGeneratorAppTestModel extends ApiGeneratorAppModel {
public $name = 'ApiGeneratorAppTestModel';
@@ -43,12 +43,12 @@ function setup() {
function testSlugPath() {
Configure::write('ApiGenerator.filePath', '/this/is/');
$result = $this->Model->slugPath('/this/is/a/path/to_my/file.php');
- $expected = 'a-path-to_my-file-php';
+ $expected = 'a-path-to-my-file-php';
$this->assertEqual($result, $expected);
Configure::write('ApiGenerator.filePath', '/this/is/');
$result = $this->Model->slugPath('/this/is/a/path/to_my/f i le.php');
- $expected = 'a-path-to_my-f-i-le-php';
+ $expected = 'a-path-to-my-f-i-le-php';
$this->assertEqual($result, $expected);
Configure::write('ApiGenerator.filePath', 'C:\www');
Oops, something went wrong.

0 comments on commit 9189e88

Please sign in to comment.