Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Get tests working (Bug #18980).

  • Loading branch information...
commit 0c3b2fccc4f721774f78b91452c38729c0387b8d 1 parent 61feb82
Daniel Convissor authored
View
2  PHP/DocBlockGenerator.php
@@ -156,4 +156,4 @@ public function generate($infile, $param = array(), $outfile = '')
}
}
-?>
+?>
View
15 PHP/DocBlockGenerator/License.php
@@ -92,10 +92,17 @@ class PHP_DocBlockGenerator_License
*/
public function __construct()
{
+ if ('@data_dir@' == '@'.'data_dir'.'@') {
+ // This package hasn't been installed. Use local files.
+ $sPath = dirname(__FILE__) . '/../../licenses';
+ } else {
+ // It has been installed. Use the configured path.
+ $sPath = '@data_dir@/PHP_DocBlockGenerator/licenses';
+ }
+
foreach ($this->license as $sId => &$aData) {
- $sPath = PEAR_INSTALL_DIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'PHP_DocBlockGenerator' . DIRECTORY_SEPARATOR . 'licenses';
- $sFile = $sPath . DIRECTORY_SEPARATOR . $sId . '.txt';
- if (file_exists($sFile) && is_readable($sFile)) {
+ $sFile = "$sPath/$sId.txt";
+ if (is_readable($sFile)) {
$this->license[$sId]['text'] = file($sFile,FILE_IGNORE_NEW_LINES);
}
}
@@ -150,4 +157,4 @@ public function isValid($name)
}
}
-?>
+?>
View
7 package2.xml
@@ -44,7 +44,9 @@ Fully tested with phpUnit. Code coverage test close to 100%.
<file name="Block.php" role="php" />
<file name="Cli.php" role="php" />
<file name="GetoptPlus.php" role="php" />
- <file name="License.php" role="php" />
+ <file name="License.php" role="php">
+ <tasks:replace from="@data_dir@" to="data_dir" type="pear-config" />
+ </file>
<file name="Tokens.php" role="php" />
<file name="Type.php" role="php" />
</dir>
@@ -74,6 +76,9 @@ Fully tested with phpUnit. Code coverage test close to 100%.
<dir name="tests">
<file name="AllTests.php" role="test" />
<file name="DocBlockGeneratorTest.php" role="test" />
+ <file name="helper.inc" role="test">
+ <tasks:replace from="@php_dir@" to="php_dir" type="pear-config" />
+ </file>
<dir name="data">
<file name="Parameters.php" role="test" />
<file name="Pear.php" role="test" />
View
26 tests/AllTests.php
@@ -34,15 +34,20 @@
* @version SVN: $Id: AllTests.php 30 2007-07-23 16:46:42Z mcorne $
* @link http://pear.php.net/package/PHP_DocBlockGenerator
*/
-if (!defined('PHPUnit_MAIN_METHOD')) {
- define('PHPUnit_MAIN_METHOD', 'PHP_DocBlockGenerator_AllTests::main');
+
+// Keep tests from running twice when calling this file directly via PHPUnit.
+$call_main = false;
+if (strpos($_SERVER['argv'][0], 'phpunit') === false) {
+ // Called via php, not PHPUnit. Pass the request to PHPUnit.
+ if (!defined('PHPUnit_MAIN_METHOD')) {
+ /** The test's main method name */
+ define('PHPUnit_MAIN_METHOD', 'PHP_DocBlockGenerator_AllTests::main');
+ $call_main = true;
+ }
}
-require_once 'PHPUnit/Framework.php';
-require_once 'PHPUnit/TextUI/TestRunner.php';
-// adds the path of the package if this is a raw install
-file_exists("../../PHP/") and set_include_path('../..' . PATH_SEPARATOR . get_include_path());
-require_once 'DocBlockGeneratorTest.php';
+require_once dirname(__FILE__) . '/helper.inc';
+require_once dirname(__FILE__) . '/DocBlockGeneratorTest.php';
/**
* DocBlock Generator Test suite
@@ -87,14 +92,13 @@ public static function main()
*/
public static function suite()
{
+ $dir = dirname(__FILE__);
$suite = new PHPUnit_Framework_TestSuite('PHP_DocBlockGenerator Tests');
- $suite->addTestSuite('tests_DocBlockGeneratorTest');
+ $suite->addTestFile("$dir/DocBlockGeneratorTest.php");
return $suite;
}
}
-if (PHPUnit_MAIN_METHOD == 'PHP_DocBlockGenerator_AllTests::main') {
+if ($call_main) {
PHP_DocBlockGenerator_AllTests::main();
}
-
-?>
View
41 tests/DocBlockGeneratorTest.php
@@ -34,11 +34,20 @@
* @version SVN: $Id: DocBlockGeneratorTest.php 31 2007-09-13 10:21:01Z mcorne $
* @link http://pear.php.net/package/PHP_DocBlockGenerator
*/
-// Call tests_DocBlockGeneratorTest::main() if this source file is executed directly.
-if (!defined("PHPUnit_MAIN_METHOD")) {
- define("PHPUnit_MAIN_METHOD", "tests_DocBlockGeneratorTest::main");
+
+// Keep tests from running twice when calling this file directly via PHPUnit.
+$call_main = false;
+if (strpos($_SERVER['argv'][0], 'phpunit') === false) {
+ // Called via php, not PHPUnit. Pass the request to PHPUnit.
+ if (!defined('PHPUnit_MAIN_METHOD')) {
+ /** The test's main method name */
+ define('PHPUnit_MAIN_METHOD', 'tests_DocBlockGeneratorTest::main');
+ $call_main = true;
+ }
}
+require_once dirname(__FILE__) . '/helper.inc';
+
require_once "PHPUnit/Framework/TestCase.php";
require_once "PHPUnit/Framework/TestSuite.php";
@@ -74,8 +83,6 @@ class tests_DocBlockGeneratorTest extends PHPUnit_Framework_TestCase
*/
public static function main()
{
- require_once "PHPUnit/TextUI/TestRunner.php";
-
$suite = new PHPUnit_Framework_TestSuite("PHP_DocBlockGeneratorTest");
$result = PHPUnit_TextUI_TestRunner::run($suite);
}
@@ -106,7 +113,11 @@ protected function tearDown()
*/
public function testTagAlign()
{
- ($result = $this->genDocBlockTest('TagAlignments.php')) === true or $this->fail($result);
+ $param = array(
+ 'year' => '2007',
+ );
+
+ ($result = $this->genDocBlockTest('TagAlignments.php', $param)) === true or $this->fail($result);
}
/**
@@ -114,7 +125,11 @@ public function testTagAlign()
*/
public function testTypes()
{
- ($result = $this->genDocBlockTest('TagTypes.php')) === true or $this->fail($result);
+ $param = array(
+ 'year' => '2007',
+ );
+
+ ($result = $this->genDocBlockTest('TagTypes.php', $param)) === true or $this->fail($result);
}
/**
@@ -122,7 +137,11 @@ public function testTypes()
*/
public function testPearFile()
{
- ($result = $this->genDocBlockTest('Pear.php')) === true or $this->fail($result);
+ $param = array(
+ 'year' => '2007',
+ );
+
+ ($result = $this->genDocBlockTest('Pear.php', $param)) === true or $this->fail($result);
}
/**
@@ -191,9 +210,7 @@ private function genDocBlockTest($fileName, $param = array())
return true;
}
}
-// Call tests_DocBlockGeneratorTest::main() if this source file is executed directly.
-if (PHPUnit_MAIN_METHOD == "tests_DocBlockGeneratorTest::main") {
+
+if ($call_main) {
tests_DocBlockGeneratorTest::main();
}
-
-?>
View
18 tests/helper.inc
@@ -0,0 +1,18 @@
+<?php
+
+if ($fp = @fopen('PHPUnit/Autoload.php', 'r', true)) {
+ require_once 'PHPUnit/Autoload.php';
+} elseif ($fp = @fopen('PHPUnit/Framework.php', 'r', true)) {
+ require_once 'PHPUnit/Framework.php';
+ require_once 'PHPUnit/TextUI/TestRunner.php';
+} else {
+ die('skip could not find PHPUnit');
+}
+fclose($fp);
+
+if ('@php_dir@' == '@'.'php_dir'.'@') {
+ // This package hasn't been installed.
+ // Adjust path to ensure includes find files in working directory.
+ set_include_path(dirname(dirname(__FILE__))
+ . PATH_SEPARATOR . get_include_path());
+}
Please sign in to comment.
Something went wrong with that request. Please try again.