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\TypeErrorException;
16 class TypeErrorExceptionTest extends \PHPUnit\Framework\TestCase
18 public function testException()
20 $e = new TypeErrorException('{{message}}', 13);
22 $this->assertInstanceOf('Psy\Exception\Exception', $e);
23 $this->assertInstanceOf('Psy\Exception\TypeErrorException', $e);
25 $this->assertEquals('TypeError: {{message}}', $e->getMessage());
26 $this->assertEquals('{{message}}', $e->getRawMessage());
27 $this->assertEquals(13, $e->getCode());
30 public function testStripsEvalFromMessage()
32 $message = 'Something or other, called in line 10: eval()\'d code';
33 $e = new TypeErrorException($message);
34 $this->assertEquals($message, $e->getRawMessage());
35 $this->assertEquals('TypeError: Something or other', $e->getMessage());
38 public function testFromTypeError()
40 if (version_compare(PHP_VERSION, '7.0.0', '<')) {
41 $this->markTestSkipped();
44 $previous = new \TypeError('{{message}}', 13);
45 $e = TypeErrorException::fromTypeError($previous);
47 $this->assertInstanceOf('Psy\Exception\TypeErrorException', $e);
48 $this->assertEquals('TypeError: {{message}}', $e->getMessage());
49 $this->assertEquals('{{message}}', $e->getRawMessage());
50 $this->assertEquals(13, $e->getCode());