Updated from some -dev modules to alpha, beta or full releases
[yaffs-website] / vendor / psy / psysh / test / Exception / ThrowUpExceptionTest.php
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 Psy\Test\Exception;
13
14 use Psy\Exception\ThrowUpException;
15
16 class ThrowUpExceptionTest extends \PHPUnit\Framework\TestCase
17 {
18     public function testException()
19     {
20         $previous = new \Exception('{{message}}', 123);
21         $e = new ThrowUpException($previous);
22
23         $this->assertInstanceOf('Psy\Exception\Exception', $e);
24         $this->assertInstanceOf('Psy\Exception\ThrowUpException', $e);
25
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());
30     }
31
32     public function testFromThrowable()
33     {
34         $previous = new \Exception('{{message}}');
35         $e = ThrowUpException::fromThrowable($previous);
36
37         $this->assertInstanceOf('Psy\Exception\ThrowUpException', $e);
38         $this->assertSame($previous, $e->getPrevious());
39     }
40
41     public function testFromThrowableWithError()
42     {
43         if (version_compare(PHP_VERSION, '7.0.0', '<')) {
44             $this->markTestSkipped();
45         }
46
47         $previous = new \Error('{{message}}');
48         $e = ThrowUpException::fromThrowable($previous);
49
50         $this->assertInstanceOf('Psy\Exception\ThrowUpException', $e);
51         $this->assertInstanceOf('Psy\Exception\ErrorException', $e->getPrevious());
52
53         $this->assertNotSame($previous, $e->getPrevious());
54         $this->assertSame($previous, $e->getPrevious()->getPrevious());
55     }
56
57     /**
58      * @expectedException \InvalidArgumentException
59      * @expectedExceptionMessage throw-up can only throw Exceptions and Errors
60      */
61     public function testFromThrowableThrowsError()
62     {
63         $notThrowable = new \StdClass();
64         ThrowUpException::fromThrowable($notThrowable);
65     }
66 }