Chris@16: getMockBuilder('Psy\\Shell') Chris@16: ->setMethods(['hasCode', 'addCode']) Chris@16: ->getMock(); Chris@16: Chris@16: $shell->expects($this->once())->method('hasCode')->willReturn($hasCode); Chris@16: $shell->expects($this->once()) Chris@16: ->method('addCode') Chris@16: ->with($this->equalTo($expect), $this->equalTo($addSilent)); Chris@16: Chris@16: $command = new ThrowUpCommand(); Chris@16: $command->setApplication($shell); Chris@16: $tester = new CommandTester($command); Chris@16: $tester->execute($args); Chris@16: $this->assertEquals('', $tester->getDisplay()); Chris@16: } Chris@16: Chris@16: public function executeThis() Chris@16: { Chris@16: $throw = 'throw \Psy\Exception\ThrowUpException::fromThrowable'; Chris@16: Chris@16: return [ Chris@16: [[], false, $throw . '($_e);'], Chris@16: Chris@16: [['exception' => '$ex'], false, $throw . '($ex);'], Chris@16: [['exception' => 'getException()'], false, $throw . '(getException());'], Chris@16: [['exception' => 'new \\Exception("WAT")'], false, $throw . '(new \\Exception("WAT"));'], Chris@16: Chris@16: [['exception' => '\'some string\''], false, $throw . '(new \\Exception(\'some string\'));'], Chris@16: [['exception' => '"WHEEEEEEE!"'], false, $throw . '(new \\Exception("WHEEEEEEE!"));'], Chris@16: Chris@16: // Everything should work with or without semicolons. Chris@16: [['exception' => '$ex;'], false, $throw . '($ex);'], Chris@16: [['exception' => '"WHEEEEEEE!";'], false, $throw . '(new \\Exception("WHEEEEEEE!"));'], Chris@16: Chris@16: // Don't add as silent code if we've already got code. Chris@16: [[], true, $throw . '($_e);', false], Chris@16: [['exception' => 'getException()'], true, $throw . '(getException());', false], Chris@16: [['exception' => '\'some string\''], true, $throw . '(new \\Exception(\'some string\'));', false], Chris@16: ]; Chris@16: } Chris@16: Chris@16: /** Chris@16: * @expectedException \InvalidArgumentException Chris@16: * @expectedExceptionMessage No idea how to throw this Chris@16: */ Chris@16: public function testMultipleArgsThrowsException() Chris@16: { Chris@16: $command = new ThrowUpCommand(); Chris@16: $command->setApplication(new Shell()); Chris@16: $tester = new CommandTester($command); Chris@16: $tester->execute(['exception' => 'foo(); bar()']); Chris@16: } Chris@16: Chris@16: /** Chris@16: * @expectedException \PhpParser\Error Chris@16: * @expectedExceptionMessage Syntax error, unexpected ')' on line 1 Chris@16: */ Chris@16: public function testParseErrorThrowsException() Chris@16: { Chris@16: $command = new ThrowUpCommand(); Chris@16: $command->setApplication(new Shell()); Chris@16: $tester = new CommandTester($command); Chris@16: $tester->execute(['exception' => 'foo)']); Chris@16: } Chris@16: }