Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed test suite to work with phpunit

  • Loading branch information...
commit 87d839ea2696ea0c65127990a848031807145c13 1 parent 2a2db26
@clbustos authored
View
14 Rakefile
@@ -1,16 +1,8 @@
require 'rake'
+require 'fileutils'
task :test do
- files=Dir.glob("tests/*.phpt")
- passed=0
- failed=0
- files.each {|f|
- if system "php #{f}"
- passed+=1
- else
- failed+=1
- end
- }
- puts "Passed:#{passed}, Failed:#{failed}"
+ Dir.chdir('tests')
+ system "phpunit ."
end
task :install do
View
432 tests/Beautifier.phpt
@@ -1,432 +0,0 @@
-<?php
- /* vim: set expandtab tabstop=4 shiftwidth=4: */
- // +----------------------------------------------------------------------+
- // | PHP version 5 |
- // +----------------------------------------------------------------------+
- // | Copyright (c) 1997-2004 The PHP Group |
- // +----------------------------------------------------------------------+
- // | This source file is subject to version 3.0 of the PHP license, |
- // | that is bundled with this package in the file LICENSE, and is |
- // | available through the world-wide-web at the following url: |
- // | http://www.php.net/license/3_0.txt. |
- // | If you did not receive a copy of the PHP license and are unable to |
- // | obtain it through the world-wide-web, please send a note to |
- // | license@php.net so we can mail you a copy immediately. |
- // +----------------------------------------------------------------------+
- // | Authors: Claudio Bustos <cdx@users.sourceforge.net> |
- // | Jens Bierkandt <schtorch@users.sourceforge.net> |
- // +----------------------------------------------------------------------+
- //
- // $Id:
- require_once "PHPUnit.php";
- # use pear or local version of php_beautifier
- if (file_exists('../Beautifier.php')) {
- include_once '../Beautifier.php';
- } else {
- include_once "PHP/Beautifier.php";
- }
- // Mock Filter object
- class Test_Filter extends PHP_Beautifier_Filter {
- public $aTokens = array();
- public $aModes = array();
- public $iIndex = 0;
- function handleToken($token)
- {
- $this->oBeaut->add($token[1]);
- $this->aTokens[] = $token;
- foreach($this->oBeaut->aModesAvailable as $sMode) {
- $this->aModes[$this->iIndex][$sMode] = $this->oBeaut->getMode($sMode);
- }
- $this->iIndex++;
- }
- }
- class Beautifier_TestCase extends PHPUnit_TestCase {
- function __construct($name)
- {
- $this->PHPUnit_TestCase($name);
- }
- function setUp()
- {
- $this->oBeaut = new PHP_Beautifier();
- $this->oBeaut->setInputFile(__FILE__);
- }
- function testsetInputFile()
- {
- $this->assertTrue($this->oBeaut->setInputFile(__FILE__));
- try {
- $this->assertFalse($this->oBeaut->setInputFile('NO_FILE'));
- }
- catch(Exception $oExp) {
- $this->assertTrue($oExp instanceof Exception);
- }
- }
- function testaddFilterDirectory()
- {
- $sDir = PHP_Beautifier_Common::normalizeDir(dirname(__FILE__));
- $this->oBeaut->addFilterDirectory($sDir);
- $aDirs = $this->oBeaut->getFilterDirectories();
- $this->assertEquals(end($aDirs) , $sDir);
- }
- function testgetFilterList()
- {
- $aFilterList = array(
- 'Default'
- );
- $this->assertEquals($aFilterList, $this->oBeaut->getFilterList());
- }
- function testaddFilter()
- {
- if(file_exists('../Beautifier/Filter/ArrayNested.filter.php')) {
- include_once('../Beautifier/Filter/ArrayNested.filter.php');
- } else {
- include_once ('PHP/Beautifier/Filter/ArrayNested.filter.php');
-
- } // Include filter by string
- $this->oBeaut->addFilter('Pear');
- $aFilterList = array(
- 'Pear',
- 'Default'
- );
- $this->assertEquals($aFilterList, $this->oBeaut->getFilterList());
- // include filter by object
- $oFilter = new PHP_Beautifier_Filter_ArrayNested($this->oBeaut);
- $this->oBeaut->addFilter($oFilter);
- array_unshift($aFilterList, 'ArrayNested');
- $this->assertEquals($aFilterList, $this->oBeaut->getFilterList());
- try {
- $this->oBeaut->addFilter('Error');
- }
- catch(Exception $oExp) {
- $this->assertTrue($oExp instanceof Exception_PHP_Beautifier_Filter);
- }
- }
- public function testgetFilterListTotal()
- {
- $aEspFilters = array(
- 'Default',
- 'ListClassFunction',
- 'NewLines',
- 'Pear',
- 'ArrayNested',
- 'IndentStyles',
- 'Lowercase',
- 'phpBB',
- 'DocBlock',
- 'Fluent',
- 'EqualsAlign'
- );
- sort($aEspFilters);
- $aRealFilters = $this->oBeaut->getFilterListTotal();
- $this->assertEquals($aEspFilters, $aRealFilters);
- }
- function testsetIndentChar()
- {
- $this->oBeaut->setIndentChar('*');
- $this->assertEquals('*', $this->oBeaut->sIndentChar);
- }
- function testsetIndentNumber()
- {
- $this->oBeaut->setIndentNumber('5');
- $this->assertEquals(5, $this->oBeaut->iIndentNumber);
- }
- function testsetNewLine()
- {
- $this->oBeaut->setNewLine("\r\n");
- $this->assertEquals("\r\n", $this->oBeaut->sNewLine);
- }
- function testsetOutputFile()
- {
- $this->oBeaut->setOutputFile('test.php');
- $this->assertEquals("test.php", $this->oBeaut->sOutputFile);
- }
- function testsetMode()
- {
- $this->oBeaut->setMode('test');
- $this->assertTrue($this->oBeaut->getMode('test'));
- }
- function testunsetMode()
- {
- $this->oBeaut->unsetMode('test');
- $this->assertFalse($this->oBeaut->getMode('test'));
- }
- function testGetFilterDescription()
- {
- $oFilter = new PHP_Beautifier_Filter_Default($this->oBeaut);
- $this->assertEquals($this->oBeaut->getFilterDescription('Default') , $oFilter);
- }
- function testsave()
- {
- $sTempFile = tempnam("/tmp", "PHP_TEST");
- $this->oBeaut->process();
- $this->oBeaut->save($sTempFile);
- $this->assertEquals(preg_replace("/\s/", "", file_get_contents(__FILE__)) , preg_replace("/\s/", "", file_get_contents($sTempFile)));
- @unlink($sTempFile);
- }
- function testget()
- {
- $this->oBeaut->process();
- $this->assertEquals(preg_replace("/\s/", "", file_get_contents(__FILE__)) , preg_replace("/\s/", "", $this->oBeaut->get()));
- }
- function testComments()
- {
- $sTextOriginal = <<<SCRIPT
-<?php
-// short comment
-/* Long comment */
-\$a=5; // short comment 2
-\$b=6; /* long comment 2 */
-/*
-Long comment 3
-*/
-/*
-Indented
- Comment
- With some levels
- Now
- Works
-*/
-?>
-SCRIPT;
- $sTextExpected = <<<SCRIPT
-<?php
-// short comment
-/* Long comment */
-\$a = 5; // short comment 2
-\$b = 6; /* long comment 2 */
-/*
-Long comment 3
-*/
-/*
-Indented
- Comment
- With some levels
- Now
- Works
-*/
-?>
-SCRIPT;
- $sTextExpected = str_replace("\r\n", "\n", $sTextExpected);
- $this->oBeaut->setInputString($sTextOriginal);
- $this->oBeaut->process();
- $sTextActual = $this->oBeaut->get();
- /*for ($x = 0;$x<strlen($sTextExpected);$x++) {
- $this->assertEquals($sTextExpected{$x}, $sTextActual{$x});
- }*/
- $this->assertEquals($sTextExpected, $sTextActual);
-
- }
-function testDocComment()
- {
- $sTextOriginal = <<<SCRIPT
-<?php
-/** Doc comment inline */
- /** First line
- * Other line
- */
-/**
- * Doc normal comment
- *
- * Other line
- */
-?>
-SCRIPT;
- $sTextExpected = <<<SCRIPT
-<?php
-/** Doc comment inline */
-/** First line
- * Other line
- */
-/**
- * Doc normal comment
- *
- * Other line
- */
-?>
-SCRIPT;
- $this->oBeaut->setInputString($sTextOriginal);
- $this->oBeaut->process();
- $this->assertEquals($sTextExpected,$this->oBeaut->get());
- }
- function testNestedSwitch() {
-$sTextOriginal = <<<SCRIPT
-<?php
-switch(\$a) {
- case 1:
- case 2:
- switch(\$b) {
- case 1:
- case 2:
- switch(\$c) {
- case 1:
- case 2:
- echo "hola";
- break;
- default:
- echo "leso";
- break;
- }
- break;
- case 3:
- echo "hola";
- break;
- }
- break;
-}
-?>
-SCRIPT;
- $sTextExpected = <<<SCRIPT
-<?php
-switch (\$a) {
- case 1:
- case 2:
- switch (\$b) {
- case 1:
- case 2:
- switch (\$c) {
- case 1:
- case 2:
- echo "hola";
- break;
- default:
- echo "leso";
- break;
- }
- break;
- case 3:
- echo "hola";
- break;
- }
- break;
-}
-?>
-SCRIPT;
- $this->oBeaut->setInputString($sTextOriginal);
- $this->oBeaut->process();
- $this->assertEquals($sTextExpected,$this->oBeaut->get());
-
- }
- /*
- function testresetProperties() {
- }
-
- function testgetTokenAssoc() {
- }
- function testgetTokenAssocText() {
- }
- function testreplaceTokenAssoc() {
- }
- function testgetTokenFunction() {
- }
- function testcontrolToken() {
- }
- function testcontrolTokenPost() {
- }
- function testpushControlSeq() {
- }
- function testpopControlSeq() {
- }
- function testpushControlParenthesis() {
- }
- function testpopControlParenthesis() {
- }
- function testsetBeautify() {
- }
- function testshow() {
- }
-
- function testgetSetting() {
- }
- function testgetControlSeq() {
- }
- function testgetControlParenthesis() {
- }
-
- function testgetMode() {
- }
- function testadd() {
- }
- function testpop() {
- }
- function testaddNewLine() {
- }
- function testaddIndent() {
- }
- function testgetPreviousToken() {
- }
- function testgetPreviousTokenConstant() {
- }
- function testgetPreviousTokenContent() {
- }
- function testgetNextToken() {
- }
- function testgetNextTokenConstant() {
- }
- function testgetNextTokenContent() {
- }
- function testremoveWhitespace() {
- }
- */
- }
- class BeautifierInternal_TestCase extends PHPUnit_TestCase {
- public $oBeaut;
- public $oFilter;
- function __construct($name)
- {
- $this->PHPUnit_TestCase($name);
- }
- function setUp()
- {
- $this->oBeaut = new PHP_Beautifier();
- $this->oFilter = new Test_Filter($this->oBeaut);
- $this->oBeaut->addFilter($this->oFilter);
- }
- function setText($sText)
- {
- $this->oBeaut->setInputString($sText);
- $this->oBeaut->process();
- }
- function testSetBeautify()
- {
- $sText = <<<SCRIPT
-<?php
-echo "sdsds";
-// php_beautifier->setBeautify(false);
-echo "don't process this token";
-// php_beautifier->on(true);
-
-?>
-SCRIPT;
- $this->setText($sText);
- // verify setBeautify
- $this->assertTrue(count($this->oFilter->aTokens) == 6);
- }
- function testModes()
- {
- $sText = <<<SCRIPT
-<?php
-\$a=(\$b>1)?'0':'2';
-\$b="asa{\$a}";
-?>
-SCRIPT;
- //php_beautifier->seatBeautify(true);
- $this->setText($sText);
- // ternary mode from ? to :
- $this->assertFalse($this->oFilter->aModes[7]['ternary_operator']);
- for ($x = 8;$x <= 10;$x++) {
- $this->assertTrue($this->oFilter->aModes[$x]['ternary_operator'], $x);
- }
- $this->assertFalse($this->oFilter->aModes[15]['double_quote']);
- // quote from " to } previous to "
- for ($x = 16;$x <= 20;$x++) {
- $this->assertTrue($this->oFilter->aModes[$x]['double_quote'], $x);
- }
- }
-
- }
- $suite = new PHPUnit_TestSuite('Beautifier_TestCase');
- $result = PHPUnit::run($suite);
- echo $result->toString();
- $suite = new PHPUnit_TestSuite('BeautifierInternal_TestCase');
- $result = PHPUnit::run($suite);
- echo $result->toString();
-?>
View
BIN  tests/Beautifier.tar.bz2
Binary file not shown
View
BIN  tests/Beautifier.tar.gz
Binary file not shown
View
1,145 tests/Beautifier_Bugs.phpt
@@ -1,1145 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-// +----------------------------------------------------------------------+
-// | PHP version 5 |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2004 The PHP Group |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 3.0 of the PHP license, |
-// | that is bundled with this package in the file LICENSE, and is |
-// | available through the world-wide-web at the following url: |
-// | http://www.php.net/license/3_0.txt. |
-// | If you did not receive a copy of the PHP license and are unable to |
-// | obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Authors: Claudio Bustos <cdx@users.sourceforge.net> |
-// | Jens Bierkandt <schtorch@users.sourceforge.net> |
-// +----------------------------------------------------------------------+
-//
-// $Id:
-require_once "PHPUnit/Framework.php";
-if (file_exists('../Beautifier.php')) {
- include_once '../Beautifier.php';
-} else {
- include_once "PHP/Beautifier.php";
-}
-
-class PHP_Beautifier_Filter_BBY extends PHP_Beautifier_Filter {
-function t_access($sTag) { $this->oBeaut->add($this->oBeaut->getTokenName($this->oBeaut->getControlSeq())); return PHP_Beautifier_Filter::BYPASS; }
-}
-
-class Beautifier_Bugs extends PHPUnit_Framework_TestCase
-{
-
- function setUp()
- {
- $this->oBeaut = new PHP_Beautifier();
- }
- function setText($sText)
- {
- $this->oBeaut->setInputString($sText);
- $this->oBeaut->process();
- }
- /**
- * HeredocBeforeCloseTag
- * Close tag after heredoc remove whitespace,
- * breaking the script.
- *
- */
- function testBugInternal1()
- {
- $sText = <<<SCRIPT
-<?php
-\$a = <<<HEREDOC
-sdsdsds
-HEREDOC;
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-\$a = <<<HEREDOC
-sdsdsds
-HEREDOC;
-
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * Bug 1597
- * Brace after short comment in new line was appended to
- * the comment, breaking the code
- */
- function testBug1597()
- {
- $sText = <<<SCRIPT
-<?php
-if (\$_POST["url"] != "") //inserting data
-{
-}
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-if (\$_POST["url"] != "") //inserting data
-{
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * Bug 2301
- * When I try to beautify PHP5 code with the 'throw new Exception'
- * statement, the code is not formatted correctly. The
- * whitespace between throw AND new is deleted.
- */
- function testBug2301()
- {
- $sText = <<<SCRIPT
-<?php
-throw new AccountFindException();
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-throw new AccountFindException();
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * Bug from Pavel Chtchevaev, 2004-11-17
- * There's one more issue about the default filter, try beautifying with
- * it the following string:
- * "<?php\n\$o->_test1(\$c->test2()->test3())\n?>"
- * It will return:
- * "<?php\n \$o->_test1(\$c->test2() ->test3())\n?>"
- */
- function testBugChtchevaev_2004_11_17()
- {
- $sText = <<<SCRIPT
-<?php
-\$o->_test1(\$c-> test2()-> test3());
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-\$o->_test1(\$c->test2()->test3());
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * Bug 3257
- * Comments between if and elseif screws up formatting.
- * The beautifier will cascade and start moving the indentations over
- * if there is a comment between if {} and elseif {}
- */
- function testBug3257()
- {
- $sText = <<<SCRIPT
-<?php
- class Foo {
- var \$foobar = 0;
- function Foo(\$a, \$b) {
- if (\$a) {
- dostuff();
- }
- // \$a no good
- elseif {
- dootherstuff();
- }
- // \$c maybe
- elseif {
- yea();
- }
- }
-
- function bar() {
- echo "Hello";
- }
- }
-
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-class Foo {
- var \$foobar = 0;
- function Foo(\$a, \$b) {
- if (\$a) {
- dostuff();
- }
- // \$a no good
- elseif {
- dootherstuff();
- }
- // \$c maybe
- elseif {
- yea();
- }
- }
- function bar() {
- echo "Hello";
- }
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * Bug from Daniel Convissor, 2005-06-20
- * Switch statements aren't coming out right. I, and most PEAR developers
- * I've asked, partial to them looking like this:
- * @deprecated as bug!
- * <code>
- * switch ($subId) {
- * case "myevents";
- * $myeventsOn = "on";
- * break;
- * case "publicevents";
- * $publiceventsOn = "on";
- * break;
- * }
- * </code>
- */
- function deprecatedtestBugConvissor_2005_06_20()
- {
- $this->oBeaut->addFilter("Pear");
- $sText = <<<SCRIPT
-<?php
-switch (\$subId) {
-case "myevents":
-\$myeventsOn = "on";
-break;
-case "publicevents":
-\$publiceventsOn = "on";
-break;
-}
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-switch (\$subId) {
- case "myevents":
- \$myeventsOn = "on";
- break;
-
- case "publicevents":
- \$publiceventsOn = "on";
- break;
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- function testBugJustinh_2005_07_26()
- {
- $sText = <<<SCRIPT
-<?php
-switch (\$var) {
-case 1:
-print "hi";
-break;
-case 2:
-default:
-break;
-}
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-switch (\$var) {
- case 1:
- print "hi";
- break;
- case 2:
- default:
- break;
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- function testBugjuancarlos2005_09_13()
- {
- $this->oBeaut->addFilter("ArrayNested");
- $this->oBeaut->addFilter('IndentStyles', array(
- 'style' => 'allman'
- ));
- $sText = <<<SCRIPT
-<?php include_once ("turnos.conf.php")
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php include_once ("turnos.conf.php")
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- function testBug5711()
- {
- $this->oBeaut->addFilter("Pear");
- $sText = <<<SCRIPT
-<?php
-
-class CampaignManagerConfig {
-
- const BLOCKSIZE_ALL = 9999999;
-
- public static function getStagingUrl(\$liveUrl) {
- return true;
- }
-
-}
-
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-class CampaignManagerConfig
-{
- const BLOCKSIZE_ALL = 9999999;
- public static function getStagingUrl(\$liveUrl)
- {
- return true;
- }
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- function testBug6237()
- {
- $this->oBeaut->addFilter("Pear");
- $sText = <<<SCRIPT
-<?php
-\$_SESSION["test\$i"];
-\$_SESSION["test_\$i"];
-\$_SESSION['test_\$i'];
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-\$_SESSION["test\$i"];
-\$_SESSION["test_\$i"];
-\$_SESSION['test_\$i'];
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * according to: http://pear.php.net/manual/en/standards.control.php
- * control strutures should be indented in K&R style
- *
- * if (<cond>) {
- * <body>
- * }
- * however, are getting indented in Allman style
- * all control structures are affected.
- */
- function testBug7347()
- {
- $this->oBeaut->addFilter("Pear");
- $sText = <<<SCRIPT
-<?php
-class Foo {
- public function __construct() {
- if(\$foo && \$bar) { echo "FUBAR"; }
- }
-}
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-class Foo
-{
- public function __construct()
- {
- if (\$foo && \$bar) {
- echo "FUBAR";
- }
- }
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * Bad code to detect tokens
- */
- function testInternal2()
- {
- $this->assertTrue(array_key_exists(T_COMMENT, $this->oBeaut->aTokenFunctions));
- }
- /**
- * Adding a comment after a case statement in a switch causes
- * the indenting to be wrong.
- */
- function testBug7759()
- {
- $sText = <<<SCRIPT
-<?php
-echo 0;
-switch(1) {
-case 1:
-case 5: // 5
-echo 1;
-break;
-case 2: //2
-echo "something";
-echo "something";
-case 3: /*3 */ /* 3? */
-case 4:
-default:
-echo '2';
-break;
-}
-echo 1;
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-echo 0;
-switch (1) {
- case 1:
- case 5: // 5
- echo 1;
- break;
- case 2: //2
- echo "something";
- echo "something";
- case 3: /*3 */ /* 3? */
- case 4:
- default:
- echo '2';
- break;
-}
-echo 1;
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- function testBug7818()
- {
- //$this->oBeaut->startLog();
- $sText = <<<SCRIPT
-<?php
-\$field->createElement(\$form, \$this->_table->{\$field->id}, \$defaults);
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-\$field->createElement(\$form, \$this->_table->{\$field->id}, \$defaults);
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * Will be great if you can rewrite T_OPEN_TAG_WITH_ECHO
- * in the default filter, specially <?= because it will be
- * removed in PHP6.
- */
- function testBug7854()
- {
- if(ini_get("short_open_tag")) {
- $this->oBeaut->addFilter("Pear");
- $sText = <<<SCRIPT
-<?= \$var ?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php echo \$var ?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- } else {
- $this->markTestSkipped(
- 'Needs short_open_tag php.ini set.'
- );
- }
- }
- /**
- * the first lines are intended if -l "ListClassFunction()"
- * is enabled
- */
- function testBug7307()
- {
- // $this->oBeaut->startLog();
- $this->oBeaut->addFilter("ListClassFunction");
- $sText = <<<SCRIPT
-<?php
-/**
- * Class and Function List:
- * Function list:
- * Classes list:
- */
-require_once 'dbobject.class.php';
-require_once 'kfp-globals.inc.php';
-class test {
- function m1() {}
- function m2() {}
-}
-function f1() {
-}
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-/**
- * Class and Function List:
- * Function list:
- * - m1()
- * - m2()
- * - f1()
- * Classes list:
- * - test
- */
-require_once 'dbobject.class.php';
-require_once 'kfp-globals.inc.php';
-class test {
- function m1() {
- }
- function m2() {
- }
-}
-function f1() {
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * When using the "break" command, the command takes an optional parameter, see http://de.php.net/break for details. But this doesn't work when using the beautifier, because, for example "break 2;" morphs to "break2;" (notice the missing space, which makes the PHP interpreter quite sour :-(
- */
- function testBug_rolfhub_2007_02_07_1()
- {
- $sText = <<<SCRIPT
-<?php
-\$i = 0;
-while (++\$i) {
- switch (\$i) {
- case 5:
- echo "At 5<br />";
- break 1; /* Exit only the switch. */
- case 10:
- echo "At 10; quitting<br />";
- break 2; /* Exit the switch and the while. */
- default:
- break;
- }
-}
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-\$i = 0;
-while (++\$i) {
- switch (\$i) {
- case 5:
- echo "At 5<br />";
- break 1; /* Exit only the switch. */
- case 10:
- echo "At 10; quitting<br />";
- break 2; /* Exit the switch and the while. */
- default:
- break;
- }
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * When using the "break" command, the command takes an optional parameter, see http://de.php.net/break for details. But this doesn't work when using the beautifier, because, for example "break 2;" morphs to "break2;" (notice the missing space, which makes the PHP interpreter quite sour :-(
- */
- function testBug_rolfhub_2007_02_07_1_pear()
- {
- $this->oBeaut->addFilter("Pear");
- $sText = <<<SCRIPT
-<?php
-\$i = 0;
-while (++\$i) {
- switch (\$i) {
- case 5:
- echo "At 5<br />";
- break 1; /* Exit only the switch. */
- case 10:
- echo "At 10; quitting<br />";
- break 2; /* Exit the switch and the while. */
- default:
- break;
- }
-}
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-\$i = 0;
-while (++\$i) {
- switch (\$i) {
- case 5:
- echo "At 5<br />";
- break 1; /* Exit only the switch. */
- case 10:
- echo "At 10; quitting<br />";
- break 2; /* Exit the switch and the while. */
- default:
- break;
- }
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * The beautifer removes the whitespaces left and right of the operator, so for example "echo 2 . 1 . 0 . "\n";" becomes "echo 2.1.0."\n";"
- */
- function testBug_rolfhub_2007_02_07_2()
- {
- $sText = <<<SCRIPT
-<?php
-echo (1.0 . " " . 2 . 3);
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-echo (1.0 . " " . 2 . 3);
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * Description:
- * ------------
- * When using the default filter, a T_ARRAY token used as a Type hint
- * (http://php.net/language.oop5.typehinting) does not get a space
- * after it.
- * Similarly the T_CLONE token also misses whitespace after it.
- */
- function testBug10839()
- {
- $sText = <<<SCRIPT
-<?php
-class test
-{
- function test(array \$moo)
- {
- return clone \$this;
- }
- public function test(OtherClass \$otherclass) {
- echo \$otherclass->var;
- }
-
-}
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-class test {
- function test(array \$moo) {
- return clone \$this;
- }
- public function test(OtherClass \$otherclass) {
- echo \$otherclass->var;
- }
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * When processing the T_DOT in the partial tokenized script, and you use
- * getPreviousWhitespace(), it will go all the back pass the T_ECHO and
- * pick up the T_WHITESPACE prior to the T_ECHO. It should actually stop
- * at the T_CONSTANT_ENCAPSED_STRING.
- */
- function testBug11661()
- {
- $sText = <<<SCRIPT
-<?php
-if (empty(\$user_password) AND empty(\$user_password2)) {
- \$user_password = makepass();
-
- } elseif (\$user_password != \$user_password2) {
-
- title(_NEWUSERERROR);
-
- OpenTable();
-
- echo '<center><b>'._PASSDIFFERENT.'</b><br /><br />'._GOBACK.'</center>';
-
- CloseTable();
-
- include_once('footer.php');
-
- die();
-
- } elseif (\$user_password == \$user_password2 AND
-strlen(\$user_password) < \$minpass) {
-
- title(_NEWUSERERROR);
-
- OpenTable();
-
- echo '<center>'._YOUPASSMUSTBE.' <b>'.\$minpass.'</b>' . _CHARLONG . '<br /><br />' . _GOBACK . '</center>';
-
- CloseTable();
-
- include_once ('footer.php');
-
- die();
-
- }
-?>
-SCRIPT;
-
-$this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-if (empty(\$user_password) AND empty(\$user_password2)) {
- \$user_password = makepass();
-} elseif (\$user_password != \$user_password2) {
- title(_NEWUSERERROR);
- OpenTable();
- echo '<center><b>' . _PASSDIFFERENT . '</b><br /><br />' . _GOBACK . '</center>';
- CloseTable();
- include_once ('footer.php');
- die();
-} elseif (\$user_password == \$user_password2 AND strlen(\$user_password) < \$minpass) {
- title(_NEWUSERERROR);
- OpenTable();
- echo '<center>' . _YOUPASSMUSTBE . ' <b>' . \$minpass . '</b>' . _CHARLONG . '<br /><br />' . _GOBACK . '</center>';
- CloseTable();
- include_once ('footer.php');
- die();
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * Doesn't works!
- */
- function atestComplexCurlySyntax()
- {
- try {
- //$this->oBeaut->startLog();
- $sText = '<?php
-$great = "fantastic";
-echo "This is { $great}";
-echo "This is {$great}";
-echo "This is ${great}";
-echo "This square is {$square->width}00 centimeters broad.";
-echo "This works: {$arr[4][3]}";
-echo "This is wrong: {$arr[foo][3]}";
-echo "This works: {$arr[foo][3]}";
-echo "This works: " . $arr["foo"][3];
-echo "You can even write {$obj->values[3]->name}";
-// echo "This is the value of the var named $name: {${$name}}";
-?>';
- $this->setText($sText);
- $sExpected = '<?php
-$great = "fantastic";
-echo "This is { $great}";
-echo "This is {$great}";
-echo "This is ${great}";
-echo "This square is {$square->width}00 centimeters broad.";
-echo "This works: {$arr[4][3]}";
-echo "This is wrong: {$arr[foo][3]}";
-echo "This works: {$arr[foo][3]}";
-echo "This works: " . $arr["foo"][3];
-echo "You can even write {$obj->values[3]->name}";
-// echo "This is the value of the var named $name: {${$name}}";
-?>';
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- catch(Exception $oExp) {
- $this->assertTrue(false);
- }
- }
-
- /**
- * Double Ternary Issue
- */
- function testBug11941()
- {
- //$this->oBeaut->startLog();
- $this->oBeaut->addFilter('Pear');
- $sText = <<<SCRIPT
-<?php
-\$html_on = ( \$submit || \$refresh ) ? ((!empty(\$HTTP_POST_VARS['disable_html'])) ? 0 : TRUE ):\$userdata['user_allowhtml'];
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-\$html_on = (\$submit || \$refresh) ? ((!empty(\$HTTP_POST_VARS['disable_html'])) ? 0 : TRUE) : \$userdata['user_allowhtml'];
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
-
-
-
-
- /**
- * Pear filter appends space to function definition line
- */
- function testBug13600()
- {
- //$this->oBeaut->startLog();
- $this->oBeaut->addFilter('Pear');
- $sText = <<<SCRIPT
-<?php
-function example(){
-}
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-function example()
-{
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
-
-
- /**
- * Pear filter breaks output - for valid, curly syntax "$this->{$method}();"
- */
- function testBug13602()
- {
- //$this->oBeaut->startLog();
- $this->oBeaut->addFilter('Pear');
- $sText = <<<SCRIPT
-<?php
-function example()
-{
- \$this->{\$method}();
-}
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-function example()
-{
- \$this->{\$method}();
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
-
-
-
- function testBug13795()
- {
- $this->oBeaut->addFilter("IndentStyles");
- $sText = <<<SCRIPT
-<?php if (true){echo 'a';}else echo 'b'; ?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php if (true) {
- echo 'a';
-}
-else echo 'b'; ?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
-
- function testBug13805()
- {
- $this->oBeaut->addFilter("Pear");
- $sText = <<<SCRIPT
-<?php
-switch (\$condition) {
-case 1:
-action1();
-break;
-case 2:
-action2();
-break;
-default:
-defaultaction();
-break;
-}
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-switch (\$condition) {
-case 1:
- action1();
- break;
-
-case 2:
- action2();
- break;
-
-default:
- defaultaction();
- break;
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
-
-
- function atestBug13861()
- {
- $sText = <<<SCRIPT
-<?php
-/*
-<?php
-class test
-{
- function test()
- {
- switch (true) {
- default:
- }
-}
-}
-*/
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-/*
-<?php
-class test
-{
- function test()
- {
- switch (true) {
- default:
- }
-}
-}
-*/
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
-
- function testBug14175()
- {
- $sText = <<<SCRIPT
-<?php
-func( <<<END
-<form id="editform" name="editform" method="post" action=""
-enctype="multipart/form-data">
-END
-);
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-func(<<<END
-<form id="editform" name="editform" method="post" action=""
-enctype="multipart/form-data">
-END
-);
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- function testBug14429()
- {
- $this->oBeaut->addFilter('Pear');
-
- $sText = <<<SCRIPT
-<?php
-\$var = new StdClass();
-\$var->text = 'hello';
-\$ok['what'] = 'ok';
-switch (\$something){
-case 'one':
-echo "{\$var->text} world {\$ok['what']}";
-break;
-default:
-break;
-}
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-\$var = new StdClass();
-\$var->text = 'hello';
-\$ok['what'] = 'ok';
-switch (\$something) {
-case 'one':
- echo "{\$var->text} world {\$ok['what']}";
- break;
-
-default:
- break;
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
-function testBug14459()
- {
- $sText = <<<SCRIPT
-<?php
-\$bye = "Goodbye";
-echo "Curly {Hello}.";
-echo "Curly {{\$bye}}.";
-echo "Curly {". \$bye ."}.";
-?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-\$bye = "Goodbye";
-echo "Curly {Hello}.";
-echo "Curly {{\$bye}}.";
-echo "Curly {" . \$bye . "}.";
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * Lowercase filter prepends the control structure with ugly space
- */
-
- function testBug11245() {
- $this->oBeaut->addFilter('Lowercase');
- $sText = <<<SCRIPT
-<?php
-IF (\$a OR \$b) { echo 'foo'; } ELSE IF (\$b AND \$c AND \$d) { echo 'bar'; }
-?>
-SCRIPT;
-$this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-if (\$a or \$b) {
- echo 'foo';
-} else if (\$b and \$c and \$d) {
- echo 'bar';
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
- /**
- * Lowercase filter prepends the control structure with ugly space
- */
-
- function testBug14396() {
- //$this->oBeaut->startLog();
- $this->oBeaut->addFilter('Lowercase');
- $sText = <<<SCRIPT
-<?php
-\$a==FALSE;
-\$b==TRUE;
-?>
-SCRIPT;
-$this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-\$a == false;
-\$b == true;
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
-
- /**
- * Bug 14537
- * PHP_Beautifier breaks code with namespace and/or use statements
- */
- function testBug14537() {
-
- if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
-
- $sText = <<<SCRIPT
-<?php
-namespace MyTestnamespace.someSubNS; use OtherNamespace::ClassA; use AnotherNamespace::Class1 as Class2; ?>
-SCRIPT;
- $this->setText($sText);
- $sExpected = <<<SCRIPT
-<?php
-namespace MyTestnamespace.someSubNS;
-use OtherNamespace::ClassA;
-use AnotherNamespace::Class1 as Class2;
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- } else {
- $this->markTestSkipped(
- 'Needs PHP5.3+');
- }
- }
-
- function testBug14754() {
- $this->oBeaut->startLog();
-$sText = <<<SCRIPT
-<?php
-class Z {
- public function a() {
- echo "hi";
- }
- private function b() {
- echo "hi"; // Comment
- }
- private function c() {
- echo "hi";
- }
-}
-?>
-SCRIPT;
-$this->oBeaut->addFilter('BBY');
-$this->setText($sText);
-$sExpected = <<<SCRIPT
-<?php
-class Z {
- T_CLASSpublic function a() {
- echo "hi";
- }
- T_CLASSprivate function b() {
- echo "hi"; // Comment
-
- }
- T_CLASSprivate function c() {
- echo "hi";
- }
-}
-?>
-SCRIPT;
- $this->assertEquals($sExpected, $this->oBeaut->get());
- }
-
-}
-?>
View
61 tests/Beautifier_Common.phpt
@@ -1,61 +0,0 @@
-<?php
- /* vim: set expandtab tabstop=4 shiftwidth=4: */
- // +----------------------------------------------------------------------+
- // | PHP version 5 |
- // +----------------------------------------------------------------------+
- // | Copyright (c) 1997-2004 The PHP Group |
- // +----------------------------------------------------------------------+
- // | This source file is subject to version 3.0 of the PHP license, |
- // | that is bundled with this package in the file LICENSE, and is |
- // | available through the world-wide-web at the following url: |
- // | http://www.php.net/license/3_0.txt. |
- // | If you did not receive a copy of the PHP license and are unable to |
- // | obtain it through the world-wide-web, please send a note to |
- // | license@php.net so we can mail you a copy immediately. |
- // +----------------------------------------------------------------------+
- // | Authors: Claudio Bustos <cdx@users.sourceforge.net> |
- // | Jens Bierkandt <schtorch@users.sourceforge.net> |
- // +----------------------------------------------------------------------+
- //
- // $Id:
- require_once "PHPUnit.php";
- if (file_exists('../Beautifier.php')) {
- include_once '../Beautifier.php';
- } else {
- include_once "PHP/Beautifier.php";
- }
- class Beautifier_Common_TestCase extends PHPUnit_TestCase {
- function Beautifier_Common_TestCase($name)
- {
- $this->PHPUnit_TestCase($name);
- }
- function testnormalizeDir()
- {
- $sDir = str_replace(DIRECTORY_SEPARATOR, '/', dirname(__FILE__)) .'/';
- $this->assertEquals($sDir, PHP_Beautifier_Common::normalizeDir(dirname(__FILE__)));
- }
- function testgetFilesByPattern()
- {
- $sDir = PHP_Beautifier_Common::normalizeDir(dirname(__FILE__));
- $aExpected = array(
- $sDir.'Beautifier.phpt'
- );
- $this->assertEquals($aExpected, PHP_Beautifier_Common::getFilesByPattern($sDir, 'Beautifier\.....', false));
- }
- function testgetFilesByGlob()
- {
- $sDir = PHP_Beautifier_Common::normalizeDir(dirname(__FILE__));
- $aExpected = array(
- $sDir.'Beautifier_Common.phpt'
- );
- $this->assertEquals($aExpected, PHP_Beautifier_Common::getFilesByGlob($sDir.basename(__FILE__, '.phpt') .'.????', false));
- }
- function testWsToString() {
- $this->assertEquals(' \t\r\n',PHP_Beautifier_Common::wsToString(" \t\r\n"));
- }
-
- }
- $suite = new PHPUnit_TestSuite('Beautifier_Common_TestCase');
- $result = PHPUnit::run($suite);
- echo $result->toString();
-?>
View
80 tests/Beautifier_Internal.phpt
@@ -1,80 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-// +----------------------------------------------------------------------+
-// | PHP version 5 |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2004 The PHP Group |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 3.0 of the PHP license, |
-// | that is bundled with this package in the file LICENSE, and is |
-// | available through the world-wide-web at the following url: |
-// | http://www.php.net/license/3_0.txt. |
-// | If you did not receive a copy of the PHP license and are unable to |
-// | obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Authors: Claudio Bustos <cdx@users.sourceforge.net> |
-// | Jens Bierkandt <schtorch@users.sourceforge.net> |
-// +----------------------------------------------------------------------+
-//
-// $Id:
-require_once "PHPUnit/Framework.php";
-if (file_exists('../Beautifier.php')) {
- include_once '../Beautifier.php';
-} else {
- include_once "PHP/Beautifier.php";
-}
-
-class BeautifierInternal_TestCase extends PHPUnit_Framework_TestCase {
- public $oBeaut;
- public $oFilter;
- function setUp()
- {
- $this->oBeaut = new PHP_Beautifier();
- $this->oFilter = new Test_Filter($this->oBeaut);
- $this->oBeaut->addFilter($this->oFilter);
- }
- function setText($sText)
- {
- $this->oBeaut->setInputString($sText);
- $this->oBeaut->process();
- }
- function testSetBeautify()
- {
- $sText = <<<SCRIPT
-<?php
-echo "sdsds";
-// php_beautifier->setBeautify(false);
-echo "don't process this token";
-// php_beautifier->on(true);
-
-?>
-SCRIPT;
- $this->setText($sText);
- // verify setBeautify
- $this->assertTrue(count($this->oFilter->aTokens) == 6);
- }
- function testModes()
- {
- $sText = <<<SCRIPT
-<?php
-\$a=(\$b>1)?'0':'2';
-\$b="asa{\$a}";
-?>
-SCRIPT;
- //php_beautifier->seatBeautify(true);
- $this->setText($sText);
- // ternary mode from ? to :
- $this->assertFalse($this->oFilter->aModes[7]['ternary_operator']);
- for ($x = 8;$x <= 10;$x++) {
- $this->assertTrue($this->oFilter->aModes[$x]['ternary_operator'], $x);
- }
- $this->assertFalse($this->oFilter->aModes[15]['double_quote']);
- // quote from " to } previous to "
- for ($x = 16;$x <= 20;$x++) {
- $this->assertTrue($this->oFilter->aModes[$x]['double_quote'], $x);
- }
- }
-
-}
-?>
View
55 tests/Beautifier_Pear.phpt
@@ -1,55 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-// +----------------------------------------------------------------------+
-// | PHP version 5 |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2004 The PHP Group |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 3.0 of the PHP license, |
-// | that is bundled with this package in the file LICENSE, and is |
-// | available through the world-wide-web at the following url: |
-// | http://www.php.net/license/3_0.txt. |
-// | If you did not receive a copy of the PHP license and are unable to |
-// | obtain it through the world-wide-web, please send a note to |
-// | license@php.net so we can mail you a copy immediately. |
-// +----------------------------------------------------------------------+
-// | Authors: Claudio Bustos <cdx@users.sourceforge.net> |
-// | Jens Bierkandt <schtorch@users.sourceforge.net> |
-// +----------------------------------------------------------------------+
-//
-// $Id:
-require_once "PHPUnit.php";
-if (file_exists('../Beautifier.php')) {
- include_once '../Beautifier.php';
-} else {
- include_once "PHP/Beautifier.php";
-}
-class Beautifier_Pear_TestCase extends PHPUnit_TestCase
-{
- function Beautifier_Pear($name)
- {
- $this->PHPUnit_TestCase($name);
- }
- function setUp()
- {
- $this->oBeaut = new PHP_Beautifier();
- }
- /**
- * Almost identical to original. The space after o before comment
- * is arbitrary, so I can't predict when I have to put a new line
- *
- */
- function testPearSample()
- {
- $sSample = dirname(__FILE__) . '/pear_sample_file.phps';
- $sContent = file_get_contents($sSample);
- $this->oBeaut->setInputFile($sSample);
- $this->oBeaut->addFilter("Pear");
- $this->oBeaut->process();
- $this->assertEquals($sContent, $this->oBeaut->get());
- }
-}
-$suite = new PHPUnit_TestSuite('Beautifier_Pear_TestCase');
-$result = PHPUnit::run($suite);
-echo $result->toString();
-?>
View
105 tests/Beautifier_StreamWrapper.phpt
@@ -1,105 +0,0 @@
-<?php
- /* vim: set expandtab tabstop=4 shiftwidth=4: */
- // +----------------------------------------------------------------------+
- // | PHP version 5 |
- // +----------------------------------------------------------------------+
- // | Copyright (c) 1997-2004 The PHP Group |
- // +----------------------------------------------------------------------+
- // | This source file is subject to version 3.0 of the PHP license, |
- // | that is bundled with this package in the file LICENSE, and is |
- // | available through the world-wide-web at the following url: |
- // | http://www.php.net/license/3_0.txt. |
- // | If you did not receive a copy of the PHP license and are unable to |
- // | obtain it through the world-wide-web, please send a note to |
- // | license@php.net so we can mail you a copy immediately. |
- // +----------------------------------------------------------------------+
- // | Authors: Claudio Bustos <cdx@users.sourceforge.net> |
- // | Jens Bierkandt <schtorch@users.sourceforge.net> |
- // +----------------------------------------------------------------------+
- //
- // $Id:
- require_once "PHPUnit.php";
- //require_once "PHP/Beautifier.php";
- if (file_exists('../Beautifier.php')) {
- include_once '../Beautifier.php';
- } else {
- include_once "PHP/Beautifier.php";
- }
- class Beautifier_StreamWrapper_Tarz extends PHPUnit_TestCase {
- var $sFile;
- var $sFileBz2;
- function Beautifier_StreamWrapper_Tarz($name) {
- $this->PHPUnit_TestCase($name);
- $this->sFile = dirname(__FILE__) ."/Beautifier.tar.gz";
- $this->sFileBz2 = dirname(__FILE__) ."/Beautifier.tar.bz2";
- }
- function setUp() {
- }
- function testopen() {
- $this->assertTrue(@fopen('tarz://'.$this->sFile."#Beautifier.php", 'r'));
- $this->assertfalse(@fopen('tarz://'.$this->sFile."#package2.xml", 'r'));
- }
- function testclose() {
- $fp = @fopen('tarz://'.$this->sFile."#Beautifier.php", 'r');
- $this->assertTrue(fclose($fp));
- }
- /**
- * In PHP5RcX, stream_feof was broken.
- * So, this function test use of feof, do loop (fread doc),
- * file_get_contents and file
- */
- function testread() {
- $oTar = new Archive_Tar($this->sFile, 'gz');
- $sExpected = $oTar->extractInString('Beautifier.php');
- unset($oTar);
- $sActual = '';
- $fp = @fopen('tarz://'.$this->sFile."#Beautifier.php", 'rb');
- $this->assertTrue($fp);
- if ($fp) {
- while (!feof($fp)) {
- $sBuffer = fread($fp, 8192);
- $sActual.= $sBuffer;
- }
- }
- $this->assertTrue($sExpected == $sActual, 'fread');
- $sActual = '';
- rewind($fp);
- do {
- $data = fread($fp, 8192);
- if (strlen($data) == 0) {
- break;
- }
- $sActual.= $data;
- }
- while (true);
- fclose($fp);
- $this->assertTrue($sExpected == $sActual, 'do');
- $sActual = file_get_contents('tarz://'.$this->sFile."#Beautifier.php");
- $this->assertTrue($sExpected == $sActual, 'file_get_contents');
- $sActual = implode("", file('tarz://'.$this->sFile."#Beautifier.php"));
- $this->assertTrue($sExpected == $sActual, 'file');
- }
- function testBz2() {
- $oTar = new Archive_Tar($this->sFileBz2, 'bz2');
- $sExpected = $oTar->extractInString('Beautifier.php');
- unset($oTar);
- $sActual = file_get_contents('tarz://'.$this->sFileBz2."#Beautifier.php");
- $this->assertTrue($sExpected == $sActual, 'file_get_contents');
- }
- function testOpenDir() {
- $this->assertTrue($oDir = opendir('tarz://'.$this->sFile));
- }
- function testReadDir() {
- if ($dh = opendir('tarz://'.$this->sFile)) {
- while (($file = readdir($dh)) !== false) {
- $this->assertTrue($fp = fopen('tarz://'.$this->sFile.'#'.$file, 'r'));
- $this->assertTrue(fclose($fp));
- }
- closedir($dh);
- }
- }
- }
- $suite = new PHPUnit_TestSuite('Beautifier_StreamWrapper_Tarz');
- $result = PHPUnit::run($suite);
- echo $result->toString();
-?>
View
8 tests/lista
@@ -1,8 +0,0 @@
-Beautifier.phpt
-Beautifier.tar.bz2
-Beautifier.tar.gz
-Beautifier_Bugs.phpt
-Beautifier_Common.phpt
-Beautifier_StreamWrapper.phpt
-lista
-log.txt
View
136 tests/log.txt
@@ -1,136 +0,0 @@
-Jun 17 03:18:34 php_beautifier [debug] Init process of string
-Jun 17 03:18:34 php_beautifier [debug] Token:T_OPEN_TAG[<?php\n]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_VARIABLE[$a]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[ ]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:[=]
-Jun 17 03:18:34 php_beautifier [debug] -space
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[ ]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_START_HEREDOC[<<<HEREDOC\n]
-Jun 17 03:18:34 php_beautifier [debug] Default Filter:unhandled[<<<HEREDOC
-]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_STRING[sdsdsds\n]
-Jun 17 03:18:34 php_beautifier [debug] Default Filter:unhandled[sdsdsds
-]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_END_HEREDOC[HEREDOC]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:[;]
-Jun 17 03:18:34 php_beautifier [debug] -space
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_CLOSE_TAG[?>]
-Jun 17 03:18:34 php_beautifier [debug] 8
-Jun 17 03:18:34 php_beautifier [debug] +space-token-without-sp:[]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] End process
-Jun 17 03:18:34 php_beautifier [debug] Init process of string
-Jun 17 03:18:34 php_beautifier [debug] Init process of string
-Jun 17 03:18:34 php_beautifier [debug] Token:T_OPEN_TAG[<?php\n]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_OPEN_TAG[<?php\n]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_IF[if]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_IF[if]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[ ]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[ ]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:[(]
-Jun 17 03:18:34 php_beautifier [debug] Token:[(]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_VARIABLE[$_POST]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_VARIABLE[$_POST]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:[[]
-Jun 17 03:18:34 php_beautifier [debug] Token:[[]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_CONSTANT_ENCAPSED_STRING["url"]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_CONSTANT_ENCAPSED_STRING["url"]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:[]]
-Jun 17 03:18:34 php_beautifier [debug] Token:[]]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[ ]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[ ]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_IS_NOT_EQUAL[!=]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_IS_NOT_EQUAL[!=]
-Jun 17 03:18:34 php_beautifier [debug] -space
-Jun 17 03:18:34 php_beautifier [debug] -space
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[ ]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[ ]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_CONSTANT_ENCAPSED_STRING[""]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_CONSTANT_ENCAPSED_STRING[""]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:[)]
-Jun 17 03:18:34 php_beautifier [debug] Token:[)]
-Jun 17 03:18:34 php_beautifier [debug] -space
-Jun 17 03:18:34 php_beautifier [debug] -space
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[ ]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[ ]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_COMMENT[//inserting data\n]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_COMMENT[//inserting data\n]
-Jun 17 03:18:34 php_beautifier [debug] -space
-Jun 17 03:18:34 php_beautifier [debug] -space
-Jun 17 03:18:34 php_beautifier [debug] 13
-Jun 17 03:18:34 php_beautifier [debug] 13
-Jun 17 03:18:34 php_beautifier [debug] 12
-Jun 17 03:18:34 php_beautifier [debug] 12
-Jun 17 03:18:34 php_beautifier [debug] +space-token-without-sp:[ ]
-Jun 17 03:18:34 php_beautifier [debug] +space-token-without-sp:[ ]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:[{]
-Jun 17 03:18:34 php_beautifier [debug] Token:[{]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[\n]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[\n]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:[}]
-Jun 17 03:18:34 php_beautifier [debug] Token:[}]
-Jun 17 03:18:34 php_beautifier [debug] -space
-Jun 17 03:18:34 php_beautifier [debug] -space
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[\n]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_WHITESPACE[\n]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Token:T_CLOSE_TAG[?>]
-Jun 17 03:18:34 php_beautifier [debug] Token:T_CLOSE_TAG[?>]
-Jun 17 03:18:34 php_beautifier [debug] -space
-Jun 17 03:18:34 php_beautifier [debug] -space
-Jun 17 03:18:34 php_beautifier [debug] 18
-Jun 17 03:18:34 php_beautifier [debug] 18
-Jun 17 03:18:34 php_beautifier [debug] 17
-Jun 17 03:18:34 php_beautifier [debug] 17
-Jun 17 03:18:34 php_beautifier [debug] +space-token-without-sp:[\n]
-Jun 17 03:18:34 php_beautifier [debug] +space-token-without-sp:[\n]
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] Filter:Default
-Jun 17 03:18:34 php_beautifier [debug] End process
-Jun 17 03:18:34 php_beautifier [debug] End process
View
241 tests/pear_sample_file.phps
@@ -1,241 +0,0 @@
-<?php
-
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * Short description for file
- *
- * Long description for file (if any)...
- *
- * PHP versions 4 and 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category CategoryName
- * @package PackageName
- * @author Original Author <author@example.com>
- * @author Another Author <another@example.com>
- * @copyright 1997-2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id:$
- * @link http://pear.php.net/package/PackageName
- * @see NetOther, Net_Sample::Net_Sample()
- * @since File available since Release 1.2.0
- * @deprecated File deprecated in Release 2.0.0
- */
-
-/**
- * This is a "Docblock Comment," also known as a "docblock." The class'
- * docblock, below, contains a complete description of how to write these.
- */
-require_once 'PEAR.php';
-
-// {{{ constants
-
-/**
- * Methods return this if they succeed
- */
-define('NET_SAMPLE_OK', 1);
-
-// }}}
-// {{{ GLOBALS
-
-/**
- * The number of objects created
- * @global int $GLOBALS['NET_SAMPLE_Count']
- */
-$GLOBALS['NET_SAMPLE_Count'] = 0;
-
-// }}}
-// {{{ Net_Sample
-
-/**
- * An example of how to write code to PEAR's standards
- *
- * Docblock comments start with "/**" at the top. Notice how the "/"
- * lines up with the normal indenting and the asterisks on subsequent rows
- * are in line with the first asterisk. The last line of comment text
- * should be immediately followed on the next line by the closing asterisk
- * and slash and then the item you are commenting on should be on the next
- * line below that. Don't add extra lines. Please put a blank line
- * between paragraphs as well as between the end of the description and
- * the start of the @tags. Wrap comments before 80 columns in order to
- * ease readability for a wide variety of users.
- *
- * Docblocks can only be used for programming constructs which allow them
- * (classes, properties, methods, defines, includes, globals). See the
- * phpDocumentor documentation for more information.
- * http://phpdoc.org/docs/HTMLSmartyConverter/default/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html
- *
- * The Javadoc Style Guide is an excellent resource for figuring out
- * how to say what needs to be said in docblock comments. Much of what is
- * written here is a summary of what is found there, though there are some
- * cases where what's said here overrides what is said there.
- * http://java.sun.com/j2se/javadoc/writingdoccomments/index.html#styleguide
- *
- * The first line of any docblock is the summary. Make them one short
- * sentence, without a period at the end. Summaries for classes, properties
- * and constants should omit the subject and simply state the object,
- * because they are describing things rather than actions or behaviors.
- *
- * Below are the tags commonly used for classes. @category through @access
- * are required. The remainder should only be used when necessary.
- * Please use them in the order they appear here. phpDocumentor has
- * several other tags available, feel free to use them.
- *
- * @category CategoryName
- * @package PackageName
- * @author Original Author <author@example.com>
- * @author Another Author <another@example.com>
- * @copyright 1997-2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: @package_version@
- * @link http://pear.php.net/package/PackageName
- * @see NetOther, Net_Sample::Net_Sample()
- * @since Class available since Release 1.2.0
- * @deprecated Class deprecated in Release 2.0.0
- */
-class Net_Sample
-{
- // {{{ properties
-
- /**
- * The status of foo's universe
- *
- * Potential values are 'good', 'fair', 'poor' and 'unknown'.
- *
- * @var string
- */
- var $foo = 'unknown';
-
- /**
- * The status of life
- *
- * Note that names of private properties or methods must be
- * preceeded by an underscore.
- *
- * @var bool
- * @access private
- */
- var $_good = true;
-
- // }}}
- // {{{ setFoo()
-
- /**
- * Registers the status of foo's universe
- *
- * Summaries for methods should use 3rd person declarative rather
- * than 2nd person imperative, begining with a verb phrase.
- *
- * Summaries should add description beyond the method's name. The
- * best method names are "self-documenting", meaning they tell you
- * basically what the method does. If the summary merely repeats
- * the method name in sentence form, it is not providing more
- * information.
- *
- * Summary Examples:
- * + Sets the label (preferred)
- * + Set the label (avoid)
- * + This method sets the label (avoid)
- *
- * Below are the tags commonly used for methods. A @param tag is
- * required for each parameter the method has. The @return and
- * @access tags are mandatory. The @throws tag is required if the
- * method uses exceptions. @static is required if the method can
- * be called statically. The remainder should only be used when
- * necessary. Please use them in the order they appear here.
- * phpDocumentor has several other tags available, feel free to use
- * them.
- *
- * The @param tag contains the data type, then the parameter's
- * name, followed by a description. By convention, the first noun in
- * the description is the data type of the parameter. Articles like
- * "a", "an", and "the" can precede the noun. The descriptions
- * should start with a phrase. If further description is necessary,
- * follow with sentences. Having two spaces between the name and the
- * description aids readability.
- *
- * When writing a phrase, do not capitalize and do not end with a
- * period:
- * + the string to be tested
- *
- * When writing a phrase followed by a sentence, do not capitalize the
- * phrase, but end it with a period to distinguish it from the start
- * of the next sentence:
- * + the string to be tested. Must use UTF-8 encoding.
- *
- * Return tags should contain the data type then a description of
- * the data returned. The data type can be any of PHP's data types
- * (int, float, bool, string, array, object, resource, mixed)
- * and should contain the type primarily returned. For example, if
- * a method returns an object when things work correctly but false
- * when an error happens, say 'object' rather than 'mixed.' Use
- * 'void' if nothing is returned.
- *
- * Here's an example of how to format examples:
- * <code>
- * require_once 'Net/Sample.php';
- *
- * $s = new Net_Sample();
- * if (PEAR::isError($s)) {
- * echo $s->getMessage() . "\n";
- * }
- * </code>
- *
- * Here is an example for non-php example or sample:
- * <samp>
- * pear install net_sample
- * </samp>
- *
- * @param string $arg1 the string to quote
- * @param int $arg2 an integer of how many problems happened.
- * Indent to the description's starting point
- * for long ones.
- *
- * @return int the integer of the set mode used. FALSE if foo
- * foo could not be set.
- * @throws exceptionclass [description]
- *
- * @access public
- * @static
- * @see Net_Sample::$foo, Net_Other::someMethod()
- * @since Method available since Release 1.2.0
- * @deprecated Method deprecated in Release 2.0.0
- */
- function setFoo($arg1, $arg2 = 0)
- {
- /*
- * This is a "Block Comment." The format is the same as
- * Docblock Comments except there is only one asterisk at the
- * top. phpDocumentor doesn't parse these.
- */
- if ($arg1 == 'good' || $arg1 == 'fair') {
- $this->foo = $arg1;
- return 1;
- } elseif ($arg1 == 'poor' && $arg2 > 1) {
- $this->foo = 'poor';
- return 2;
- } else {
- return false;
- }
- }
-
- // }}}
-}
-
-// }}}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * c-hanging-comment-ender-p: nil
- * End:
- */
-
-?>
Please sign in to comment.
Something went wrong with that request. Please try again.