Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

Commit

Permalink
Making all test cases pass
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Sep 30, 2011
1 parent 8bba981 commit 9189e88
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 98 deletions.
5 changes: 3 additions & 2 deletions Console/Command/ApiIndexShell.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -233,8 +233,9 @@ protected function config() {
$this->hr(); $this->hr();


$path = null; $path = null;

while($path == null && $path != 'q') { 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] != ':') { if ($path[0] != '/' && $path[1] != ':') {
$path = $this->params['working'] . DS . $path; $path = $this->params['working'] . DS . $path;
} }
Expand Down Expand Up @@ -291,7 +292,7 @@ protected function config() {


$regex = null; $regex = null;
while($regex == null && $regex != 'n') { 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') { if ($regex != 'n') {
$config['file']['regex'] = $regex; $config['file']['regex'] = $regex;
} }
Expand Down
4 changes: 2 additions & 2 deletions Model/ApiConfig.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct() {
if (file_exists(APP . 'Config' . DS . 'api_config.ini')) { if (file_exists(APP . 'Config' . DS . 'api_config.ini')) {
$this->path = APP . 'Config' . DS . 'api_config.ini'; $this->path = APP . 'Config' . DS . 'api_config.ini';
} else { } else {
$this->path = dirname(dirname(__FILE__)) . DS . 'config' . DS . 'api_config.ini'; $this->path = dirname(dirname(__FILE__)) . DS . 'Config' . DS . 'api_config.ini';
} }
} }
/** /**
Expand Down Expand Up @@ -202,7 +202,7 @@ public function makeAbsolute($path, $roots = array()) {
if (Folder::isAbsolute($path)) { if (Folder::isAbsolute($path)) {
return $path; return $path;
} }
$coreFile = CAKE_CORE_INCLUDE_PATH . DS . $path; $coreFile = CAKE . $path;
if (file_exists($coreFile)) { if (file_exists($coreFile)) {
return $coreFile; return $coreFile;
} }
Expand Down
5 changes: 5 additions & 0 deletions Model/ApiFile.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ protected function _parseClassNamesInFile($fileName, $getParents = false) {
$foundClasses = array_merge($foundClasses, explode(', ', $className[2])); $foundClasses = array_merge($foundClasses, explode(', ', $className[2]));
} }
} }
foreach ($foundClasses as $i => $class) {
if (strpos($fileContent, "App::uses('$class'") !== false) {
unset($foundClasses[$i]);
}
}
return $foundClasses; return $foundClasses;
} }
/** /**
Expand Down
2 changes: 2 additions & 0 deletions Model/ApiGeneratorAppModel.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @since ApiGenerator 0.1 * @since ApiGenerator 0.1
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
**/ **/
App::uses('AppModel', 'Model');

class ApiGeneratorAppModel extends AppModel { class ApiGeneratorAppModel extends AppModel {
/** /**
* Inflect a slashed path to url safe path. Trims ApiGenerator.filePath off as well. * Inflect a slashed path to url safe path. Trims ApiGenerator.filePath off as well.
Expand Down
7 changes: 3 additions & 4 deletions Test/Case/Lib/DocBlockAnalyzerTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public function bestFunction($one, $two, $three) {
} }
} }


Mock::generate('DocBlockRule', 'MockDocBlockRule');

class DocBlockAnalyzerTestCase extends CakeTestCase { class DocBlockAnalyzerTestCase extends CakeTestCase {
/** /**
* test construction and rule building. * test construction and rule building.
Expand Down Expand Up @@ -84,9 +82,10 @@ function testSourceSetting() {
**/ **/
function testAnalyze() { function testAnalyze() {
//test that rules get called properly //test that rules get called properly
$this->getMock('DocBlockRule', array(), array(), 'MockDocBlockRule');
$analyze = new DocBlockAnalyzer(array('Mock')); $analyze = new DocBlockAnalyzer(array('Mock'));
$analyze->rules['Mock']->expectCallCount('setSubject', 7); $analyze->rules['Mock']->expects($this->exactly(7))->method('setSubject');
$analyze->rules['Mock']->expectCallCount('score', 7); $analyze->rules['Mock']->expects($this->exactly(7))->method('score');


$reflection = new ClassDocumentor('TestSubjectOne'); $reflection = new ClassDocumentor('TestSubjectOne');
$result = $analyze->analyze($reflection); $result = $analyze->analyze($reflection);
Expand Down
6 changes: 4 additions & 2 deletions Test/Case/Lib/DocMarkdownTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


App::import('Lib', 'ApiGenerator.DocMarkdown'); App::import('Lib', 'ApiGenerator.DocMarkdown');
App::import('Lib', 'ApiGenerator.ApiLinkGenerator'); App::import('Lib', 'ApiGenerator.ApiLinkGenerator');
App::uses('View', 'View');
App::uses('Controller', 'Controller');


class DocMarkdownTestCase extends CakeTestCase { class DocMarkdownTestCase extends CakeTestCase {


Expand Down Expand Up @@ -641,7 +643,7 @@ function testMixedList() {
* @return void * @return void
*/ */
function testClassLinks() { function testClassLinks() {
$generator = new ApiLinkGenerator(); $generator = new ApiLinkGenerator(new View(new Controller));
$generator->setClassIndex(array('model' => 'Model')); $generator->setClassIndex(array('model' => 'Model'));
$this->Parser->setLinkGenerator($generator); $this->Parser->setLinkGenerator($generator);
$text = <<<TEXT $text = <<<TEXT
Expand All @@ -661,7 +663,7 @@ function testClassLinks() {
* @return void * @return void
*/ */
function testPropertyLinks() { function testPropertyLinks() {
$generator = new ApiLinkGenerator(); $generator = new ApiLinkGenerator(new View(new Controller));
$generator->setClassIndex(array('model' => 'Model')); $generator->setClassIndex(array('model' => 'Model'));
$this->Parser->setLinkGenerator($generator); $this->Parser->setLinkGenerator($generator);
$text = <<<TEXT $text = <<<TEXT
Expand Down
24 changes: 12 additions & 12 deletions Test/Case/Model/ApiClassTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ApiClassTestCase extends CakeTestCase {
**/ **/
function setUp() { function setUp() {
parent::setUp(); parent::setUp();
$this->_path = App::pluginPath('api_generator'); $this->_path = CakePlugin::path('ApiGenerator');
$this->_testAppPath = dirname(dirname(dirname(__FILE__))) . DS . 'test_app' . DS; $this->_testAppPath = dirname(dirname(dirname(__FILE__))) . DS . 'test_app' . DS;


Configure::write('ApiGenerator.filePath', $this->_path); Configure::write('ApiGenerator.filePath', $this->_path);
Expand All @@ -124,7 +124,7 @@ function testSaveClassDocs() {
$docs = new ClassDocumentor('ApiClassSampleClass'); $docs = new ClassDocumentor('ApiClassSampleClass');


$result = $this->ApiClass->saveClassDocs($docs); $result = $this->ApiClass->saveClassDocs($docs);
$this->assertTrue($result); $this->assertFalse(empty($result));


$result = $this->ApiClass->read(); $result = $this->ApiClass->read();
$now = date('Y-m-d H:i:s'); $now = date('Y-m-d H:i:s');
Expand All @@ -147,7 +147,7 @@ function testSaveClassDocs() {


$docs = new ClassDocumentor('ApiClassSampleClassChild'); $docs = new ClassDocumentor('ApiClassSampleClassChild');
$result = $this->ApiClass->saveClassDocs($docs); $result = $this->ApiClass->saveClassDocs($docs);
$this->assertTrue($result); $this->assertFalse(empty($result));
$result = $this->ApiClass->read(); $result = $this->ApiClass->read();
$now = date('Y-m-d H:i:s'); $now = date('Y-m-d H:i:s');
$expected = array( $expected = array(
Expand All @@ -173,12 +173,12 @@ function testSaveClassDocs() {
* @return void * @return void
**/ **/
function testSavePseudoClassDocs() { function testSavePseudoClassDocs() {
$file = TEST_CAKE_CORE_INCLUDE_PATH . 'basics.php'; $file = CAKE . 'basics.php';
$ApiFile = ClassRegistry::init('ApiGenerator.ApiFile'); $ApiFile = ClassRegistry::init('ApiGenerator.ApiFile');
$docs = $ApiFile->loadFile($file); $docs = $ApiFile->loadFile($file);


$result = $this->ApiClass->savePseudoClassDocs($docs['function'], $file); $result = $this->ApiClass->savePseudoClassDocs($docs['function'], $file);
$this->assertTrue($result); $this->assertFalse(empty($result));
} }
/** /**
* test the search implementation * test the search implementation
Expand All @@ -204,12 +204,12 @@ function testSearch() {
//test by partial method match //test by partial method match
$result = $this->ApiClass->search('missing'); $result = $this->ApiClass->search('missing');
$this->assertEqual(count($result), 1); $this->assertEqual(count($result), 1);
$this->assertEqual(array_keys($result), array('ErrorHandler')); $this->assertEqual(array_keys($result), array('ConsoleErrorHandler'));


//test relevance in find //test relevance in find
$result = $this->ApiClass->search('acl'); $result = $this->ApiClass->search('acl');
$this->assertEqual(count($result), 4); $this->assertEqual(count($result), 2);
$this->assertEqual(array_keys($result), array('AclComponent', 'DbAcl', 'AclBase', 'IniAcl')); $this->assertEqual(array_keys($result), array('AclComponent', 'IniAcl'));


//test searching of global functions //test searching of global functions
$result = $this->ApiClass->search('debug'); $result = $this->ApiClass->search('debug');
Expand Down Expand Up @@ -248,11 +248,11 @@ function testClearIndex() {
**/ **/
function testGetClassIndex() { function testGetClassIndex() {
$results = $this->ApiClass->getClassIndex(); $results = $this->ApiClass->getClassIndex();
$this->assertEqual(count($results), 8); $this->assertEqual(count($results), 6);
$this->assertFalse(in_array('basics.php', $results)); $this->assertFalse(in_array('basics.php', $results));


$results = $this->ApiClass->getClassIndex(true); $results = $this->ApiClass->getClassIndex(true);
$this->assertEqual(count($results), 9); $this->assertEqual(count($results), 7);
$this->assertTrue(in_array('basics.php', $results)); $this->assertTrue(in_array('basics.php', $results));
} }
/** /**
Expand All @@ -262,15 +262,15 @@ function testGetClassIndex() {
**/ **/
function testAnalyzeCoverage() { function testAnalyzeCoverage() {
//dispatcher class //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); $result = $this->ApiClass->analyzeCoverage($apiClass);


$this->assertTrue(isset($result['sectionTotals']['properties'])); $this->assertTrue(isset($result['sectionTotals']['properties']));
$this->assertTrue(isset($result['sectionTotals']['methods'])); $this->assertTrue(isset($result['sectionTotals']['methods']));
$this->assertTrue(isset($result['sectionTotals']['classInfo'])); $this->assertTrue(isset($result['sectionTotals']['classInfo']));


$this->ApiClass->cacheQueries = false; $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'])); $this->assertTrue(is_numeric($apiClass['ApiClass']['coverage_cache']));


// try with pseudo class file. // try with pseudo class file.
Expand Down
7 changes: 3 additions & 4 deletions Test/Case/Model/ApiConfigTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ function endTest() {
* @return void * @return void
*/ */
function testMakeAbosolute() { function testMakeAbosolute() {
$path = 'view/helpers/xml.php'; $path = 'View/Helper/HtmlHelper.php';
$roots = Configure::corePaths(); $result = $this->ApiConfig->makeAbsolute($path);
$result = $this->ApiConfig->makeAbsolute($path, $roots['libs']); $this->assertEquals(CAKE . $path, $result);
$this->assertEqual($result, $roots['libs'][0] . $path);
} }


/** /**
Expand Down
44 changes: 21 additions & 23 deletions Test/Case/Model/ApiFileTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -71,24 +71,24 @@ function testLoadExtractor() {
* @return void * @return void
**/ **/
function testRead() { function testRead() {
$result = $this->ApiFile->read($this->_path . DS . 'models'); $result = $this->ApiFile->read($this->_path . DS . 'Model');
$this->assertTrue(empty($result[0])); $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($result[1]);
sort($expected); sort($expected);
$this->assertEqual($result[1], $expected); $this->assertEquals($expected, $result[1]);


$this->ApiFile->allowedExtensions = array('php', 'ctp'); $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])); $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($result[1]);
sort($expected); sort($expected);
$this->assertEqual($result[1], $expected); $this->assertEqual($result[1], $expected);


$this->ApiFile->excludeFiles[] = 'api_class.php'; $this->ApiFile->excludeFiles[] = 'ApiClass.php';
$result = $this->ApiFile->read($this->_path . DS . 'models'); $result = $this->ApiFile->read($this->_path . DS . 'Model');
$expected = array('api_config.php', 'api_file.php', 'api_package.php'); $expected = array('ApiConfig.php', 'ApiFile.php', 'ApiGeneratorAppModel.php', 'ApiPackage.php');
$this->assertEqual($result[1], $expected); $this->assertEqual($result[1], $expected);


$this->ApiFile->excludeDirectories = array('models', 'controllers'); $this->ApiFile->excludeDirectories = array('models', 'controllers');
Expand All @@ -97,7 +97,7 @@ function testRead() {
$this->assertFalse(in_array('models', $result[0])); $this->assertFalse(in_array('models', $result[0]));


$this->ApiFile->allowedExtensions = array('css'); $this->ApiFile->allowedExtensions = array('css');
$this->ApiFile->excludeDirectories = array('models'); $this->ApiFile->excludeDirectories = array('Model');
$result = $this->ApiFile->read($this->_path); $result = $this->ApiFile->read($this->_path);
$this->assertTrue(empty($result[1]), 'file with not allowed extension found. %s'); $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'); $this->assertFalse(in_array('models', $result[0]), 'file in ignored folder found %s');
Expand All @@ -116,35 +116,33 @@ function testRead() {
* @return void * @return void
**/ **/
function testGetFileList() { function testGetFileList() {
$this->ApiFile->excludeDirectories = array('config', 'webroot'); $this->ApiFile->excludeDirectories = array('Config', 'webroot');
$result = $this->ApiFile->fileList(APP); $result = $this->ApiFile->fileList(APP);
$core = CONFIGS . 'core.php'; $core = APP . 'Config' . DS . 'core.php';
$vendorJs = WWW_ROOT . 'js' . DS . 'vendors.php'; $index = WWW_ROOT . 'index.php';
$this->assertFalse(in_array($core, $result)); $this->assertFalse(in_array($core, $result));
$this->assertFalse(in_array($vendorJs, $result)); $this->assertFalse(in_array($index, $result));


$this->ApiFile->excludeDirectories = array(); $this->ApiFile->excludeDirectories = array();
$this->ApiFile->allowedExtensions = array('css'); $this->ApiFile->allowedExtensions = array('css');
$result = $this->ApiFile->fileList(APP); $result = $this->ApiFile->fileList(APP);
$core = CONFIGS . 'core.php'; $core = APP . 'Config' . DS . 'core.php';
$vendorJs = WWW_ROOT . 'js' . DS . 'vendors.php';
$this->assertFalse(in_array($core, $result)); $this->assertFalse(in_array($core, $result));
$this->assertFalse(in_array($vendorJs, $result)); $this->assertFalse(in_array($index, $result));


$this->ApiFile->excludeDirectories = array(); $this->ApiFile->excludeDirectories = array();
$this->ApiFile->allowedExtensions = array('css'); $this->ApiFile->allowedExtensions = array('css');
$result = $this->ApiFile->fileList(APP); $result = $this->ApiFile->fileList(APP);
$core = CONFIGS . 'core.php'; $core = APP . 'Config' . DS . 'core.php';
$vendorJs = WWW_ROOT . 'js' . DS . 'vendors.php';
$this->assertFalse(in_array($core, $result)); $this->assertFalse(in_array($core, $result));
$this->assertFalse(in_array($vendorJs, $result)); $this->assertFalse(in_array($index, $result));


$this->ApiFile->excludeDirectories = array(); $this->ApiFile->excludeDirectories = array();
$this->ApiFile->allowedExtensions = array('php'); $this->ApiFile->allowedExtensions = array('php');
$this->ApiFile->excludeFiles = array('index.php'); $this->ApiFile->excludeFiles = array('index.php');
$this->ApiFile->fileRegExp = '[a-z_0-9]+'; $this->ApiFile->fileRegExp = '[a-z_0-9]+';
$result = $this->ApiFile->fileList(APP); $result = $this->ApiFile->fileList(APP);
$core = CONFIGS . 'core.php'; $core = APP . 'Config' . DS . 'core.php';
$index = APP . 'index.php'; $index = APP . 'index.php';
$this->assertTrue(in_array($core, $result)); $this->assertTrue(in_array($core, $result));
$this->assertFalse(in_array($index, $result)); $this->assertFalse(in_array($index, $result));
Expand Down Expand Up @@ -176,7 +174,7 @@ function testLoadFileOnAlreadyIncludedFile() {
$this->assertTrue(isset($result['function'])); $this->assertTrue(isset($result['function']));
$this->assertTrue($result['class'][__CLASS__] instanceof ClassDocumentor); $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['class']));
$this->assertTrue(isset($result['function'])); $this->assertTrue(isset($result['function']));
$this->assertTrue($result['class']['ApiClass'] instanceof ClassDocumentor); $this->assertTrue($result['class']['ApiClass'] instanceof ClassDocumentor);
Expand All @@ -187,7 +185,7 @@ function testLoadFileOnAlreadyIncludedFile() {
* @return void * @return void
**/ **/
function testLoadingEvilPath() { 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())); $this->assertEqual($result, array('class' => array(), 'function' => array()));
} }
/** /**
Expand Down Expand Up @@ -248,7 +246,7 @@ function testExceptionThrowing() {
* @return void * @return void
**/ **/
function testLoadingFileWithAmbiguousFunction() { function testLoadingFileWithAmbiguousFunction() {
$cacheFile = LIBS . 'cache.php'; $cacheFile = CAKE . 'Cache' . DS . 'Cache.php';
$this->assertTrue(function_exists('config')); $this->assertTrue(function_exists('config'));
$results = $this->ApiFile->loadFile($cacheFile); $results = $this->ApiFile->loadFile($cacheFile);
$this->assertEqual($results['function'], array()); $this->assertEqual($results['function'], array());
Expand Down
6 changes: 3 additions & 3 deletions Test/Case/Model/ApiGeneratorModelTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @since ApiGenerator 0.1 * @since ApiGenerator 0.1
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @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 { class ApiGeneratorAppTestModel extends ApiGeneratorAppModel {
public $name = 'ApiGeneratorAppTestModel'; public $name = 'ApiGeneratorAppTestModel';
Expand All @@ -43,12 +43,12 @@ function setup() {
function testSlugPath() { function testSlugPath() {
Configure::write('ApiGenerator.filePath', '/this/is/'); Configure::write('ApiGenerator.filePath', '/this/is/');
$result = $this->Model->slugPath('/this/is/a/path/to_my/file.php'); $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); $this->assertEqual($result, $expected);


Configure::write('ApiGenerator.filePath', '/this/is/'); Configure::write('ApiGenerator.filePath', '/this/is/');
$result = $this->Model->slugPath('/this/is/a/path/to_my/f i le.php'); $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); $this->assertEqual($result, $expected);


Configure::write('ApiGenerator.filePath', 'C:\www'); Configure::write('ApiGenerator.filePath', 'C:\www');
Expand Down
Loading

0 comments on commit 9189e88

Please sign in to comment.