81aeffb5adf18fadb4652bdf6d305fee8bc880bd
Author: Mark Story
Date: 2009-04-03 00:16:14 -0400
diff --git a/models/api_class.php b/models/api_class.php
index 642776f..0d4ebef 100644
--- a/models/api_class.php
+++ b/models/api_class.php
@@ -204,8 +204,8 @@ class ApiClass extends ApiGeneratorAppModel {
$searchedClasses = Set::extract('/ApiClass/name', $results);
$ApiFile =& ClassRegistry::init('ApiGenerator.ApiFile');
- foreach ($results as $i => $result) {
- $result = $ApiFile->loadFile($result['ApiClass']['file_name'], array('useIndex' => true));
+ foreach ($results as $i => $record) {
+ $result = $ApiFile->loadFile($record['ApiClass']['file_name'], array('useIndex' => true));
foreach ($result['class'] as $name => $obj) {
if (!in_array($name, $searchedClasses)) {
continue;
@@ -223,6 +223,7 @@ class ApiClass extends ApiGeneratorAppModel {
$_return[$relevance][$name]['class'][$name] = $obj;
}
foreach ($result['function'] as $name => $obj) {
+ $obj->info['declaredInFile'] = $record['ApiClass']['file_name'];
$relevance = 0;
$relevance += $this->_calculateRelevance(array(compact('name')), $terms, array('high' => 6, 'low' => 3));
if ($relevance > 0) {
diff --git a/models/api_file.php b/models/api_file.php
index 788e88f..3a51251 100644
--- a/models/api_file.php
+++ b/models/api_file.php
@@ -301,7 +301,7 @@ class ApiFile extends Object {
$new = $tmp = array();
$tmp['class'] = $this->_parseClassNamesInFile($filePath);
$tmp['function'] = $this->_parseFunctionNamesInFile($filePath);
-
+
$include = false;
foreach ($tmp['class'] as $classInFile) {
$include = false;
@@ -366,7 +366,7 @@ class ApiFile extends Object {
$foundFuncs = array();
$fileContent = file_get_contents($fileName);
$funcNames = implode('|', $this->_definedFunctions);
- preg_match_all('/^\tfunction\s*(' . $funcNames . ')[\s|\(]+/mi', $fileContent, $matches, PREG_SET_ORDER);
+ preg_match_all('/^\t*function\s*(' . $funcNames . ')[\s|\(]+/mi', $fileContent, $matches, PREG_SET_ORDER);
foreach ($matches as $function) {
$foundFuncs[] = $function[1];
}
diff --git a/tests/cases/models/api_class.test.php b/tests/cases/models/api_class.test.php
index da08a37..4a27ef9 100644
--- a/tests/cases/models/api_class.test.php
+++ b/tests/cases/models/api_class.test.php
@@ -107,6 +107,8 @@ class ApiClassTestCase extends CakeTestCase {
**/
function startTest() {
$this->_path = APP . 'plugins' . DS . 'api_generator';
+ $this->_testAppPath = dirname(dirname(dirname(__FILE__))) . DS . 'test_app' . DS;
+
Configure::write('ApiGenerator.filePath', $this->_path);
$this->ApiClass = ClassRegistry::init('ApiClass');
}
@@ -217,4 +219,17 @@ class ApiClassTestCase extends CakeTestCase {
$this->assertTrue($result['debug']['function']['debug'] instanceof FunctionDocumentor);
}
+/**
+ * Test that files containing global functions always have the declaredInFile set to the file_name
+ * in the index
+ *
+ * @return void
+ **/
+ function testSearchingForGlobalFilesInIndex() {
+ $this->ApiClass->id = '498cee77-97c8-441a-99c3-80ed87460ad7';
+ $this->ApiClass->saveField('file_name', $this->_testAppPath . 'basics.php');
+ $result = $this->ApiClass->search('debug');
+ $filename = $result['debug']['function']['debug']->info['declaredInFile'];
+ $this->assertNoPattern('/test_basics/', $filename);
+ }
}
\ No newline at end of file
diff --git a/tests/test_app/basics.php b/tests/test_app/basics.php
new file mode 100644
index 0000000..e372cb8
--- /dev/null
+++ b/tests/test_app/basics.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Does something
+ *
+ * @access public
+ * @return void
+ **/
+ function debug() {
+
+ }
+?>
\ No newline at end of file
