X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fpsy%2Fpsysh%2Ftest%2FPsy%2FTest%2FCodeCleaner%2FCalledClassPassTest.php;fp=vendor%2Fpsy%2Fpsysh%2Ftest%2FPsy%2FTest%2FCodeCleaner%2FCalledClassPassTest.php;h=dad8a05b7b157e7333bf3ba4b5123c12fc279e16;hb=eba34333e3c89f208d2f72fa91351ad019a71583;hp=0000000000000000000000000000000000000000;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/psy/psysh/test/Psy/Test/CodeCleaner/CalledClassPassTest.php b/vendor/psy/psysh/test/Psy/Test/CodeCleaner/CalledClassPassTest.php new file mode 100644 index 000000000..dad8a05b7 --- /dev/null +++ b/vendor/psy/psysh/test/Psy/Test/CodeCleaner/CalledClassPassTest.php @@ -0,0 +1,98 @@ +pass = new CalledClassPass(); + $this->traverser = new NodeTraverser(); + $this->traverser->addVisitor($this->pass); + } + + /** + * @dataProvider invalidStatements + * @expectedException \Psy\Exception\ErrorException + */ + public function testProcessStatementFails($code) + { + $stmts = $this->parse($code); + $this->traverser->traverse($stmts); + } + + public function invalidStatements() + { + return array( + array('get_class()'), + array('get_class(null)'), + array('get_called_class()'), + array('get_called_class(null)'), + array('function foo() { return get_class(); }'), + array('function foo() { return get_class(null); }'), + array('function foo() { return get_called_class(); }'), + array('function foo() { return get_called_class(null); }'), + ); + } + + /** + * @dataProvider validStatements + */ + public function testProcessStatementPasses($code) + { + $stmts = $this->parse($code); + $this->traverser->traverse($stmts); + } + + public function validStatements() + { + return array( + array('get_class($foo)'), + array('get_class(bar())'), + array('get_called_class($foo)'), + array('get_called_class(bar())'), + array('function foo($bar) { return get_class($bar); }'), + array('function foo($bar) { return get_called_class($bar); }'), + array('class Foo { function bar() { return get_class(); } }'), + array('class Foo { function bar() { return get_class(null); } }'), + array('class Foo { function bar() { return get_called_class(); } }'), + array('class Foo { function bar() { return get_called_class(null); } }'), + array('$foo = function () {}; $foo()'), + ); + } + + /** + * @dataProvider validTraitStatements + */ + public function testProcessTraitStatementPasses($code) + { + if (version_compare(PHP_VERSION, '5.4', '<')) { + $this->markTestSkipped(); + } + + $stmts = $this->parse($code); + $this->traverser->traverse($stmts); + } + + public function validTraitStatements() + { + return array( + array('trait Foo { function bar() { return get_class(); } }'), + array('trait Foo { function bar() { return get_class(null); } }'), + array('trait Foo { function bar() { return get_called_class(); } }'), + array('trait Foo { function bar() { return get_called_class(null); } }'), + ); + } +}