annotate vendor/psy/psysh/test/Exception/ThrowUpExceptionTest.php @ 4:a9cd425dd02b

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