update v 1.0.7.5

This commit is contained in:
Sujit Prasad
2016-06-13 20:41:55 +05:30
parent aa9786d829
commit 283d97e3ea
5078 changed files with 339851 additions and 175995 deletions

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,7 +11,7 @@
namespace Psy\Test\CodeCleaner;
use PHPParser_NodeTraverser as NodeTraverser;
use PhpParser\NodeTraverser;
use Psy\CodeCleaner\AbstractClassPass;
class AbstractClassPassTest extends CodeCleanerTestCase

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,7 +11,7 @@
namespace Psy\Test\CodeCleaner;
use PHPParser_NodeTraverser as NodeTraverser;
use PhpParser\NodeTraverser;
use Psy\CodeCleaner\AssignThisVariablePass;
class AssignThisVariablePassTest extends CodeCleanerTestCase

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,7 +11,7 @@
namespace Psy\Test\CodeCleaner;
use PHPParser_NodeTraverser as NodeTraverser;
use PhpParser\NodeTraverser;
use Psy\CodeCleaner\CallTimePassByReferencePass;
class CallTimePassByReferencePassTest extends CodeCleanerTestCase

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,7 +11,7 @@
namespace Psy\Test\CodeCleaner;
use PHPParser_NodeTraverser as NodeTraverser;
use PhpParser\NodeTraverser;
use Psy\CodeCleaner\CalledClassPass;
class CalledClassPassTest extends CodeCleanerTestCase

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,12 +11,12 @@
namespace Psy\Test\CodeCleaner;
use PHPParser_Lexer as Lexer;
use PHPParser_NodeTraverser as NodeTraverser;
use PHPParser_Parser as Parser;
use PHPParser_PrettyPrinter_Default as Printer;
use PhpParser\NodeTraverser;
use PhpParser\Parser;
use PhpParser\PrettyPrinter\Standard as Printer;
use Psy\CodeCleaner\CodeCleanerPass;
use Psy\Exception\ParseErrorException;
use Psy\ParserFactory;
class CodeCleanerTestCase extends \PHPUnit_Framework_TestCase
{
@@ -39,7 +39,7 @@ class CodeCleanerTestCase extends \PHPUnit_Framework_TestCase
$code = $prefix . $code;
try {
return $this->getParser()->parse($code);
} catch (\PHPParser_Error $e) {
} catch (\PhpParser\Error $e) {
if (!$this->parseErrorIsEOF($e)) {
throw ParseErrorException::fromParseError($e);
}
@@ -47,7 +47,7 @@ class CodeCleanerTestCase extends \PHPUnit_Framework_TestCase
try {
// Unexpected EOF, try again with an implicit semicolon
return $this->getParser()->parse($code . ';');
} catch (\PHPParser_Error $e) {
} catch (\PhpParser\Error $e) {
return false;
}
}
@@ -73,7 +73,8 @@ class CodeCleanerTestCase extends \PHPUnit_Framework_TestCase
private function getParser()
{
if (!isset($this->parser)) {
$this->parser = new Parser(new Lexer());
$parserFactory = new ParserFactory();
$this->parser = $parserFactory->createParser();
}
return $this->parser;
@@ -88,10 +89,10 @@ class CodeCleanerTestCase extends \PHPUnit_Framework_TestCase
return $this->printer;
}
private function parseErrorIsEOF(\PHPParser_Error $e)
private function parseErrorIsEOF(\PhpParser\Error $e)
{
$msg = $e->getRawMessage();
return ($msg === "Unexpected token EOF") || (strpos($msg, "Syntax error, unexpected EOF") !== false);
return ($msg === 'Unexpected token EOF') || (strpos($msg, 'Syntax error, unexpected EOF') !== false);
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*
* This file is part of Psy Shell.
*
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Psy\Test\CodeCleaner;
use Psy\CodeCleaner\ExitPass;
class ExitPassTest extends CodeCleanerTestCase
{
/**
* @var string
*/
private $expectedExceptionString = "throw new Psy\\Exception\\BreakException('Goodbye.');";
public function setUp()
{
$this->setPass(new ExitPass());
}
/**
* @dataProvider dataProviderExitStatement
*/
public function testExitStatement($from, $to)
{
$this->assertProcessesAs($from, $to);
}
/**
* Data provider for testExitStatement.
*
* @return array
*/
public function dataProviderExitStatement()
{
return array(
array('exit;', $this->expectedExceptionString),
array('exit();', $this->expectedExceptionString),
array('die;', $this->expectedExceptionString),
array('if (true) { exit; }', "if (true) {\n $this->expectedExceptionString\n}"),
array('if (false) { exit; }', "if (false) {\n $this->expectedExceptionString\n}"),
);
}
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,7 +11,7 @@
namespace Psy\Test\CodeCleaner;
use PHPParser_NodeTraverser as NodeTraverser;
use PhpParser\NodeTraverser;
use Psy\CodeCleaner\FunctionReturnInWriteContextPass;
use Psy\Exception\FatalErrorException;
@@ -53,7 +53,10 @@ class FunctionReturnInWriteContextPassTest extends CodeCleanerTestCase
$this->fail();
} catch (FatalErrorException $e) {
if (version_compare(PHP_VERSION, '5.5', '>=')) {
$this->assertContains('Cannot use isset() on the result of a function call (you can use "null !== func()" instead)', $e->getMessage());
$this->assertContains(
'Cannot use isset() on the result of a function call (you can use "null !== func()" instead)',
$e->getMessage()
);
} else {
$this->assertContains("Can't use function return value in write context", $e->getMessage());
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -33,6 +33,7 @@ class ImplicitReturnPassTest extends CodeCleanerTestCase
return array(
array('4', 'return 4;'),
array('foo()', 'return foo();'),
array('exit()', 'die;'),
);
}
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -33,7 +33,7 @@ class MagicConstantsPassTest extends CodeCleanerTestCase
return array(
array('__DIR__;', 'getcwd();'),
array('__FILE__;', "'';"),
array('___FILE___;', "___FILE___;"),
array('___FILE___;', '___FILE___;'),
);
}
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -0,0 +1,53 @@
<?php
/*
* This file is part of Psy Shell.
*
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Psy\Test\CodeCleaner;
use Psy\CodeCleaner\StrictTypesPass;
class StrictTypesPassTest extends CodeCleanerTestCase
{
public function setUp()
{
if (version_compare(PHP_VERSION, '7.0', '<')) {
$this->markTestSkipped();
}
$this->setPass(new StrictTypesPass());
}
public function testProcess()
{
$this->assertProcessesAs('declare(strict_types=1)', 'declare (strict_types=1);');
$this->assertProcessesAs('null', "declare (strict_types=1);\nnull;");
$this->assertProcessesAs('declare(strict_types=0)', 'declare (strict_types=0);');
$this->assertProcessesAs('null', 'null;');
}
/**
* @dataProvider invalidDeclarations
* @expectedException \Psy\Exception\FatalErrorException
*/
public function testInvalidDeclarations($declaration)
{
$stmts = $this->parse($declaration);
$this->traverser->traverse($stmts);
}
public function invalidDeclarations()
{
return array(
array('declare(strict_types=-1)'),
array('declare(strict_types=2)'),
array('declare(strict_types="foo")'),
);
}
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -33,7 +33,7 @@ class UseStatementPassTest extends CodeCleanerTestCase
return array(
array(
"use StdClass as NotSoStd;\n\$std = new NotSoStd();",
"\$std = new \\StdClass();",
'$std = new \\StdClass();',
),
array(
"namespace Foo;\n\nuse StdClass as S;\n\$std = new S();",
@@ -45,7 +45,7 @@ class UseStatementPassTest extends CodeCleanerTestCase
),
array(
"use Foo\\Bar as fb;\n\$baz = new fb\\Baz();",
"\$baz = new \\Foo\\Bar\\Baz();",
'$baz = new \\Foo\\Bar\\Baz();',
),
);
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -53,49 +53,49 @@ class ValidClassNamePassTest extends CodeCleanerTestCase
array('trait stdClass {}', true),
// collisions inside the same code snippet
array("
array('
class Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
class Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
"),
array("
'),
array('
class Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
trait Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
", true),
array("
', true),
array('
trait Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
class Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
", true),
array("
', true),
array('
trait Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
interface Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
", true),
array("
', true),
array('
interface Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
trait Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
", true),
array("
', true),
array('
interface Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
class Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
"),
array("
'),
array('
class Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
interface Psy_Test_CodeCleaner_ValidClassNamePass_Alpha {}
"),
'),
// namespaced collisions
array("
array('
namespace Psy\\Test\\CodeCleaner {
class ValidClassNamePassTest {}
}
"),
array("
'),
array('
namespace Psy\\Test\\CodeCleaner\\ValidClassNamePass {
class Beta {}
}
namespace Psy\\Test\\CodeCleaner\\ValidClassNamePass {
class Beta {}
}
"),
'),
// extends and implements
array('class ValidClassNamePassTest extends NotAClass {}'),
@@ -107,11 +107,11 @@ class ValidClassNamePassTest extends CodeCleanerTestCase
// class instantiations
array('new Psy_Test_CodeCleaner_ValidClassNamePass_Gamma();'),
array("
array('
namespace Psy\\Test\\CodeCleaner\\ValidClassNamePass {
new Psy_Test_CodeCleaner_ValidClassNamePass_Delta();
}
"),
'),
// class constant fetch
array('Psy\\Test\\CodeCleaner\\ValidClassNamePass\\NotAClass::FOO'),
@@ -133,53 +133,147 @@ class ValidClassNamePassTest extends CodeCleanerTestCase
public function getValid()
{
return array(
$valid = array(
// class declarations
array('class Psy_Test_CodeCleaner_ValidClassNamePass_Epsilon {}'),
array('namespace Psy\Test\CodeCleaner\ValidClassNamePass; class Zeta {}'),
array("
array('
namespace { class Psy_Test_CodeCleaner_ValidClassNamePass_Eta {}; }
namespace Psy\\Test\\CodeCleaner\\ValidClassNamePass {
class Psy_Test_CodeCleaner_ValidClassNamePass_Eta {}
}
"),
'),
array('namespace Psy\Test\CodeCleaner\ValidClassNamePass { class stdClass {} }'),
// class instantiations
array('new stdClass();'),
array('new stdClass();'),
array("
array('
namespace Psy\\Test\\CodeCleaner\\ValidClassNamePass {
class Theta {}
}
namespace Psy\\Test\\CodeCleaner\\ValidClassNamePass {
new Theta();
}
"),
array("
'),
array('
namespace Psy\\Test\\CodeCleaner\\ValidClassNamePass {
class Iota {}
new Iota();
}
"),
array("
'),
array('
namespace Psy\\Test\\CodeCleaner\\ValidClassNamePass {
class Kappa {}
}
namespace {
new \\Psy\\Test\\CodeCleaner\\ValidClassNamePass\\Kappa();
}
"),
'),
// Class constant fetch (ValidConstantPassTest validates the actual constant)
array('class A {} A::FOO'),
array('$a = new DateTime; $a::ATOM'),
array('interface A { const B = 1; } A::B'),
// static call
array('DateTime::createFromFormat()'),
array('DateTime::$someMethod()'),
array('Psy\Test\CodeCleaner\Fixtures\ClassWithStatic::doStuff()'),
array('Psy\Test\CodeCleaner\Fixtures\ClassWithCallStatic::doStuff()'),
// Allow `self` and `static` as class names.
array('
class Psy_Test_CodeCleaner_ValidClassNamePass_ClassWithStatic {
public static function getInstance() {
return new self();
}
}
'),
array('
class Psy_Test_CodeCleaner_ValidClassNamePass_ClassWithStatic {
public static function getInstance() {
return new SELF();
}
}
'),
array('
class Psy_Test_CodeCleaner_ValidClassNamePass_ClassWithStatic {
public static function getInstance() {
return new self;
}
}
'),
array('
class Psy_Test_CodeCleaner_ValidClassNamePass_ClassWithStatic {
public static function getInstance() {
return new static();
}
}
'),
array('
class Psy_Test_CodeCleaner_ValidClassNamePass_ClassWithStatic {
public static function getInstance() {
return new Static();
}
}
'),
array('
class Psy_Test_CodeCleaner_ValidClassNamePass_ClassWithStatic {
public static function getInstance() {
return new static;
}
}
'),
array('
class Psy_Test_CodeCleaner_ValidClassNamePass_ClassWithStatic {
public static function foo() {
return parent::bar();
}
}
'),
array('
class Psy_Test_CodeCleaner_ValidClassNamePass_ClassWithStatic {
public static function foo() {
return self::bar();
}
}
'),
array('
class Psy_Test_CodeCleaner_ValidClassNamePass_ClassWithStatic {
public static function foo() {
return static::bar();
}
}
'),
array('class A { static function b() { return new A; } }'),
array('
class A {
const B = 123;
function c() {
return A::B;
}
}
'),
array('class A {} class B { function c() { return new A; } }'),
);
// Ugh. There's gotta be a better way to test for this.
if (class_exists('PhpParser\ParserFactory')) {
// PHP 7.0 anonymous classes, only supported by PHP Parser v2.x
$valid[] = array('$obj = new class() {}');
}
if (version_compare(PHP_VERSION, '5.5', '>=')) {
$valid[] = array('interface A {} A::class');
$valid[] = array('interface A {} A::CLASS');
$valid[] = array('class A {} A::class');
$valid[] = array('class A {} A::CLASS');
$valid[] = array('A::class');
$valid[] = array('A::CLASS');
}
return $valid;
}
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -59,6 +59,8 @@ class ValidConstantPassTest extends CodeCleanerTestCase
array('NotAClass::FOO'),
array('DateTime::ATOM'),
array('$a = new DateTime; $a::ATOM'),
array('DateTime::class'),
array('$a = new DateTime; $a::class'),
);
}
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -36,26 +36,29 @@ class ValidFunctionNamePassTest extends CodeCleanerTestCase
// function declarations
array('function array_merge() {}'),
array('function Array_Merge() {}'),
array("
array('
function psy_test_codecleaner_validfunctionnamepass_alpha() {}
function psy_test_codecleaner_validfunctionnamepass_alpha() {}
"),
array("
'),
array('
namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
function beta() {}
}
namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
function beta() {}
}
"),
'),
// function calls
array('psy_test_codecleaner_validfunctionnamepass_gamma()'),
array("
array('
namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
delta();
}
"),
'),
// recursion
array('function a() { a(); } function a() {}'),
);
}
@@ -72,53 +75,56 @@ class ValidFunctionNamePassTest extends CodeCleanerTestCase
{
return array(
array('function psy_test_codecleaner_validfunctionnamepass_epsilon() {}'),
array("
array('
namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
function zeta() {}
}
"),
array("
'),
array('
namespace {
function psy_test_codecleaner_validfunctionnamepass_eta() {}
}
namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
function psy_test_codecleaner_validfunctionnamepass_eta() {}
}
"),
array("
'),
array('
namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
function psy_test_codecleaner_validfunctionnamepass_eta() {}
}
namespace {
function psy_test_codecleaner_validfunctionnamepass_eta() {}
}
"),
array("
'),
array('
namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
function array_merge() {}
}
"),
'),
// function calls
array('array_merge();'),
array("
array('
namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
function theta() {}
}
namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
theta();
}
"),
'),
// closures
array('$test = function(){};$test()'),
array("
array('
namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
function theta() {}
}
namespace {
Psy\\Test\\CodeCleaner\\ValidFunctionNamePass\\theta();
}
"),
'),
// recursion
array('function a() { a(); }'),
);
}
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -16,7 +16,7 @@ use Psy\CodeCleaner;
class CodeCleanerTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider codeProvider
* @dataProvider semicolonCodeProvider
*/
public function testAutomaticSemicolons(array $lines, $requireSemicolons, $expected)
{
@@ -24,7 +24,7 @@ class CodeCleanerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected, $cc->clean($lines, $requireSemicolons));
}
public function codeProvider()
public function semicolonCodeProvider()
{
return array(
array(array('true'), false, 'return true;'),
@@ -33,7 +33,63 @@ class CodeCleanerTest extends \PHPUnit_Framework_TestCase
array(array('true'), true, false),
array(array('echo "foo";', 'true'), false, "echo 'foo';\nreturn true;"),
array(array('echo "foo";', 'true'), true , false),
array(array('echo "foo";', 'true'), true, false),
);
}
/**
* @dataProvider unclosedStatementsProvider
*/
public function testUnclosedStatements(array $lines, $isUnclosed)
{
$cc = new CodeCleaner();
$res = $cc->clean($lines);
if ($isUnclosed) {
$this->assertFalse($res);
} else {
$this->assertNotFalse($res);
}
}
public function unclosedStatementsProvider()
{
return array(
array(array('echo "'), true),
array(array('echo \''), true),
array(array('if (1) {'), true),
array(array('echo ""'), false),
array(array("echo ''"), false),
array(array('if (1) {}'), false),
array(array("\$content = <<<EOS\n"), true),
array(array("\$content = <<<'EOS'\n"), true),
);
}
/**
* @dataProvider invalidStatementsProvider
* @expectedException Psy\Exception\ParseErrorException
*/
public function testInvalidStatementsThrowParseErrors($code)
{
$cc = new CodeCleaner();
$cc->clean(array($code));
}
public function invalidStatementsProvider()
{
return array(
array('function "what'),
array("function 'what"),
array('echo }'),
array('echo {'),
array('if (1) }'),
array('echo """'),
array("echo '''"),
array('$foo "bar'),
array('$foo \'bar'),
);
}
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -28,6 +28,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(function_exists('pcntl_signal'), $config->hasPcntl());
$this->assertEquals(function_exists('pcntl_signal'), $config->usePcntl());
$this->assertFalse($config->requireSemicolons());
$this->assertSame(Configuration::COLOR_MODE_AUTO, $config->colorMode());
}
public function testGettersAndSetters()
@@ -99,6 +100,8 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
'pager' => $pager,
'loop' => $loop,
'requireSemicolons' => true,
'errorLoggingLevel' => E_ERROR | E_WARNING,
'colorMode' => Configuration::COLOR_MODE_FORCED,
));
$this->assertFalse($config->useReadline());
@@ -107,6 +110,8 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
$this->assertSame($pager, $config->getPager());
$this->assertSame($loop, $config->getLoop());
$this->assertTrue($config->requireSemicolons());
$this->assertEquals(E_ERROR | E_WARNING, $config->errorLoggingLevel());
$this->assertSame(Configuration::COLOR_MODE_FORCED, $config->colorMode());
}
public function testLoadConfigFile()
@@ -117,38 +122,35 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
$this->assertStringStartsWith($runtimeDir, realpath($config->getTempFile('foo', 123)));
$this->assertStringStartsWith($runtimeDir, realpath(dirname($config->getPipe('pipe', 123))));
// This will be deprecated, but we want to actually test the value.
$was = error_reporting(error_reporting() & ~E_USER_DEPRECATED);
$this->assertStringStartsWith($runtimeDir, realpath($config->getTempDir()));
error_reporting($was);
$this->assertStringStartsWith($runtimeDir, realpath($config->getRuntimeDir()));
$this->assertEquals(function_exists('readline'), $config->useReadline());
$this->assertFalse($config->usePcntl());
$this->assertEquals(E_ALL & ~E_NOTICE, $config->errorLoggingLevel());
}
/**
* @expectedException PHPUnit_Framework_Error_Deprecated
*/
public function testSetTempDirIsDeprecated()
public function testLoadLocalConfigFile()
{
$oldPwd = getenv('PWD');
putenv('PWD=' . realpath(__DIR__ . '/../../fixtures/project/'));
$config = new Configuration();
$config->setTempDir('fake');
// When no configuration file is specified local project config is merged
$this->assertFalse($config->useReadline());
$this->assertTrue($config->usePcntl());
$config = new Configuration(array('configFile' => __DIR__ . '/../../fixtures/config.php'));
// Defining a configuration file skips loading local project config
$this->assertTrue($config->useReadline());
$this->assertFalse($config->usePcntl());
putenv("PWD=$oldPwd");
}
/**
* @expectedException PHPUnit_Framework_Error_Deprecated
*/
public function testGetTempDirIsDeprecated()
{
$config = new Configuration();
$config->getTempDir();
}
/**
* @expectedException PHPUnit_Framework_Error_Deprecated
* @expectedException Psy\Exception\DeprecatedException
*/
public function testBaseDirConfigIsDeprecated()
{
@@ -171,4 +173,69 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
$this->assertCount(1, $includes);
$this->assertEquals('/file.php', $includes[0]);
}
public function testGetOutput()
{
$config = new Configuration();
$output = $config->getOutput();
$this->assertInstanceOf('\Psy\Output\ShellOutput', $output);
}
public function getOutputDecoratedProvider()
{
return array(
'auto' => array(
null,
Configuration::COLOR_MODE_AUTO,
),
'forced' => array(
true,
Configuration::COLOR_MODE_FORCED,
),
'disabled' => array(
false,
Configuration::COLOR_MODE_DISABLED,
),
);
}
/** @dataProvider getOutputDecoratedProvider */
public function testGetOutputDecorated($expectation, $colorMode)
{
$config = new Configuration();
$config->setColorMode($colorMode);
$this->assertSame($expectation, $config->getOutputDecorated());
}
public function setColorModeValidProvider()
{
return array(
'auto' => array(Configuration::COLOR_MODE_AUTO),
'forced' => array(Configuration::COLOR_MODE_FORCED),
'disabled' => array(Configuration::COLOR_MODE_DISABLED),
);
}
/** @dataProvider setColorModeValidProvider */
public function testSetColorModeValid($colorMode)
{
$config = new Configuration();
$config->setColorMode($colorMode);
$this->assertEquals($colorMode, $config->colorMode());
}
public function testSetColorModeInvalid()
{
$config = new Configuration();
$colorMode = 'some invalid mode';
$this->setExpectedException(
'\InvalidArgumentException',
'invalid color mode: some invalid mode'
);
$config->setColorMode($colorMode);
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*
* This file is part of Psy Shell.
*
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Psy\Test;
use Psy\Configuration;
use Psy\ConsoleColorFactory;
class ConsoleColorFactoryTest extends \PHPUnit_Framework_TestCase
{
public function testGetConsoleColorAuto()
{
$colorMode = Configuration::COLOR_MODE_AUTO;
$factory = new ConsoleColorFactory($colorMode);
$colors = $factory->getConsoleColor();
$themes = $colors->getThemes();
$this->assertFalse($colors->isStyleForced());
$this->assertEquals(array('blue'), $themes['line_number']);
}
public function testGetConsoleColorForced()
{
$colorMode = Configuration::COLOR_MODE_FORCED;
$factory = new ConsoleColorFactory($colorMode);
$colors = $factory->getConsoleColor();
$themes = $colors->getThemes();
$this->assertTrue($colors->isStyleForced());
$this->assertEquals(array('blue'), $themes['line_number']);
}
public function testGetConsoleColorDisabled()
{
$colorMode = Configuration::COLOR_MODE_DISABLED;
$factory = new ConsoleColorFactory($colorMode);
$colors = $factory->getConsoleColor();
$themes = $colors->getThemes();
$this->assertFalse($colors->isStyleForced());
$this->assertEquals(array('none'), $themes['line_number']);
}
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -21,7 +21,7 @@ class ParseErrorExceptionTest extends \PHPUnit_Framework_TestCase
$e = new ParseErrorException();
$this->assertTrue($e instanceof Exception);
$this->assertTrue($e instanceof \PHPParser_Error);
$this->assertTrue($e instanceof \PhpParser\Error);
$this->assertTrue($e instanceof ParseErrorException);
}
@@ -35,7 +35,7 @@ class ParseErrorExceptionTest extends \PHPUnit_Framework_TestCase
public function testConstructFromParseError()
{
$e = ParseErrorException::fromParseError(new \PHPParser_Error('{msg}'));
$e = ParseErrorException::fromParseError(new \PhpParser\Error('{msg}'));
$this->assertContains('{msg}', $e->getRawMessage());
$this->assertContains('PHP Parse error:', $e->getMessage());

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -17,15 +17,15 @@ class CodeFormatterTest extends \PHPUnit_Framework_TestCase
{
private function ignoreThisMethod($arg)
{
echo "whot!";
echo 'whot!';
}
public function testFormat()
{
$expected = <<<EOS
> 18| private function ignoreThisMethod(\$arg)
$expected = <<<'EOS'
> 18| private function ignoreThisMethod($arg)
19| {
20| echo "whot!";
20| echo 'whot!';
21| }
EOS;

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -33,7 +33,7 @@ class DocblockFormatterTest extends \PHPUnit_Framework_TestCase
throw new \InvalidArgumentException();
}
return "method called";
return 'method called';
}
public function testFormat()

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -29,10 +29,6 @@ class SignatureFormatterTest extends \PHPUnit_Framework_TestCase
public function testFormat($reflector, $expected)
{
$this->assertEquals($expected, strip_tags(SignatureFormatter::format($reflector)));
// $this->assertEquals(
// ,
// strip_tags(SignatureFormatter::format(new \ReflectionFunction('sort')))
// );
}
public function signatureReflectors()
@@ -41,13 +37,13 @@ class SignatureFormatterTest extends \PHPUnit_Framework_TestCase
array(
new \ReflectionClass($this),
"class Psy\Test\Formatter\SignatureFormatterTest "
. "extends PHPUnit_Framework_TestCase implements "
. "PHPUnit_Framework_SelfDescribing, Countable, "
. "PHPUnit_Framework_Test",
. 'extends PHPUnit_Framework_TestCase implements '
. 'Countable, PHPUnit_Framework_SelfDescribing, '
. 'PHPUnit_Framework_Test',
),
array(
new \ReflectionFunction('implode'),
'function implode($glue, $pieces)',
defined('HHVM_VERSION') ? 'function implode($arg1, $arg2 = null)' : 'function implode($glue, $pieces)',
),
array(
new ReflectionConstant($this, 'FOO'),
@@ -63,7 +59,9 @@ class SignatureFormatterTest extends \PHPUnit_Framework_TestCase
),
array(
new \ReflectionClass('Psy\CodeCleaner\CodeCleanerPass'),
'abstract class Psy\CodeCleaner\CodeCleanerPass extends PhpParser\NodeVisitorAbstract implements PhpParser\NodeVisitor',
'abstract class Psy\CodeCleaner\CodeCleanerPass '
. 'extends PhpParser\NodeVisitorAbstract '
. 'implements PhpParser\NodeVisitor',
),
);
}

View File

@@ -1,127 +0,0 @@
<?php
/*
* This file is part of Psy Shell
*
* (c) 2012-2014 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Psy\Test\Presenter;
use Psy\Presenter\ArrayPresenter;
use Psy\Presenter\ObjectPresenter;
use Psy\Presenter\PresenterManager;
use Psy\Presenter\ScalarPresenter;
class ArrayPresenterTest extends \PHPUnit_Framework_TestCase
{
private $presenter;
private $manager;
public function setUp()
{
$this->presenter = new ArrayPresenter();
$this->manager = new PresenterManager();
$this->manager->addPresenter(new ScalarPresenter());
$this->manager->addPresenter(new ObjectPresenter());
$this->manager->addPresenter($this->presenter);
}
/**
* @dataProvider presentData
*/
public function testPresent($array, $expect)
{
$this->assertEquals($expect, self::strip($this->presenter->present($array)));
}
public function presentData()
{
return array(
array(array(), '[]'),
array(array(1), '[<number>1</number>]'),
array(array(2, "string"), '[<number>2</number>,<string>"string"</string>]'),
array(array('a' => 1, 'b' => 2), '[<string>"a"</string>=><number>1</number>,<string>"b"</string>=><number>2</number>]'),
);
}
/**
* @dataProvider presentRefData
*/
public function testPresentRef($array, $expect)
{
$this->assertEquals($expect, $this->presenter->presentRef($array));
}
public function presentRefData()
{
return array(
array(array(), '[]'),
array(array(1), 'Array(<number>1</number>)'),
array(array(1, 2), 'Array(<number>2</number>)'),
array(array(1, 2, 3), 'Array(<number>3</number>)'),
);
}
/**
* @dataProvider presentArrayObjectsData
*/
public function testPresentArrayObjects($arrayObj, $expect, $expectRef)
{
$this->assertEquals($expect, $this->presenter->present($arrayObj));
$this->assertEquals($expectRef, $this->presenter->presentRef($arrayObj));
}
public function presentArrayObjectsData()
{
$obj1 = new \ArrayObject(array(1, "string"));
$hash1 = spl_object_hash($obj1);
$ref1 = '<object>\\<<class>ArrayObject</class> <strong>#' . $hash1 . '</strong>></object>';
$expect1 = <<<EOS
$ref1 [
<number>1</number>,
<string>"string"</string>
]
EOS;
$obj2 = new FakeArrayObject(array('a' => 'AAA', 'b' => 'BBB'));
$hash2 = spl_object_hash($obj2);
$ref2 = '<object>\\<<class>Psy\\Test\\Presenter\\FakeArrayObject</class> <strong>#' . $hash2 . '</strong>></object>';
$expect2 = <<<EOS
$ref2 [
<string>"a"</string> => <string>"AAA"</string>,
<string>"b"</string> => <string>"BBB"</string>
]
EOS;
return array(
array($obj1, $expect1, $ref1),
array($obj2, $expect2, $ref2),
);
}
public function testPresentsRecursively()
{
$obj = new \StdClass();
$array = array(1, $obj, "a");
$hash = spl_object_hash($obj);
$expected = <<<EOS
[
<number>1</number>,
<object>\<<class>stdClass</class> <strong>#$hash</strong>></object> {},
<string>"a"</string>
]
EOS;
$this->assertEquals($expected, $this->presenter->present($array));
}
private static function strip($text)
{
return preg_replace('/\\s/', '', $text);
}
}

View File

@@ -1,88 +0,0 @@
<?php
/*
* This file is part of Psy Shell
*
* (c) 2012-2014 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Psy\Test\Presenter;
use Psy\Presenter\ClosurePresenter;
use Psy\Presenter\ObjectPresenter;
use Psy\Presenter\PresenterManager;
use Psy\Presenter\ScalarPresenter;
class ClosurePresenterTest extends \PHPUnit_Framework_TestCase
{
private $presenter;
private $manager;
public function setUp()
{
$this->presenter = new ClosurePresenter();
$this->manager = new PresenterManager();
$this->manager->addPresenter(new ScalarPresenter());
$this->manager->addPresenter(new ObjectPresenter());
$this->manager->addPresenter($this->presenter);
}
/**
* @dataProvider presentData
*/
public function testPresent($closure, $expect)
{
$this->assertEquals($expect, $this->presenter->present($closure));
}
/**
* @dataProvider presentData
*/
public function testPresentRef($closure, $expect)
{
$this->assertEquals($expect, $this->presenter->presentRef($closure));
}
public function presentData()
{
$null = null;
$eol = version_compare(PHP_VERSION, '5.4.3', '>=') ? '<const>PHP_EOL</const>' : '<string>"\n"</string>';
return array(
array(
function () {
},
'<keyword>function</keyword> () { <comment>...</comment> }',
),
array(
function ($foo) {
},
'<keyword>function</keyword> ($<strong>foo</strong>) { <comment>...</comment> }',
),
array(
function ($foo, $bar = null) {
},
'<keyword>function</keyword> ($<strong>foo</strong>, $<strong>bar</strong> = <bool>null</bool>) { <comment>...</comment> }',
),
array(
function ($foo = "bar") {
},
'<keyword>function</keyword> ($<strong>foo</strong> = <string>"bar"</string>) { <comment>...</comment> }',
),
array(
function ($foo = \PHP_EOL) {
},
'<keyword>function</keyword> ($<strong>foo</strong> = ' . $eol . ') { <comment>...</comment> }',
),
array(
function ($foo) use ($eol, $null) {
},
'<keyword>function</keyword> ($<strong>foo</strong>) use ($<strong>eol</strong>, $<strong>null</strong>) { <comment>...</comment> }',
),
);
}
}

View File

@@ -1,21 +0,0 @@
<?php
/*
* This file is part of Psy Shell
*
* (c) 2012-2014 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Psy\Test\Presenter\Fixtures;
class SimpleClass
{
public $hello = 'Hello world!';
protected $foo = 'bar';
private $secret = 42;
}

View File

@@ -1,123 +0,0 @@
<?php
/*
* This file is part of Psy Shell
*
* (c) 2012-2014 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Psy\Test\Presenter;
use Psy\Presenter\ArrayPresenter;
use Psy\Presenter\ObjectPresenter;
use Psy\Presenter\Presenter;
use Psy\Presenter\PresenterManager;
use Psy\Presenter\ScalarPresenter;
use Psy\Test\Presenter\Fixtures\SimpleClass;
class ObjectPresenterTest extends \PHPUnit_Framework_TestCase
{
private $presenter;
private $manager;
public function setUp()
{
$this->presenter = new ObjectPresenter();
$this->manager = new PresenterManager();
$this->manager->addPresenter(new ScalarPresenter());
$this->manager->addPresenter(new ArrayPresenter());
$this->manager->addPresenter($this->presenter);
}
public function testPresentEmptyObject()
{
$empty = new \StdClass();
$this->assertEquals(
$this->presenter->presentRef($empty) . ' {}',
$this->presenter->present($empty)
);
}
public function testPresentWithDepth()
{
$obj = new \StdClass();
$obj->name = 'std';
$obj->type = 'class';
$obj->tags = array('stuff', 'junk');
$obj->child = new \StdClass();
$obj->child->name = 'std, jr';
$hash = spl_object_hash($obj);
$childHash = spl_object_hash($obj->child);
$expected = <<<EOS
<object>\<<class>stdClass</class> <strong>#$hash</strong>></object> {
name: <string>"std"</string>,
type: <string>"class"</string>,
tags: Array(<number>2</number>),
child: <object>\<<class>stdClass</class> <strong>#$childHash</strong>></object>
}
EOS;
$this->assertStringMatchesFormat($expected, $this->presenter->present($obj, 1));
}
public function testPresentWithoutDepth()
{
$obj = new \StdClass();
$obj->name = 'std';
$obj->type = 'class';
$obj->tags = array('stuff', 'junk');
$obj->child = new \StdClass();
$obj->child->name = 'std, jr';
$hash = spl_object_hash($obj);
$childHash = spl_object_hash($obj->child);
$expected = <<<EOS
<object>\<<class>stdClass</class> <strong>#$hash</strong>></object> {
name: <string>"std"</string>,
type: <string>"class"</string>,
tags: [
<string>"stuff"</string>,
<string>"junk"</string>
],
child: <object>\<<class>stdClass</class> <strong>#$childHash</strong>></object> {
name: <string>"std, jr"</string>
}
}
EOS;
$this->assertStringMatchesFormat($expected, $this->presenter->present($obj));
}
public function testPresentRef()
{
$obj = new \StdClass();
$formatted = $this->presenter->presentRef($obj);
$this->assertStringMatchesFormat('<object>\<<class>stdClass</class> <strong>#%s</strong>></object>', $formatted);
$this->assertContains(spl_object_hash($obj), $formatted);
}
public function testPresentVerbose()
{
$obj = new SimpleClass();
$hash = spl_object_hash($obj);
$expected = <<<EOS
<object>\<<class>Psy\Test\Presenter\Fixtures\SimpleClass</class> <strong>#$hash</strong>></object> {
hello: <string>"Hello world!"</string>,
<protected>foo</protected>: <string>"bar"</string>,
<private>secret</private>: <number>42</number>
}
EOS;
$this->assertStringMatchesFormat($expected, $this->presenter->present($obj, null, Presenter::VERBOSE));
}
}

View File

@@ -1,31 +0,0 @@
<?php
/*
* This file is part of Psy Shell
*
* (c) 2012-2014 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Psy\Test\Presenter;
use Psy\Presenter\ResourcePresenter;
class ResourcePresenterTest extends \PHPUnit_Framework_TestCase
{
private $presenter;
public function setUp()
{
$this->presenter = new ResourcePresenter();
}
public function testPresent()
{
$resource = fopen('php://stdin', 'r');
$this->assertStringMatchesFormat('<resource>\<STDIO stream <strong>resource #%d</strong>></resource>', $this->presenter->present($resource));
fclose($resource);
}
}

View File

@@ -1,53 +0,0 @@
<?php
/*
* This file is part of Psy Shell
*
* (c) 2012-2014 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Psy\Test\Presenter;
use Psy\Presenter\ScalarPresenter;
class ScalarPresenterTest extends \PHPUnit_Framework_TestCase
{
private $presenter;
public function setUp()
{
$this->presenter = new ScalarPresenter();
}
/**
* @dataProvider scalarData
*/
public function testPresent($value, $expect)
{
$this->assertEquals($expect, $this->presenter->present($value));
}
public function scalarData()
{
return array(
array(1, '<number>1</number>'),
array(1.0, '<number>1.0</number>'),
array(1.5, '<number>1.5</number>'),
array('2', '<string>"2"</string>'),
array('2.5', '<string>"2.5"</string>'),
array('alpha', '<string>"alpha"</string>'),
array("a\nb", '<string>"a\\nb"</string>'),
array(true, '<bool>true</bool>'),
array(false, '<bool>false</bool>'),
array(null, '<bool>null</bool>'),
array(NAN, '<number>NAN</number>'), // heh.
array(acos(8), '<number>NAN</number>'),
array(INF, '<number>INF</number>'),
array(-INF, '<number>-INF</number>'),
array(log(0), '<number>-INF</number>'),
);
}
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -121,7 +121,7 @@ class LibeditTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(
"foo\rbar",
"baz\r",
"w00t",
'w00t',
), $readline->listHistory());
$readline->clearHistory();
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -105,11 +105,12 @@ class ShellTest extends \PHPUnit_Framework_TestCase
$stream = $output->getStream();
$e = new ParseErrorException('message', 13);
$shell->setOutput($output);
$shell->addCode('code');
$this->assertTrue($shell->hasCode());
$this->assertNotEmpty($shell->getCodeBuffer());
$shell->renderException($e, $output);
$shell->writeException($e);
$this->assertSame($e, $shell->getScopeVariable('_e'));
$this->assertFalse($shell->hasCode());
@@ -285,8 +286,8 @@ class ShellTest extends \PHPUnit_Framework_TestCase
public function getReturnValues()
{
return array(
array('{{return value}}', '=> <string>"{{return value}}"</string>' . PHP_EOL),
array(1, '=> <number>1</number>' . PHP_EOL),
array('{{return value}}', "=> \"\033[32m{{return value}}\033[39m\"" . PHP_EOL),
array(1, "=> \033[35m1\033[39m" . PHP_EOL),
);
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -114,7 +114,11 @@ class AutoCompleterTest extends \PHPUnit_Framework_TestCase
array('ls ', array(), array('ls')),
array('sho', array('show'), array()),
array('12 + clone $', array('foo'), array()),
// array('$foo ', array('+', 'clone'), array('$foo', 'DOMDocument', 'array_map')), requires a operator matcher?
// array(
// '$foo ',
// array('+', 'clone'),
// array('$foo', 'DOMDocument', 'array_map')
// ), requires a operator matcher?
array('$', array('foo', 'bar'), array('require', 'array_search', 'T_OPEN_TAG', 'Psy')),
array(
'Psy\\',

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -49,7 +49,7 @@ class DocblockTest extends \PHPUnit_Framework_TestCase
*
* @throws \Exception with a description
*/',
"This is a docblock",
'This is a docblock',
array(
'throws' => array(array('type' => '\Exception', 'desc' => 'with a description')),
),

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,17 +11,18 @@
namespace Psy\Test\Util;
use Psy\Util\String;
use Psy\Util\Str;
class StringTest extends \PHPUnit_Framework_TestCase
class StrTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider testUnvisProvider
*/
public function testUnvis($input, $expected)
{
$this->assertEquals($expected, String::unvis($input));
$this->assertEquals($expected, Str::unvis($input));
}
public function testUnvisProvider()
{
//return require_once(__DIR__.'/../../../fixtures/unvis_fixtures.php');

View File

@@ -1,17 +0,0 @@
<?php
/*
* This file is part of Psy Shell
*
* (c) 2012-2014 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (!is_file(dirname(__DIR__) . '/vendor/autoload.php')) {
throw new RuntimeException('Install dependencies to run test suite.');
}
$loader = require dirname(__DIR__) . '/vendor/autoload.php';
$loader->add('Psy\\Test\\', __DIR__);

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of Psy Shell
* This file is part of Psy Shell.
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -12,6 +12,7 @@
$config->setRuntimeDir(sys_get_temp_dir() . '/psysh_test/withconfig/temp');
return array(
'useReadline' => true,
'usePcntl' => false,
'useReadline' => true,
'usePcntl' => false,
'errorLoggingLevel' => E_ALL & ~E_NOTICE,
);

View File

@@ -1 +1,12 @@
<?php
/*
* This file is part of Psy Shell.
*
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/* this space intentionally left blank */

View File

@@ -3,15 +3,13 @@
/*
* This file is part of Psy Shell
*
* (c) 2012-2014 Justin Hileman
* (c) 2012-2015 Justin Hileman
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Psy\Test\Presenter;
class FakeArrayObject extends \ArrayObject
{
// this space intentionally left blank.
}
return array(
'useReadline' => false,
'usePcntl' => true,
);

View File

@@ -46,7 +46,7 @@ RANGES = {
if __name__ == '__main__':
argp = argparse.ArgumentParser(
description='Generates test data for Psy\\Test\\Util\\StringTest')
description='Generates test data for Psy\\Test\\Util\\StrTest')
argp.add_argument('-f', '--format-output', action='store_true',
help='Indent JSON output to ease debugging')
argp.add_argument('-a', '--all', action='store_true',