X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fpsy%2Fpsysh%2Ftest%2FPsy%2FTest%2FException%2FErrorExceptionTest.php;fp=vendor%2Fpsy%2Fpsysh%2Ftest%2FPsy%2FTest%2FException%2FErrorExceptionTest.php;h=f4ca54f2ece187effe975d0705efba7dc64bb539;hp=0000000000000000000000000000000000000000;hb=eba34333e3c89f208d2f72fa91351ad019a71583;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae diff --git a/vendor/psy/psysh/test/Psy/Test/Exception/ErrorExceptionTest.php b/vendor/psy/psysh/test/Psy/Test/Exception/ErrorExceptionTest.php new file mode 100644 index 000000000..f4ca54f2e --- /dev/null +++ b/vendor/psy/psysh/test/Psy/Test/Exception/ErrorExceptionTest.php @@ -0,0 +1,108 @@ +assertTrue($e instanceof Exception); + $this->assertTrue($e instanceof \ErrorException); + $this->assertTrue($e instanceof ErrorException); + } + + public function testMessage() + { + $e = new ErrorException('foo'); + + $this->assertContains('foo', $e->getMessage()); + $this->assertEquals('foo', $e->getRawMessage()); + } + + /** + * @dataProvider getLevels + */ + public function testErrorLevels($level, $type) + { + $e = new ErrorException('foo', 0, $level); + $this->assertContains('PHP ' . $type, $e->getMessage()); + } + + /** + * @dataProvider getLevels + */ + public function testThrowException($level, $type) + { + try { + ErrorException::throwException($level, '{whot}', '{file}', '13'); + } catch (ErrorException $e) { + $this->assertContains('PHP ' . $type, $e->getMessage()); + $this->assertContains('{whot}', $e->getMessage()); + $this->assertContains('in {file}', $e->getMessage()); + $this->assertContains('on line 13', $e->getMessage()); + } + } + + public function getLevels() + { + return array( + array(E_WARNING, 'warning'), + array(E_CORE_WARNING, 'warning'), + array(E_COMPILE_WARNING, 'warning'), + array(E_USER_WARNING, 'warning'), + array(E_STRICT, 'Strict error'), + array(0, 'error'), + ); + } + + /** + * @dataProvider getUserLevels + */ + public function testThrowExceptionAsErrorHandler($level, $type) + { + set_error_handler(array('Psy\Exception\ErrorException', 'throwException')); + try { + trigger_error('{whot}', $level); + } catch (ErrorException $e) { + $this->assertContains('PHP ' . $type, $e->getMessage()); + $this->assertContains('{whot}', $e->getMessage()); + } + restore_error_handler(); + } + + public function getUserLevels() + { + return array( + array(E_USER_ERROR, 'error'), + array(E_USER_WARNING, 'warning'), + array(E_USER_NOTICE, 'error'), + array(E_USER_DEPRECATED, 'error'), + ); + } + + public function testIgnoreExecutionLoopFilename() + { + $e = new ErrorException('{{message}}', 0, 1, '/fake/path/to/Psy/ExecutionLoop/Loop.php'); + $this->assertEmpty($e->getFile()); + + $e = new ErrorException('{{message}}', 0, 1, 'c:\fake\path\to\Psy\ExecutionLoop\Loop.php'); + $this->assertEmpty($e->getFile()); + + $e = new ErrorException('{{message}}', 0, 1, '/fake/path/to/Psy/File.php'); + $this->assertNotEmpty($e->getFile()); + } +}