Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/test/Command/ThrowUpCommandTest.php @ 16:c2387f117808
Routine composer update
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 15:07:59 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:e200cb7efeb3 | 16:c2387f117808 |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of Psy Shell. | |
5 * | |
6 * (c) 2012-2018 Justin Hileman | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Symfony\Component\Console\Tests\Command; | |
13 | |
14 use Psy\Command\ThrowUpCommand; | |
15 use Psy\Shell; | |
16 use Symfony\Component\Console\Tester\CommandTester; | |
17 | |
18 class ThrowUpCommandTest extends \PHPUnit\Framework\TestCase | |
19 { | |
20 /** | |
21 * @dataProvider executeThis | |
22 */ | |
23 public function testExecute($args, $hasCode, $expect, $addSilent = true) | |
24 { | |
25 $shell = $this->getMockBuilder('Psy\\Shell') | |
26 ->setMethods(['hasCode', 'addCode']) | |
27 ->getMock(); | |
28 | |
29 $shell->expects($this->once())->method('hasCode')->willReturn($hasCode); | |
30 $shell->expects($this->once()) | |
31 ->method('addCode') | |
32 ->with($this->equalTo($expect), $this->equalTo($addSilent)); | |
33 | |
34 $command = new ThrowUpCommand(); | |
35 $command->setApplication($shell); | |
36 $tester = new CommandTester($command); | |
37 $tester->execute($args); | |
38 $this->assertEquals('', $tester->getDisplay()); | |
39 } | |
40 | |
41 public function executeThis() | |
42 { | |
43 $throw = 'throw \Psy\Exception\ThrowUpException::fromThrowable'; | |
44 | |
45 return [ | |
46 [[], false, $throw . '($_e);'], | |
47 | |
48 [['exception' => '$ex'], false, $throw . '($ex);'], | |
49 [['exception' => 'getException()'], false, $throw . '(getException());'], | |
50 [['exception' => 'new \\Exception("WAT")'], false, $throw . '(new \\Exception("WAT"));'], | |
51 | |
52 [['exception' => '\'some string\''], false, $throw . '(new \\Exception(\'some string\'));'], | |
53 [['exception' => '"WHEEEEEEE!"'], false, $throw . '(new \\Exception("WHEEEEEEE!"));'], | |
54 | |
55 // Everything should work with or without semicolons. | |
56 [['exception' => '$ex;'], false, $throw . '($ex);'], | |
57 [['exception' => '"WHEEEEEEE!";'], false, $throw . '(new \\Exception("WHEEEEEEE!"));'], | |
58 | |
59 // Don't add as silent code if we've already got code. | |
60 [[], true, $throw . '($_e);', false], | |
61 [['exception' => 'getException()'], true, $throw . '(getException());', false], | |
62 [['exception' => '\'some string\''], true, $throw . '(new \\Exception(\'some string\'));', false], | |
63 ]; | |
64 } | |
65 | |
66 /** | |
67 * @expectedException \InvalidArgumentException | |
68 * @expectedExceptionMessage No idea how to throw this | |
69 */ | |
70 public function testMultipleArgsThrowsException() | |
71 { | |
72 $command = new ThrowUpCommand(); | |
73 $command->setApplication(new Shell()); | |
74 $tester = new CommandTester($command); | |
75 $tester->execute(['exception' => 'foo(); bar()']); | |
76 } | |
77 | |
78 /** | |
79 * @expectedException \PhpParser\Error | |
80 * @expectedExceptionMessage Syntax error, unexpected ')' on line 1 | |
81 */ | |
82 public function testParseErrorThrowsException() | |
83 { | |
84 $command = new ThrowUpCommand(); | |
85 $command->setApplication(new Shell()); | |
86 $tester = new CommandTester($command); | |
87 $tester->execute(['exception' => 'foo)']); | |
88 } | |
89 } |