Chris@16
|
1 <?php
|
Chris@16
|
2
|
Chris@16
|
3 /*
|
Chris@16
|
4 * This file is part of Psy Shell.
|
Chris@16
|
5 *
|
Chris@16
|
6 * (c) 2012-2018 Justin Hileman
|
Chris@16
|
7 *
|
Chris@16
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@16
|
9 * file that was distributed with this source code.
|
Chris@16
|
10 */
|
Chris@16
|
11
|
Chris@16
|
12 namespace Psy\Test\Exception;
|
Chris@16
|
13
|
Chris@16
|
14 use Psy\Exception\ThrowUpException;
|
Chris@16
|
15
|
Chris@16
|
16 class ThrowUpExceptionTest extends \PHPUnit\Framework\TestCase
|
Chris@16
|
17 {
|
Chris@16
|
18 public function testException()
|
Chris@16
|
19 {
|
Chris@16
|
20 $previous = new \Exception('{{message}}', 123);
|
Chris@16
|
21 $e = new ThrowUpException($previous);
|
Chris@16
|
22
|
Chris@16
|
23 $this->assertInstanceOf('Psy\Exception\Exception', $e);
|
Chris@16
|
24 $this->assertInstanceOf('Psy\Exception\ThrowUpException', $e);
|
Chris@16
|
25
|
Chris@16
|
26 $this->assertEquals("Throwing Exception with message '{{message}}'", $e->getMessage());
|
Chris@16
|
27 $this->assertEquals('{{message}}', $e->getRawMessage());
|
Chris@16
|
28 $this->assertEquals(123, $e->getCode());
|
Chris@16
|
29 $this->assertSame($previous, $e->getPrevious());
|
Chris@16
|
30 }
|
Chris@16
|
31
|
Chris@16
|
32 public function testFromThrowable()
|
Chris@16
|
33 {
|
Chris@16
|
34 $previous = new \Exception('{{message}}');
|
Chris@16
|
35 $e = ThrowUpException::fromThrowable($previous);
|
Chris@16
|
36
|
Chris@16
|
37 $this->assertInstanceOf('Psy\Exception\ThrowUpException', $e);
|
Chris@16
|
38 $this->assertSame($previous, $e->getPrevious());
|
Chris@16
|
39 }
|
Chris@16
|
40
|
Chris@16
|
41 public function testFromThrowableWithError()
|
Chris@16
|
42 {
|
Chris@17
|
43 if (\version_compare(PHP_VERSION, '7.0.0', '<')) {
|
Chris@16
|
44 $this->markTestSkipped();
|
Chris@16
|
45 }
|
Chris@16
|
46
|
Chris@16
|
47 $previous = new \Error('{{message}}');
|
Chris@16
|
48 $e = ThrowUpException::fromThrowable($previous);
|
Chris@16
|
49
|
Chris@16
|
50 $this->assertInstanceOf('Psy\Exception\ThrowUpException', $e);
|
Chris@16
|
51 $this->assertInstanceOf('Psy\Exception\ErrorException', $e->getPrevious());
|
Chris@16
|
52
|
Chris@16
|
53 $this->assertNotSame($previous, $e->getPrevious());
|
Chris@16
|
54 $this->assertSame($previous, $e->getPrevious()->getPrevious());
|
Chris@16
|
55 }
|
Chris@16
|
56
|
Chris@16
|
57 /**
|
Chris@16
|
58 * @expectedException \InvalidArgumentException
|
Chris@16
|
59 * @expectedExceptionMessage throw-up can only throw Exceptions and Errors
|
Chris@16
|
60 */
|
Chris@16
|
61 public function testFromThrowableThrowsError()
|
Chris@16
|
62 {
|
Chris@16
|
63 $notThrowable = new \StdClass();
|
Chris@16
|
64 ThrowUpException::fromThrowable($notThrowable);
|
Chris@16
|
65 }
|
Chris@16
|
66 }
|