Source for file ShellTests.php
Documentation is available at ShellTests.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
require_once 'PHPUnit2/Framework/TestCase.php';
require_once 'PHP/Shell.php';
class ShellTests extends PHPUnit2_Framework_TestCase {
public function setUp () {
/* create a fresh shell object */
public function tearDown () {
foreach ($this->vars as $k => $v) {
public function execute () {
foreach($this->vars as $__k => $__v) {
$ {$__k} = $GLOBALS[$__k];
if ($this->shell->parse () == 0 ) {
$__retval = eval ($this->shell->getCode ());
## export vars to global scope
$this->vars[$__k] = $__v;
public function testComments () {
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
if ($this->shell->parse () == 0 ) {
eval ($this->shell->getCode ());
public function testUndefVars () {
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testNewClass () {
'$v = new ArrayObject()',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testMethod () {
'$v = new ArrayObject()',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testNotExistingMethod () {
'$v = new ArrayObject()',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testNotExistingClass () {
'$not_existing->not_existing()'
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testClass () {
'class a { const a = "a"; }'
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
public function testClassExtends () {
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
public function testClassExtendsNotExisting () {
'class c extends not_existing { }',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testClassDuplicate () {
'class duplicate_class { }',
'class duplicate_class { }',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testClassDuplicateMethod () {
'class d { function duplicate_method () { } function duplicate_method() {} }',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testClassConstant () {
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testClassConstantNotExisting () {
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testFunctionDuplicate () {
'function duplicate_function() {}',
'function duplicate_function() {}',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testFunctionDynamicNotExisting () {
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testLoops () {
'$a = array(0 => "2", 1 => "3")',
'foreach ($a as $k => $v) { }',
'for ($i = 0; $i < count($a); $i++) {} '
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testIf () {
'if (0) { } else if (1) { } else { } ',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testImplements () {
'class e implements Serializable { function serialize() { } function unserialize($a) {} }',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testInterfaceNotExists () {
'class f implements not_existing_interface { }',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testAbstractClass () {
'abstract class g { abstract function f(); }',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testStaticCall () {
'class h { static function foo() { } }',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testStaticCallNotExists () {
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testObjectArray () {
'class obj_array { function params($p1, $p2) { } }',
'$c = new ReflectionClass("obj_array")',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testObjectArrayMethodNotExists () {
'$c = new ReflectionClass("obj_array")',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testVariableMethod () {
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testVariableStaticMethod () {
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testVariableMethodNotExisting () {
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testInternalMethodCall () {
'class thisclass { function a() { } function b () { $this->a(); }}',
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testSingletonClass () {
' static private $inst = null; '.
' static function getInstance() { '.
' if (is_null(self::$inst)) { '.
' self::$inst = new singleton(); '.
' public function get() { return 1; }'.
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testGetInstance () {
'singleton::getInstance()->get()'
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testArrayAccessOnObject () {
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
## we should get a Exception
try { $this->execute (); $this->fail (); }
catch ( Exception $e ) { }
public function testFunctionVars () {
'function '.__FUNCTION__. '($a) { print $a; }'
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testMethodVars () {
'class '.__FUNCTION__. ' { function f2($a) { print $a; } }'
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testMethodDynamicConst () {
'class '.__FUNCTION__. ' { function f2($a) { print $a->foo; } }'
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testMethodDynamicFunction () {
'class '.__FUNCTION__. ' { function f2($a) { print $a->foo(); } }'
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
public function testMethodDynamicFunctionDynamic () {
'class '.__FUNCTION__. ' { function f2($a) { print $a->$foo(); } }'
foreach ($tests as $code) {
$this->shell->resetCode ();
$this->shell->appendCode ($code);
Documentation generated on Mon, 11 Mar 2019 14:40:36 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|