4 * This file is part of Psy Shell.
6 * (c) 2012-2018 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Psy\Test\Exception;
14 use Psy\Exception\ThrowUpException;
16 class ThrowUpExceptionTest extends \PHPUnit\Framework\TestCase
18 public function testException()
20 $previous = new \Exception('{{message}}', 123);
21 $e = new ThrowUpException($previous);
23 $this->assertInstanceOf('Psy\Exception\Exception', $e);
24 $this->assertInstanceOf('Psy\Exception\ThrowUpException', $e);
26 $this->assertEquals("Throwing Exception with message '{{message}}'", $e->getMessage());
27 $this->assertEquals('{{message}}', $e->getRawMessage());
28 $this->assertEquals(123, $e->getCode());
29 $this->assertSame($previous, $e->getPrevious());
32 public function testFromThrowable()
34 $previous = new \Exception('{{message}}');
35 $e = ThrowUpException::fromThrowable($previous);
37 $this->assertInstanceOf('Psy\Exception\ThrowUpException', $e);
38 $this->assertSame($previous, $e->getPrevious());
41 public function testFromThrowableWithError()
43 if (version_compare(PHP_VERSION, '7.0.0', '<')) {
44 $this->markTestSkipped();
47 $previous = new \Error('{{message}}');
48 $e = ThrowUpException::fromThrowable($previous);
50 $this->assertInstanceOf('Psy\Exception\ThrowUpException', $e);
51 $this->assertInstanceOf('Psy\Exception\ErrorException', $e->getPrevious());
53 $this->assertNotSame($previous, $e->getPrevious());
54 $this->assertSame($previous, $e->getPrevious()->getPrevious());
58 * @expectedException \InvalidArgumentException
59 * @expectedExceptionMessage throw-up can only throw Exceptions and Errors
61 public function testFromThrowableThrowsError()
63 $notThrowable = new \StdClass();
64 ThrowUpException::fromThrowable($notThrowable);