X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Ftest%2FCodeCleaner%2FCalledClassPassTest.php;fp=vendor%2Fpsy%2Fpsysh%2Ftest%2FCodeCleaner%2FCalledClassPassTest.php;h=c80f257ac951080945ffb9d432e477760fc1840a;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/psy/psysh/test/CodeCleaner/CalledClassPassTest.php b/vendor/psy/psysh/test/CodeCleaner/CalledClassPassTest.php new file mode 100644 index 000000000..c80f257ac --- /dev/null +++ b/vendor/psy/psysh/test/CodeCleaner/CalledClassPassTest.php @@ -0,0 +1,90 @@ +setPass(new CalledClassPass()); + } + + /** + * @dataProvider invalidStatements + * @expectedException \Psy\Exception\ErrorException + */ + public function testProcessStatementFails($code) + { + $this->parseAndTraverse($code); + } + + public function invalidStatements() + { + return [ + ['get_class()'], + ['get_class(null)'], + ['get_called_class()'], + ['get_called_class(null)'], + ['function foo() { return get_class(); }'], + ['function foo() { return get_class(null); }'], + ['function foo() { return get_called_class(); }'], + ['function foo() { return get_called_class(null); }'], + ]; + } + + /** + * @dataProvider validStatements + */ + public function testProcessStatementPasses($code) + { + $this->parseAndTraverse($code); + $this->assertTrue(true); + } + + public function validStatements() + { + return [ + ['get_class($foo)'], + ['get_class(bar())'], + ['get_called_class($foo)'], + ['get_called_class(bar())'], + ['function foo($bar) { return get_class($bar); }'], + ['function foo($bar) { return get_called_class($bar); }'], + ['class Foo { function bar() { return get_class(); } }'], + ['class Foo { function bar() { return get_class(null); } }'], + ['class Foo { function bar() { return get_called_class(); } }'], + ['class Foo { function bar() { return get_called_class(null); } }'], + ['$foo = function () {}; $foo()'], + ]; + } + + /** + * @dataProvider validTraitStatements + */ + public function testProcessTraitStatementPasses($code) + { + $this->parseAndTraverse($code); + $this->assertTrue(true); + } + + public function validTraitStatements() + { + return [ + ['trait Foo { function bar() { return get_class(); } }'], + ['trait Foo { function bar() { return get_class(null); } }'], + ['trait Foo { function bar() { return get_called_class(); } }'], + ['trait Foo { function bar() { return get_called_class(null); } }'], + ]; + } +}