public function tearDown()
{
foreach ($this->streams as $stream) {
- fclose($stream);
+ \fclose($stream);
}
}
$_e = 'ignore this';
$shell = new Shell($this->getConfig());
- $shell->setScopeVariables(compact('one', 'two', 'three', '__psysh__', '_', '_e', 'this'));
+ $shell->setScopeVariables(\compact('one', 'two', 'three', '__psysh__', '_', '_e', 'this'));
$this->assertNotContains('__psysh__', $shell->getScopeVariableNames());
$this->assertSame(['one', 'two', 'three', '_'], $shell->getScopeVariableNames());
$this->assertSame($three, $shell->getScopeVariable('three'));
$this->assertNull($shell->getScopeVariable('_'));
+ $diff = $shell->getScopeVariablesDiff(['one' => $one, 'two' => 'not two']);
+ $this->assertSame(['two' => $two, 'three' => $three, '_' => null], $diff);
+
$shell->setScopeVariables([]);
$this->assertSame(['_'], $shell->getScopeVariableNames());
$config = $this->getConfig(['usePcntl' => false]);
$shell = new Shell($config);
- $shell->setScopeVariables(compact('one', 'two', 'three', '__psysh__', '_', '_e', 'this'));
+ $shell->setScopeVariables(\compact('one', 'two', 'three', '__psysh__', '_', '_e', 'this'));
$shell->addInput('exit', true);
// This is super slow and we shouldn't do this :(
$this->assertFalse($shell->hasCode());
$this->assertEmpty($shell->getCodeBuffer());
- rewind($stream);
- $streamContents = stream_get_contents($stream);
+ \rewind($stream);
+ $streamContents = \stream_get_contents($stream);
$this->assertContains('PHP Parse error', $streamContents);
$this->assertContains('message', $streamContents);
$stream = $output->getStream();
$shell->setOutput($output);
- $oldLevel = error_reporting();
- error_reporting($oldLevel & ~E_USER_NOTICE);
+ $oldLevel = \error_reporting();
+ \error_reporting($oldLevel & ~E_USER_NOTICE);
try {
$shell->handleError(E_USER_NOTICE, 'wheee', null, 13);
} catch (ErrorException $e) {
- error_reporting($oldLevel);
+ \error_reporting($oldLevel);
$this->fail('Unexpected error exception');
}
- error_reporting($oldLevel);
+ \error_reporting($oldLevel);
- rewind($stream);
- $streamContents = stream_get_contents($stream);
+ \rewind($stream);
+ $streamContents = \stream_get_contents($stream);
$this->assertContains('PHP Notice:', $streamContents);
$this->assertContains('wheee', $streamContents);
public function testNotHandlingErrors()
{
$shell = new Shell($this->getConfig());
- $oldLevel = error_reporting();
- error_reporting($oldLevel | E_USER_NOTICE);
+ $oldLevel = \error_reporting();
+ \error_reporting($oldLevel | E_USER_NOTICE);
try {
$shell->handleError(E_USER_NOTICE, 'wheee', null, 13);
} catch (ErrorException $e) {
- error_reporting($oldLevel);
+ \error_reporting($oldLevel);
throw $e;
}
}
$this->assertInstanceOf('Symfony\Component\Console\Application', $shell);
$this->assertContains(Shell::VERSION, $shell->getVersion());
- $this->assertContains(phpversion(), $shell->getVersion());
- $this->assertContains(php_sapi_name(), $shell->getVersion());
+ $this->assertContains(PHP_VERSION, $shell->getVersion());
+ $this->assertContains(PHP_SAPI, $shell->getVersion());
}
public function testCodeBuffer()
$shell->addCode('{}');
$code = $shell->flushCode();
$this->assertFalse($shell->hasCode());
- $code = preg_replace('/\s+/', ' ', $code);
+ $code = \preg_replace('/\s+/', ' ', $code);
$this->assertNotNull($code);
$this->assertSame('class a { } return new \\Psy\\CodeCleaner\\NoReturnValue();', $code);
}
$shell->addCode('+ 1');
$code = $shell->flushCode();
$this->assertFalse($shell->hasCode());
- $code = preg_replace('/\s+/', ' ', $code);
+ $code = \preg_replace('/\s+/', ' ', $code);
$this->assertNotNull($code);
$this->assertSame('return 1 + 1 + 1;', $code);
}
$shell->writeStdout("{{stdout}}\n");
- rewind($stream);
- $streamContents = stream_get_contents($stream);
+ \rewind($stream);
+ $streamContents = \stream_get_contents($stream);
$this->assertSame('{{stdout}}' . PHP_EOL, $streamContents);
}
$shell->writeStdout('{{stdout}}');
- rewind($stream);
- $streamContents = stream_get_contents($stream);
+ \rewind($stream);
+ $streamContents = \stream_get_contents($stream);
$this->assertSame('{{stdout}}<aside>⏎</aside>' . PHP_EOL, $streamContents);
}
$shell->setOutput($output);
$shell->writeReturnValue($input);
- rewind($stream);
- $this->assertEquals($expected, stream_get_contents($stream));
+ \rewind($stream);
+ $this->assertEquals($expected, \stream_get_contents($stream));
}
public function getReturnValues()
$shell->setOutput($output);
$shell->writeException($exception);
- rewind($stream);
- $this->assertSame($expected, stream_get_contents($stream));
+ \rewind($stream);
+ $this->assertSame($expected, \stream_get_contents($stream));
}
public function getRenderedExceptions()
$shell = new Shell($this->getConfig());
$shell->setOutput($output);
$this->assertEquals($expected, $shell->execute($input));
- rewind($stream);
- $this->assertSame('', stream_get_contents($stream));
+ \rewind($stream);
+ $this->assertSame('', \stream_get_contents($stream));
}
public function getExecuteValues()
private function getOutput()
{
- $stream = fopen('php://memory', 'w+');
+ $stream = \fopen('php://memory', 'w+');
$this->streams[] = $stream;
$output = new StreamOutput($stream, StreamOutput::VERBOSITY_NORMAL, false);
private function getConfig(array $config = [])
{
// Mebbe there's a better way than this?
- $dir = tempnam(sys_get_temp_dir(), 'psysh_shell_test_');
- unlink($dir);
+ $dir = \tempnam(\sys_get_temp_dir(), 'psysh_shell_test_');
+ \unlink($dir);
$defaults = [
'configDir' => $dir,
'runtimeDir' => $dir,
];
- return new Configuration(array_merge($defaults, $config));
+ return new Configuration(\array_merge($defaults, $config));
}
}