Skip to content

Commit

Permalink
Get tests working (Bug #18980).
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Convissor committed Dec 11, 2011
1 parent 61feb82 commit 0c3b2fc
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 29 deletions.
2 changes: 1 addition & 1 deletion PHP/DocBlockGenerator.php
Expand Up @@ -156,4 +156,4 @@ public function generate($infile, $param = array(), $outfile = '')
} }
} }


?> ?>
15 changes: 11 additions & 4 deletions PHP/DocBlockGenerator/License.php
Expand Up @@ -92,10 +92,17 @@ class PHP_DocBlockGenerator_License
*/ */
public function __construct() 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) { foreach ($this->license as $sId => &$aData) {
$sPath = PEAR_INSTALL_DIR . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'PHP_DocBlockGenerator' . DIRECTORY_SEPARATOR . 'licenses'; $sFile = "$sPath/$sId.txt";
$sFile = $sPath . DIRECTORY_SEPARATOR . $sId . '.txt'; if (is_readable($sFile)) {
if (file_exists($sFile) && is_readable($sFile)) {
$this->license[$sId]['text'] = file($sFile,FILE_IGNORE_NEW_LINES); $this->license[$sId]['text'] = file($sFile,FILE_IGNORE_NEW_LINES);
} }
} }
Expand Down Expand Up @@ -150,4 +157,4 @@ public function isValid($name)
} }
} }


?> ?>
7 changes: 6 additions & 1 deletion package2.xml
Expand Up @@ -44,7 +44,9 @@ Fully tested with phpUnit. Code coverage test close to 100%.
<file name="Block.php" role="php" /> <file name="Block.php" role="php" />
<file name="Cli.php" role="php" /> <file name="Cli.php" role="php" />
<file name="GetoptPlus.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="Tokens.php" role="php" />
<file name="Type.php" role="php" /> <file name="Type.php" role="php" />
</dir> </dir>
Expand Down Expand Up @@ -74,6 +76,9 @@ Fully tested with phpUnit. Code coverage test close to 100%.
<dir name="tests"> <dir name="tests">
<file name="AllTests.php" role="test" /> <file name="AllTests.php" role="test" />
<file name="DocBlockGeneratorTest.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"> <dir name="data">
<file name="Parameters.php" role="test" /> <file name="Parameters.php" role="test" />
<file name="Pear.php" role="test" /> <file name="Pear.php" role="test" />
Expand Down
26 changes: 15 additions & 11 deletions tests/AllTests.php
Expand Up @@ -34,15 +34,20 @@
* @version SVN: $Id: AllTests.php 30 2007-07-23 16:46:42Z mcorne $ * @version SVN: $Id: AllTests.php 30 2007-07-23 16:46:42Z mcorne $
* @link http://pear.php.net/package/PHP_DocBlockGenerator * @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 dirname(__FILE__) . '/helper.inc';
require_once 'PHPUnit/TextUI/TestRunner.php'; require_once dirname(__FILE__) . '/DocBlockGeneratorTest.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';


/** /**
* DocBlock Generator Test suite * DocBlock Generator Test suite
Expand Down Expand Up @@ -87,14 +92,13 @@ public static function main()
*/ */
public static function suite() public static function suite()
{ {
$dir = dirname(__FILE__);
$suite = new PHPUnit_Framework_TestSuite('PHP_DocBlockGenerator Tests'); $suite = new PHPUnit_Framework_TestSuite('PHP_DocBlockGenerator Tests');
$suite->addTestSuite('tests_DocBlockGeneratorTest'); $suite->addTestFile("$dir/DocBlockGeneratorTest.php");
return $suite; return $suite;
} }
} }


if (PHPUnit_MAIN_METHOD == 'PHP_DocBlockGenerator_AllTests::main') { if ($call_main) {
PHP_DocBlockGenerator_AllTests::main(); PHP_DocBlockGenerator_AllTests::main();
} }

?>
41 changes: 29 additions & 12 deletions tests/DocBlockGeneratorTest.php
Expand Up @@ -34,11 +34,20 @@
* @version SVN: $Id: DocBlockGeneratorTest.php 31 2007-09-13 10:21:01Z mcorne $ * @version SVN: $Id: DocBlockGeneratorTest.php 31 2007-09-13 10:21:01Z mcorne $
* @link http://pear.php.net/package/PHP_DocBlockGenerator * @link http://pear.php.net/package/PHP_DocBlockGenerator
*/ */
// Call tests_DocBlockGeneratorTest::main() if this source file is executed directly.
if (!defined("PHPUnit_MAIN_METHOD")) { // Keep tests from running twice when calling this file directly via PHPUnit.
define("PHPUnit_MAIN_METHOD", "tests_DocBlockGeneratorTest::main"); $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/TestCase.php";
require_once "PHPUnit/Framework/TestSuite.php"; require_once "PHPUnit/Framework/TestSuite.php";


Expand Down Expand Up @@ -74,8 +83,6 @@ class tests_DocBlockGeneratorTest extends PHPUnit_Framework_TestCase
*/ */
public static function main() public static function main()
{ {
require_once "PHPUnit/TextUI/TestRunner.php";

$suite = new PHPUnit_Framework_TestSuite("PHP_DocBlockGeneratorTest"); $suite = new PHPUnit_Framework_TestSuite("PHP_DocBlockGeneratorTest");
$result = PHPUnit_TextUI_TestRunner::run($suite); $result = PHPUnit_TextUI_TestRunner::run($suite);
} }
Expand Down Expand Up @@ -106,23 +113,35 @@ protected function tearDown()
*/ */
public function testTagAlign() 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);
} }


/** /**
* Tag types test * Tag types test
*/ */
public function testTypes() 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);
} }


/** /**
* Pear file test * Pear file test
*/ */
public function testPearFile() 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);
} }


/** /**
Expand Down Expand Up @@ -191,9 +210,7 @@ private function genDocBlockTest($fileName, $param = array())
return true; 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(); tests_DocBlockGeneratorTest::main();
} }

?>
18 changes: 18 additions & 0 deletions 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());
}

0 comments on commit 0c3b2fc

Please sign in to comment.