Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Psy\Test; use Psy\Configuration; use Psy\Exception\BreakException; use Ps..
Decoded Output download
<?php
namespace Psy\Test; use Psy\Configuration; use Psy\Exception\BreakException; use Psy\Exception\ParseErrorException; use Psy\Shell; use Psy\TabCompletion\Matcher\ClassMethodsMatcher; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\StreamOutput; class ShellTest extends TestCase { private $streams = array(); public function closeOpenStreams() { foreach ($this->streams as $stream) { \fclose($stream); } } public function testScopeVariables() { $one = "banana"; $two = 123; $three = new \stdClass(); $__psysh__ = "ignore this"; $_ = "ignore this"; $_e = "ignore this"; $shell = new Shell($this->getConfig()); $shell->setScopeVariables(\compact("one", "two", "three", "__psysh__", "_", "_e", "this")); $this->assertNotContains("__psysh__", $shell->getScopeVariableNames()); $this->assertSame(array("one", "two", "three", "_"), $shell->getScopeVariableNames()); $this->assertSame("banana", $shell->getScopeVariable("one")); $this->assertSame(123, $shell->getScopeVariable("two")); $this->assertSame($three, $shell->getScopeVariable("three")); $this->assertNull($shell->getScopeVariable("_")); $diff = $shell->getScopeVariablesDiff(array("one" => $one, "two" => "not two")); $this->assertSame(array("two" => $two, "three" => $three, "_" => null), $diff); $shell->setScopeVariables(array()); $this->assertSame(array("_"), $shell->getScopeVariableNames()); $shell->setBoundObject($this); $this->assertSame(array("_", "this"), $shell->getScopeVariableNames()); $this->assertSame($this, $shell->getScopeVariable("this")); $this->assertSame(array("_" => null), $shell->getScopeVariables(false)); $this->assertSame(array("_" => null, "this" => $this), $shell->getScopeVariables()); } public function testUnknownScopeVariablesThrowExceptions() { $this->expectException(\InvalidArgumentException::class); $shell = new Shell($this->getConfig()); $shell->setScopeVariables(array("foo" => "FOO", "bar" => 1)); $shell->getScopeVariable("baz"); $this->fail(); } public function testIncludesWithScopeVariables() { $one = "banana"; $two = 123; $three = new \stdClass(); $__psysh__ = "ignore this"; $_ = "ignore this"; $_e = "ignore this"; $config = $this->getConfig(array("usePcntl" => false)); $shell = new Shell($config); $shell->setScopeVariables(\compact("one", "two", "three", "__psysh__", "_", "_e", "this")); $shell->addInput("exit", true); $shell->run(null, $this->getOutput()); $this->assertNotContains("__psysh__", $shell->getScopeVariableNames()); $this->assertArrayEquals(array("one", "two", "three", "_"), $shell->getScopeVariableNames()); $this->assertSame("banana", $shell->getScopeVariable("one")); $this->assertSame(123, $shell->getScopeVariable("two")); $this->assertSame($three, $shell->getScopeVariable("three")); $this->assertNull($shell->getScopeVariable("_")); } protected function assertArrayEquals(array $expected, array $actual, $message = '') { if (\method_exists($this, "assertSameCanonicalizing")) { return $this->assertSameCanonicalizing($expected, $actual, $message); } \sort($expected); \sort($actual); $this->assertSame($expected, $actual, $message); } public function testNonInteractiveDoesNotUpdateContext() { $config = $this->getConfig(array("usePcntl" => false, "interactiveMode" => Configuration::INTERACTIVE_MODE_DISABLED)); $shell = new Shell($config); $input = $this->getInput(''); $shell->addInput("$var=5;", true); $shell->addInput("exit", true); $shell->run($input, $this->getOutput()); $this->assertNotContains("var", $shell->getScopeVariableNames()); } public function testNonInteractiveRawOutput() { $config = $this->getConfig(array("usePcntl" => false, "rawOutput" => true, "interactiveMode" => Configuration::INTERACTIVE_MODE_DISABLED)); $shell = new Shell($config); $input = $this->getInput(''); $output = $this->getOutput(); $stream = $output->getStream(); $shell->setOutput($output); $shell->addInput("$foo = "bar"", true); $shell->addInput("exit", true); $shell->run($input, $output); \rewind($stream); $streamContents = \stream_get_contents($stream); $this->assertStringNotContainsString("Justin Hileman", $streamContents); $this->assertStringNotContainsString(\PHP_VERSION, $streamContents); $this->assertStringNotContainsString(Shell::VERSION, $streamContents); $this->assertStringNotContainsString("Goodbye", $streamContents); $this->assertStringNotContainsString("Exiting", $streamContents); } public function testIncludes() { $config = $this->getConfig(array("configFile" => __DIR__ . "/fixtures/empty.php")); $shell = new Shell($config); $this->assertEmpty($shell->getIncludes()); $shell->setIncludes(array("foo", "bar", "baz")); $this->assertSame(array("foo", "bar", "baz"), $shell->getIncludes()); } public function testIncludesConfig() { $config = $this->getConfig(array("defaultIncludes" => array("/file.php"), "configFile" => __DIR__ . "/fixtures/empty.php")); $shell = new Shell($config); $includes = $shell->getIncludes(); $this->assertSame("/file.php", $includes[0]); } public function testAddMatchersViaConfig() { $shell = new FakeShell(); $matcher = new ClassMethodsMatcher(); $config = $this->getConfig(array("matchers" => array($matcher))); $config->setShell($shell); $this->assertSame(array($matcher), $shell->matchers); } public function testAddMatchersViaConfigAfterShell() { $shell = new FakeShell(); $matcher = new ClassMethodsMatcher(); $config = $this->getConfig(array()); $config->setShell($shell); $config->addMatchers(array($matcher)); $this->assertSame(array($matcher), $shell->matchers); } public function testRenderingExceptions() { $shell = new Shell($this->getConfig()); $output = $this->getOutput(); $stream = $output->getStream(); $e = new ParseErrorException("message", 13); $shell->setOutput($output); $shell->addCode("code"); $this->assertTrue($shell->hasCode()); $this->assertNotEmpty($shell->getCodeBuffer()); $shell->writeException($e); $this->assertSame($e, $shell->getScopeVariable("_e")); $this->assertFalse($shell->hasCode()); $this->assertEmpty($shell->getCodeBuffer()); \rewind($stream); $streamContents = \stream_get_contents($stream); $expected = "PARSE ERROR PHP Parse error: message in test/ShellTest.php on line 236."; $this->assertSame($expected, \trim($streamContents)); } public function testReportsErrors($errno, $label) { $shell = new Shell($this->getConfig()); $output = $this->getOutput(); $stream = $output->getStream(); $shell->setOutput($output); $oldLevel = \error_reporting(\E_ALL); $shell->handleError($errno, "wheee", null, 13); \error_reporting($oldLevel); \rewind($stream); $streamContents = \stream_get_contents($stream); $this->assertStringContainsString($label, $streamContents); $this->assertStringContainsString("wheee", $streamContents); $this->assertStringContainsString("line 13", $streamContents); } public function notSoBadErrors() { return array(array(\E_WARNING, "WARNING"), array(\E_NOTICE, "NOTICE"), array(\E_CORE_WARNING, "CORE WARNING"), array(\E_COMPILE_WARNING, "COMPILE WARNING"), array(\E_USER_WARNING, "USER WARNING"), array(\E_USER_NOTICE, "USER NOTICE"), array(\E_DEPRECATED, "DEPRECATED"), array(\E_USER_DEPRECATED, "USER DEPRECATED")); } public function testThrowsBadErrors($errno) { $this->expectException(\Psy\Exception\ErrorException::class); $shell = new Shell($this->getConfig()); $shell->handleError($errno, "wheee", null, 13); $this->fail(); } public function badErrors() { return array(array(\E_ERROR), array(\E_PARSE), array(\E_CORE_ERROR), array(\E_COMPILE_ERROR), array(\E_USER_ERROR), array(\E_RECOVERABLE_ERROR)); } public function testVersion() { $shell = new Shell($this->getConfig()); $this->assertInstanceOf(Application::class, $shell); $this->assertStringContainsString(Shell::VERSION, $shell->getVersion()); $this->assertStringContainsString(\PHP_VERSION, $shell->getVersion()); $this->assertStringContainsString(\PHP_SAPI, $shell->getVersion()); } public function testGetVersionHeader() { $header = Shell::getVersionHeader(false); $this->assertStringContainsString(Shell::VERSION, $header); $this->assertStringContainsString(\PHP_VERSION, $header); $this->assertStringContainsString(\PHP_SAPI, $header); } public function testCodeBuffer() { $shell = new Shell($this->getConfig()); $shell->addCode("class"); $this->assertNull($shell->flushCode()); $this->assertTrue($shell->hasCode()); $shell->addCode("a"); $this->assertNull($shell->flushCode()); $this->assertTrue($shell->hasCode()); $shell->addCode("{}"); $code = $shell->flushCode(); $this->assertFalse($shell->hasCode()); $code = \preg_replace("/\s+/", " ", $code); $this->assertNotNull($code); $this->assertSame("class a { } return new \Psy\CodeCleaner\NoReturnValue();", $code); } public function testKeepCodeBufferOpen() { $shell = new Shell($this->getConfig()); $shell->addCode("1 \"); $this->assertNull($shell->flushCode()); $this->assertTrue($shell->hasCode()); $shell->addCode("+ 1 \"); $this->assertNull($shell->flushCode()); $this->assertTrue($shell->hasCode()); $shell->addCode("+ 1"); $code = $shell->flushCode(); $this->assertFalse($shell->hasCode()); $code = \preg_replace("/\s+/", " ", $code); $this->assertNotNull($code); $this->assertSame("return 1 + 1 + 1;", $code); } public function testCodeBufferThrowsParseExceptions() { $this->expectException(ParseErrorException::class); $shell = new Shell($this->getConfig()); $shell->addCode("this is not valid"); $shell->flushCode(); $this->fail(); } public function testClosuresSupport() { $shell = new Shell($this->getConfig()); $code = "$test = function () {}"; $shell->addCode($code); $shell->flushCode(); $code = "$test()"; $shell->addCode($code); $this->assertSame($shell->flushCode(), "return $test();"); } public function testWriteStdout() { $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig()); $shell->setOutput($output); $shell->writeStdout("{{stdout}}\xa"); \rewind($stream); $streamContents = \stream_get_contents($stream); $this->assertSame("{{stdout}}" . \PHP_EOL, $streamContents); } public function testWriteStdoutWithoutNewline() { $this->markTestSkipped("This test won't work on CI without overriding pipe detection"); $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig()); $shell->setOutput($output); $shell->writeStdout("{{stdout}}"); \rewind($stream); $streamContents = \stream_get_contents($stream); $this->assertSame("{{stdout}}<aside>\xe2\217\216</aside>" . \PHP_EOL, $streamContents); } public function testWriteStdoutRawOutputWithoutNewline() { $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("rawOutput" => true))); $shell->setOutput($output); $shell->writeStdout("{{stdout}}"); \rewind($stream); $streamContents = \stream_get_contents($stream); $this->assertSame("{{stdout}}" . \PHP_EOL, $streamContents); } public function testWriteReturnValue($input, $expected) { $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("theme" => "modern"))); $shell->setOutput($output); $shell->writeReturnValue($input); \rewind($stream); $this->assertSame($expected, \stream_get_contents($stream)); } public function testDoNotWriteReturnValueWhenQuiet($input, $expected) { $output = $this->getOutput(); $output->setVerbosity(StreamOutput::VERBOSITY_QUIET); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("theme" => "modern"))); $shell->setOutput($output); $shell->writeReturnValue($input); \rewind($stream); $this->assertSame('', \stream_get_contents($stream)); } public function getReturnValues() { return array(array("{{return value}}", "<whisper>= </whisper>"\x1b[32m{{return value}}\x1b[39m"" . \PHP_EOL), array(1, "<whisper>= </whisper>\x1b[35m1\33[39m" . \PHP_EOL)); } public function testWriteException($exception, $expected) { $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("theme" => "compact"))); $shell->setOutput($output); $shell->writeException($exception); \rewind($stream); $this->assertSame($expected, \stream_get_contents($stream)); } public function testWriteExceptionVerbose($exception, $expected) { $output = $this->getOutput(); $output->setVerbosity(StreamOutput::VERBOSITY_VERBOSE); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("theme" => "compact"))); $shell->setOutput($output); $shell->writeException($exception); \rewind($stream); $stdout = \stream_get_contents($stream); $this->assertStringStartsWith($expected, $stdout); $this->assertStringContainsString(\basename(__FILE__), $stdout); $lineCount = \count(\explode(\PHP_EOL, $stdout)); $this->assertGreaterThan(4, $lineCount); } public function getRenderedExceptions() { return array(array(new \Exception("{{message}}"), " Exception {{message}}.
")); } public function testWriteExceptionVerboseButNotReallyBecauseItIsABreakException() { $output = $this->getOutput(); $output->setVerbosity(StreamOutput::VERBOSITY_VERBOSE); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("theme" => "compact"))); $shell->setOutput($output); $shell->writeException(new BreakException("yeah")); \rewind($stream); $this->assertSame(" INFO yeah.
", \stream_get_contents($stream)); } public function testCompactExceptionOutput($theme, $exception, $expected) { $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("theme" => $theme))); $shell->setOutput($output); $shell->writeException($exception); \rewind($stream); $this->assertSame($expected, \stream_get_contents($stream)); } public function getExceptionOutput() { return array(array("compact", new BreakException("break"), " INFO break.\xa"), array("modern", new BreakException("break"), "
INFO break.\xa
"), array("compact", new \Exception("foo"), " Exception foo.
"), array("modern", new \Exception("bar"), "
Exception bar.\xa\xa")); } public function testShellExecute($input, $expected) { $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig()); $shell->setOutput($output); $this->assertSame($expected, $shell->execute($input)); \rewind($stream); $this->assertSame('', \stream_get_contents($stream)); } public function getExecuteValues() { return array(array("return 12", 12), array(""{{return value}}"", "{{return value}}"), array("1", 1)); } public function testHasCommand($command, $has) { $shell = new Shell($this->getConfig()); $refl = new \ReflectionClass(Shell::class); $method = $refl->getMethod("hasCommand"); $method->setAccessible(true); $this->assertSame($method->invokeArgs($shell, array($command)), $has); } public function commandsToHas() { return array(array("help", true), array("help help", true), array(""help"", false), array(""help help"", false), array("ls -al ", true), array("ls "-al" ", true), array("ls"-al"", false), array(" q", true), array(" q --help", true), array(""q"", false), array(""q",", false)); } private function getInput($input) { $input = new StringInput($input); return $input; } private function getOutput() { $stream = \fopen("php://memory", "w+"); $this->streams[] = $stream; $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, false); return $output; } private function getConfig(array $config = array()) { $dir = \tempnam(\sys_get_temp_dir(), "psysh_shell_test_"); \unlink($dir); $defaults = array("configDir" => $dir, "dataDir" => $dir, "runtimeDir" => $dir, "colorMode" => Configuration::COLOR_MODE_FORCED); return new Configuration(\array_merge($defaults, $config)); } public function testStrictTypesExecute() { $shell = new Shell($this->getConfig(array("strictTypes" => false))); $shell->setOutput($this->getOutput()); $shell->execute("(function(): int { return 1.1; })()", true); $this->assertTrue(true); } public function testLaxTypesExecute() { $this->expectException(\TypeError::class); $shell = new Shell($this->getConfig(array("strictTypes" => true))); $shell->setOutput($this->getOutput()); $shell->execute("(function(): int { return 1.1; })()", true); } } ?>
Did this file decode correctly?
Original Code
<?php
namespace Psy\Test; use Psy\Configuration; use Psy\Exception\BreakException; use Psy\Exception\ParseErrorException; use Psy\Shell; use Psy\TabCompletion\Matcher\ClassMethodsMatcher; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\StreamOutput; class ShellTest extends TestCase { private $streams = array(); public function closeOpenStreams() { foreach ($this->streams as $stream) { \fclose($stream); } } public function testScopeVariables() { $one = "\x62\x61\156\141\156\141"; $two = 123; $three = new \stdClass(); $__psysh__ = "\x69\147\156\157\x72\x65\40\164\x68\151\x73"; $_ = "\x69\147\156\157\x72\145\x20\164\x68\151\163"; $_e = "\x69\147\x6e\157\x72\145\x20\164\x68\x69\163"; $shell = new Shell($this->getConfig()); $shell->setScopeVariables(\compact("\x6f\x6e\x65", "\164\167\157", "\164\150\x72\145\145", "\x5f\137\x70\163\x79\x73\150\137\x5f", "\x5f", "\137\145", "\164\x68\x69\x73")); $this->assertNotContains("\x5f\137\x70\163\171\163\150\137\x5f", $shell->getScopeVariableNames()); $this->assertSame(array("\157\156\145", "\x74\167\157", "\x74\150\x72\145\x65", "\137"), $shell->getScopeVariableNames()); $this->assertSame("\x62\141\156\141\156\141", $shell->getScopeVariable("\157\x6e\x65")); $this->assertSame(123, $shell->getScopeVariable("\164\167\157")); $this->assertSame($three, $shell->getScopeVariable("\x74\x68\x72\x65\145")); $this->assertNull($shell->getScopeVariable("\137")); $diff = $shell->getScopeVariablesDiff(array("\x6f\156\145" => $one, "\164\167\x6f" => "\x6e\x6f\164\40\x74\167\x6f")); $this->assertSame(array("\164\x77\157" => $two, "\164\150\162\x65\x65" => $three, "\137" => null), $diff); $shell->setScopeVariables(array()); $this->assertSame(array("\x5f"), $shell->getScopeVariableNames()); $shell->setBoundObject($this); $this->assertSame(array("\x5f", "\164\x68\x69\x73"), $shell->getScopeVariableNames()); $this->assertSame($this, $shell->getScopeVariable("\x74\x68\151\x73")); $this->assertSame(array("\137" => null), $shell->getScopeVariables(false)); $this->assertSame(array("\137" => null, "\x74\x68\151\x73" => $this), $shell->getScopeVariables()); } public function testUnknownScopeVariablesThrowExceptions() { $this->expectException(\InvalidArgumentException::class); $shell = new Shell($this->getConfig()); $shell->setScopeVariables(array("\x66\157\x6f" => "\x46\x4f\x4f", "\142\141\162" => 1)); $shell->getScopeVariable("\142\141\172"); $this->fail(); } public function testIncludesWithScopeVariables() { $one = "\x62\x61\156\x61\x6e\x61"; $two = 123; $three = new \stdClass(); $__psysh__ = "\x69\147\156\157\x72\x65\x20\x74\150\x69\163"; $_ = "\x69\147\156\x6f\162\x65\40\x74\150\151\163"; $_e = "\151\147\156\157\162\145\40\x74\150\x69\x73"; $config = $this->getConfig(array("\165\x73\x65\x50\x63\156\164\154" => false)); $shell = new Shell($config); $shell->setScopeVariables(\compact("\157\x6e\x65", "\x74\167\x6f", "\x74\x68\x72\x65\145", "\x5f\x5f\x70\x73\171\x73\150\137\x5f", "\x5f", "\x5f\145", "\x74\150\151\163")); $shell->addInput("\x65\170\x69\x74", true); $shell->run(null, $this->getOutput()); $this->assertNotContains("\137\137\x70\x73\171\x73\x68\x5f\137", $shell->getScopeVariableNames()); $this->assertArrayEquals(array("\157\x6e\x65", "\164\167\157", "\x74\x68\162\145\145", "\137"), $shell->getScopeVariableNames()); $this->assertSame("\142\x61\156\x61\x6e\141", $shell->getScopeVariable("\157\156\145")); $this->assertSame(123, $shell->getScopeVariable("\x74\x77\157")); $this->assertSame($three, $shell->getScopeVariable("\164\150\x72\145\145")); $this->assertNull($shell->getScopeVariable("\137")); } protected function assertArrayEquals(array $expected, array $actual, $message = '') { if (\method_exists($this, "\141\x73\163\x65\x72\164\x53\141\x6d\x65\x43\x61\156\157\156\x69\143\x61\x6c\151\172\x69\x6e\x67")) { return $this->assertSameCanonicalizing($expected, $actual, $message); } \sort($expected); \sort($actual); $this->assertSame($expected, $actual, $message); } public function testNonInteractiveDoesNotUpdateContext() { $config = $this->getConfig(array("\x75\x73\x65\x50\x63\x6e\164\x6c" => false, "\x69\156\x74\145\x72\x61\x63\164\151\x76\145\115\157\x64\145" => Configuration::INTERACTIVE_MODE_DISABLED)); $shell = new Shell($config); $input = $this->getInput(''); $shell->addInput("\44\166\x61\162\x3d\65\73", true); $shell->addInput("\x65\x78\x69\x74", true); $shell->run($input, $this->getOutput()); $this->assertNotContains("\166\141\162", $shell->getScopeVariableNames()); } public function testNonInteractiveRawOutput() { $config = $this->getConfig(array("\x75\x73\145\x50\143\x6e\x74\x6c" => false, "\x72\141\x77\x4f\x75\x74\160\165\x74" => true, "\151\156\x74\x65\162\x61\x63\164\x69\166\x65\x4d\157\144\145" => Configuration::INTERACTIVE_MODE_DISABLED)); $shell = new Shell($config); $input = $this->getInput(''); $output = $this->getOutput(); $stream = $output->getStream(); $shell->setOutput($output); $shell->addInput("\44\146\157\x6f\40\75\40\42\142\141\162\x22", true); $shell->addInput("\145\170\151\164", true); $shell->run($input, $output); \rewind($stream); $streamContents = \stream_get_contents($stream); $this->assertStringNotContainsString("\x4a\165\x73\x74\x69\x6e\40\110\x69\x6c\145\155\141\156", $streamContents); $this->assertStringNotContainsString(\PHP_VERSION, $streamContents); $this->assertStringNotContainsString(Shell::VERSION, $streamContents); $this->assertStringNotContainsString("\x47\x6f\157\x64\x62\x79\x65", $streamContents); $this->assertStringNotContainsString("\x45\x78\151\x74\x69\156\x67", $streamContents); } public function testIncludes() { $config = $this->getConfig(array("\x63\x6f\x6e\x66\x69\x67\106\151\x6c\x65" => __DIR__ . "\57\x66\151\x78\x74\x75\x72\x65\163\x2f\x65\155\160\164\171\x2e\160\150\x70")); $shell = new Shell($config); $this->assertEmpty($shell->getIncludes()); $shell->setIncludes(array("\146\157\x6f", "\142\141\x72", "\x62\141\172")); $this->assertSame(array("\x66\x6f\x6f", "\x62\x61\162", "\x62\141\x7a"), $shell->getIncludes()); } public function testIncludesConfig() { $config = $this->getConfig(array("\x64\x65\x66\141\x75\154\164\x49\x6e\x63\x6c\165\x64\x65\x73" => array("\x2f\x66\151\x6c\x65\56\x70\150\x70"), "\143\x6f\x6e\x66\151\x67\x46\x69\154\145" => __DIR__ . "\57\146\x69\170\164\x75\162\145\x73\x2f\x65\x6d\x70\164\x79\x2e\160\150\x70")); $shell = new Shell($config); $includes = $shell->getIncludes(); $this->assertSame("\57\146\151\x6c\145\56\x70\x68\x70", $includes[0]); } public function testAddMatchersViaConfig() { $shell = new FakeShell(); $matcher = new ClassMethodsMatcher(); $config = $this->getConfig(array("\155\x61\x74\x63\150\145\x72\x73" => array($matcher))); $config->setShell($shell); $this->assertSame(array($matcher), $shell->matchers); } public function testAddMatchersViaConfigAfterShell() { $shell = new FakeShell(); $matcher = new ClassMethodsMatcher(); $config = $this->getConfig(array()); $config->setShell($shell); $config->addMatchers(array($matcher)); $this->assertSame(array($matcher), $shell->matchers); } public function testRenderingExceptions() { $shell = new Shell($this->getConfig()); $output = $this->getOutput(); $stream = $output->getStream(); $e = new ParseErrorException("\x6d\x65\163\x73\x61\x67\x65", 13); $shell->setOutput($output); $shell->addCode("\x63\x6f\144\x65"); $this->assertTrue($shell->hasCode()); $this->assertNotEmpty($shell->getCodeBuffer()); $shell->writeException($e); $this->assertSame($e, $shell->getScopeVariable("\137\145")); $this->assertFalse($shell->hasCode()); $this->assertEmpty($shell->getCodeBuffer()); \rewind($stream); $streamContents = \stream_get_contents($stream); $expected = "\120\x41\122\123\105\40\105\x52\x52\x4f\122\40\x20\120\110\120\40\120\x61\x72\x73\x65\40\x65\x72\x72\157\x72\72\x20\x6d\x65\x73\163\141\147\145\40\x69\156\40\x74\145\x73\x74\57\123\150\x65\x6c\x6c\x54\x65\163\164\x2e\160\x68\x70\x20\157\156\40\154\x69\156\x65\40\62\63\x36\x2e"; $this->assertSame($expected, \trim($streamContents)); } public function testReportsErrors($errno, $label) { $shell = new Shell($this->getConfig()); $output = $this->getOutput(); $stream = $output->getStream(); $shell->setOutput($output); $oldLevel = \error_reporting(\E_ALL); $shell->handleError($errno, "\167\150\145\x65\x65", null, 13); \error_reporting($oldLevel); \rewind($stream); $streamContents = \stream_get_contents($stream); $this->assertStringContainsString($label, $streamContents); $this->assertStringContainsString("\x77\x68\x65\x65\145", $streamContents); $this->assertStringContainsString("\x6c\x69\156\145\40\x31\63", $streamContents); } public function notSoBadErrors() { return array(array(\E_WARNING, "\x57\101\122\116\x49\x4e\107"), array(\E_NOTICE, "\116\117\124\111\x43\105"), array(\E_CORE_WARNING, "\x43\x4f\x52\x45\x20\x57\101\122\x4e\111\x4e\107"), array(\E_COMPILE_WARNING, "\103\117\x4d\120\111\x4c\x45\40\x57\x41\x52\116\111\116\x47"), array(\E_USER_WARNING, "\125\123\x45\122\40\127\101\122\x4e\x49\x4e\107"), array(\E_USER_NOTICE, "\125\x53\105\x52\40\x4e\x4f\x54\x49\103\x45"), array(\E_DEPRECATED, "\x44\105\120\122\x45\x43\101\124\x45\x44"), array(\E_USER_DEPRECATED, "\x55\x53\105\122\40\x44\x45\120\x52\105\103\x41\124\x45\x44")); } public function testThrowsBadErrors($errno) { $this->expectException(\Psy\Exception\ErrorException::class); $shell = new Shell($this->getConfig()); $shell->handleError($errno, "\x77\x68\145\x65\x65", null, 13); $this->fail(); } public function badErrors() { return array(array(\E_ERROR), array(\E_PARSE), array(\E_CORE_ERROR), array(\E_COMPILE_ERROR), array(\E_USER_ERROR), array(\E_RECOVERABLE_ERROR)); } public function testVersion() { $shell = new Shell($this->getConfig()); $this->assertInstanceOf(Application::class, $shell); $this->assertStringContainsString(Shell::VERSION, $shell->getVersion()); $this->assertStringContainsString(\PHP_VERSION, $shell->getVersion()); $this->assertStringContainsString(\PHP_SAPI, $shell->getVersion()); } public function testGetVersionHeader() { $header = Shell::getVersionHeader(false); $this->assertStringContainsString(Shell::VERSION, $header); $this->assertStringContainsString(\PHP_VERSION, $header); $this->assertStringContainsString(\PHP_SAPI, $header); } public function testCodeBuffer() { $shell = new Shell($this->getConfig()); $shell->addCode("\x63\154\141\163\x73"); $this->assertNull($shell->flushCode()); $this->assertTrue($shell->hasCode()); $shell->addCode("\141"); $this->assertNull($shell->flushCode()); $this->assertTrue($shell->hasCode()); $shell->addCode("\173\175"); $code = $shell->flushCode(); $this->assertFalse($shell->hasCode()); $code = \preg_replace("\57\x5c\x73\x2b\x2f", "\40", $code); $this->assertNotNull($code); $this->assertSame("\143\154\141\x73\163\40\x61\x20\173\40\175\x20\162\145\164\x75\x72\x6e\40\x6e\x65\167\40\x5c\x50\163\x79\x5c\x43\157\x64\x65\x43\154\145\141\156\145\162\x5c\x4e\157\x52\x65\x74\x75\x72\x6e\x56\141\154\165\145\50\51\73", $code); } public function testKeepCodeBufferOpen() { $shell = new Shell($this->getConfig()); $shell->addCode("\x31\x20\x5c"); $this->assertNull($shell->flushCode()); $this->assertTrue($shell->hasCode()); $shell->addCode("\53\x20\x31\40\134"); $this->assertNull($shell->flushCode()); $this->assertTrue($shell->hasCode()); $shell->addCode("\x2b\40\x31"); $code = $shell->flushCode(); $this->assertFalse($shell->hasCode()); $code = \preg_replace("\57\134\x73\x2b\x2f", "\40", $code); $this->assertNotNull($code); $this->assertSame("\x72\x65\164\165\x72\x6e\40\x31\40\53\40\61\40\x2b\40\61\73", $code); } public function testCodeBufferThrowsParseExceptions() { $this->expectException(ParseErrorException::class); $shell = new Shell($this->getConfig()); $shell->addCode("\164\150\151\x73\40\x69\163\40\156\157\x74\40\166\x61\x6c\151\144"); $shell->flushCode(); $this->fail(); } public function testClosuresSupport() { $shell = new Shell($this->getConfig()); $code = "\44\x74\145\163\x74\x20\x3d\40\x66\165\156\x63\x74\x69\x6f\156\x20\50\51\x20\173\175"; $shell->addCode($code); $shell->flushCode(); $code = "\x24\164\x65\x73\x74\50\x29"; $shell->addCode($code); $this->assertSame($shell->flushCode(), "\x72\x65\x74\x75\162\x6e\40\44\164\145\x73\x74\x28\51\x3b"); } public function testWriteStdout() { $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig()); $shell->setOutput($output); $shell->writeStdout("\173\173\x73\x74\144\157\x75\x74\x7d\175\xa"); \rewind($stream); $streamContents = \stream_get_contents($stream); $this->assertSame("\173\x7b\163\164\x64\x6f\165\164\175\x7d" . \PHP_EOL, $streamContents); } public function testWriteStdoutWithoutNewline() { $this->markTestSkipped("\x54\x68\x69\x73\x20\164\145\x73\x74\x20\x77\x6f\x6e\x27\164\40\167\x6f\162\x6b\x20\157\156\40\x43\111\x20\x77\x69\164\150\157\165\x74\40\157\x76\x65\162\162\151\144\x69\x6e\x67\x20\160\x69\x70\x65\40\x64\x65\x74\x65\x63\x74\151\x6f\x6e"); $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig()); $shell->setOutput($output); $shell->writeStdout("\173\173\x73\x74\144\x6f\x75\x74\x7d\x7d"); \rewind($stream); $streamContents = \stream_get_contents($stream); $this->assertSame("\x7b\173\163\x74\x64\x6f\165\164\x7d\175\74\x61\163\151\144\145\76\xe2\217\216\74\x2f\141\x73\151\144\x65\76" . \PHP_EOL, $streamContents); } public function testWriteStdoutRawOutputWithoutNewline() { $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("\x72\141\x77\117\x75\164\160\x75\164" => true))); $shell->setOutput($output); $shell->writeStdout("\x7b\173\x73\x74\x64\157\165\164\x7d\x7d"); \rewind($stream); $streamContents = \stream_get_contents($stream); $this->assertSame("\x7b\173\x73\164\144\x6f\165\164\x7d\x7d" . \PHP_EOL, $streamContents); } public function testWriteReturnValue($input, $expected) { $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("\x74\x68\145\x6d\145" => "\x6d\157\x64\145\x72\x6e"))); $shell->setOutput($output); $shell->writeReturnValue($input); \rewind($stream); $this->assertSame($expected, \stream_get_contents($stream)); } public function testDoNotWriteReturnValueWhenQuiet($input, $expected) { $output = $this->getOutput(); $output->setVerbosity(StreamOutput::VERBOSITY_QUIET); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("\164\x68\x65\155\x65" => "\155\x6f\x64\145\x72\x6e"))); $shell->setOutput($output); $shell->writeReturnValue($input); \rewind($stream); $this->assertSame('', \stream_get_contents($stream)); } public function getReturnValues() { return array(array("\x7b\x7b\162\145\x74\x75\x72\156\40\166\141\x6c\x75\x65\x7d\175", "\x3c\167\x68\x69\163\160\x65\x72\x3e\75\x20\x3c\x2f\x77\x68\x69\163\160\145\162\x3e\42\x1b\x5b\x33\x32\x6d\x7b\173\x72\145\164\x75\x72\x6e\40\x76\141\154\165\x65\175\x7d\x1b\x5b\x33\x39\155\x22" . \PHP_EOL), array(1, "\x3c\167\x68\151\163\x70\145\x72\76\x3d\40\74\57\167\150\x69\x73\x70\145\162\x3e\x1b\133\63\x35\x6d\x31\33\133\x33\x39\x6d" . \PHP_EOL)); } public function testWriteException($exception, $expected) { $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("\164\x68\145\155\x65" => "\x63\x6f\155\x70\x61\x63\x74"))); $shell->setOutput($output); $shell->writeException($exception); \rewind($stream); $this->assertSame($expected, \stream_get_contents($stream)); } public function testWriteExceptionVerbose($exception, $expected) { $output = $this->getOutput(); $output->setVerbosity(StreamOutput::VERBOSITY_VERBOSE); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("\164\x68\145\x6d\145" => "\x63\x6f\x6d\x70\141\143\164"))); $shell->setOutput($output); $shell->writeException($exception); \rewind($stream); $stdout = \stream_get_contents($stream); $this->assertStringStartsWith($expected, $stdout); $this->assertStringContainsString(\basename(__FILE__), $stdout); $lineCount = \count(\explode(\PHP_EOL, $stdout)); $this->assertGreaterThan(4, $lineCount); } public function getRenderedExceptions() { return array(array(new \Exception("\x7b\173\155\x65\x73\163\141\x67\145\175\175"), "\x20\x45\170\143\145\x70\164\151\x6f\156\40\x20\173\173\155\x65\x73\163\141\x67\x65\x7d\x7d\56\12")); } public function testWriteExceptionVerboseButNotReallyBecauseItIsABreakException() { $output = $this->getOutput(); $output->setVerbosity(StreamOutput::VERBOSITY_VERBOSE); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("\164\150\x65\155\145" => "\143\x6f\155\x70\141\x63\x74"))); $shell->setOutput($output); $shell->writeException(new BreakException("\x79\x65\141\x68")); \rewind($stream); $this->assertSame("\x20\111\116\x46\117\40\40\x79\x65\x61\150\56\12", \stream_get_contents($stream)); } public function testCompactExceptionOutput($theme, $exception, $expected) { $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig(array("\x74\x68\x65\x6d\x65" => $theme))); $shell->setOutput($output); $shell->writeException($exception); \rewind($stream); $this->assertSame($expected, \stream_get_contents($stream)); } public function getExceptionOutput() { return array(array("\143\157\x6d\x70\x61\x63\164", new BreakException("\x62\x72\x65\141\153"), "\x20\111\116\x46\117\40\40\x62\x72\145\141\153\x2e\xa"), array("\x6d\157\144\145\162\x6e", new BreakException("\x62\x72\x65\x61\x6b"), "\12\x20\x20\x20\111\x4e\x46\117\40\x20\142\162\145\x61\x6b\x2e\xa\12"), array("\143\x6f\155\x70\141\143\164", new \Exception("\x66\157\157"), "\40\105\170\x63\x65\160\164\151\157\156\x20\x20\146\157\157\56\12"), array("\x6d\x6f\x64\x65\162\x6e", new \Exception("\x62\141\x72"), "\12\x20\40\x20\105\x78\x63\x65\160\x74\x69\x6f\156\x20\40\142\141\162\x2e\xa\xa")); } public function testShellExecute($input, $expected) { $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig()); $shell->setOutput($output); $this->assertSame($expected, $shell->execute($input)); \rewind($stream); $this->assertSame('', \stream_get_contents($stream)); } public function getExecuteValues() { return array(array("\x72\x65\x74\165\162\156\x20\61\62", 12), array("\x22\x7b\x7b\162\145\164\x75\x72\x6e\40\x76\141\154\165\x65\175\175\x22", "\173\173\162\x65\x74\165\162\156\x20\x76\x61\154\x75\145\x7d\x7d"), array("\x31", 1)); } public function testHasCommand($command, $has) { $shell = new Shell($this->getConfig()); $refl = new \ReflectionClass(Shell::class); $method = $refl->getMethod("\150\141\163\x43\x6f\x6d\155\141\x6e\x64"); $method->setAccessible(true); $this->assertSame($method->invokeArgs($shell, array($command)), $has); } public function commandsToHas() { return array(array("\x68\x65\x6c\x70", true), array("\150\x65\154\x70\40\150\145\154\x70", true), array("\42\150\145\154\160\x22", false), array("\x22\x68\x65\x6c\x70\x20\150\x65\154\160\x22", false), array("\x6c\x73\x20\55\141\x6c\40", true), array("\154\x73\40\x22\x2d\141\x6c\42\x20", true), array("\154\x73\x22\55\x61\x6c\x22", false), array("\x20\161", true), array("\40\x20\x20\x71\x20\x20\55\x2d\x68\145\x6c\x70", true), array("\42\x71\42", false), array("\42\161\42\x2c", false)); } private function getInput($input) { $input = new StringInput($input); return $input; } private function getOutput() { $stream = \fopen("\x70\x68\160\x3a\57\x2f\x6d\145\x6d\157\x72\171", "\x77\53"); $this->streams[] = $stream; $output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, false); return $output; } private function getConfig(array $config = array()) { $dir = \tempnam(\sys_get_temp_dir(), "\160\163\x79\x73\x68\x5f\x73\x68\x65\x6c\x6c\137\164\x65\x73\x74\x5f"); \unlink($dir); $defaults = array("\143\x6f\x6e\146\x69\147\104\x69\x72" => $dir, "\x64\x61\x74\x61\104\x69\x72" => $dir, "\x72\165\156\x74\151\155\145\x44\x69\x72" => $dir, "\143\157\154\x6f\x72\x4d\157\144\145" => Configuration::COLOR_MODE_FORCED); return new Configuration(\array_merge($defaults, $config)); } public function testStrictTypesExecute() { $shell = new Shell($this->getConfig(array("\x73\164\162\x69\143\164\124\x79\160\x65\x73" => false))); $shell->setOutput($this->getOutput()); $shell->execute("\50\x66\x75\x6e\x63\164\x69\x6f\x6e\50\51\x3a\x20\x69\156\x74\40\173\40\162\x65\x74\165\x72\x6e\40\x31\x2e\x31\x3b\x20\x7d\x29\50\x29", true); $this->assertTrue(true); } public function testLaxTypesExecute() { $this->expectException(\TypeError::class); $shell = new Shell($this->getConfig(array("\x73\x74\x72\151\143\x74\x54\171\x70\x65\x73" => true))); $shell->setOutput($this->getOutput()); $shell->execute("\x28\x66\165\156\x63\x74\151\157\x6e\50\x29\x3a\40\151\x6e\164\40\x7b\40\x72\145\x74\x75\162\156\x20\x31\56\x31\73\40\175\51\x28\51", true); } }
Function Calls
| None |
Stats
| MD5 | 7fd390b12d56bce47a46b1795699ffd1 |
| Eval Count | 0 |
| Decode Time | 118 ms |