How to use exception class

Best Atoum code snippet using exception

ExceptionRendererTest.php

Source:ExceptionRendererTest.php Github

copy

Full Screen

...183 * @return void184 */185 public function testSubclassMethodsNotBeingConvertedToError()186 {187 $exception = new MissingWidgetThingException('Widget not found');188 $ExceptionRenderer = $this->_mockResponse(new MyCustomExceptionRenderer($exception));189 $result = $ExceptionRenderer->render();190 $this->assertEquals('widget thing is missing', $result->body());191 }192 /**193 * test that subclass methods are not converted when debug = 0194 *195 * @return void196 */197 public function testSubclassMethodsNotBeingConvertedDebug0()198 {199 Configure::write('debug', false);200 $exception = new MissingWidgetThingException('Widget not found');201 $ExceptionRenderer = $this->_mockResponse(new MyCustomExceptionRenderer($exception));202 $result = $ExceptionRenderer->render();203 $this->assertEquals('missingWidgetThing', $ExceptionRenderer->method);204 $this->assertEquals(205 'widget thing is missing',206 $result->body(),207 'Method declared in subclass converted to error400'208 );209 }210 /**211 * test that ExceptionRenderer subclasses properly convert framework errors.212 *213 * @return void214 */215 public function testSubclassConvertingFrameworkErrors()216 {217 Configure::write('debug', false);218 $exception = new MissingControllerException('PostsController');219 $ExceptionRenderer = $this->_mockResponse(new MyCustomExceptionRenderer($exception));220 $result = $ExceptionRenderer->render();221 $this->assertRegExp(222 '/Not Found/',223 $result->body(),224 'Method declared in error handler not converted to error400. %s'225 );226 }227 /**228 * test things in the constructor.229 *230 * @return void231 */232 public function testConstruction()233 {234 $exception = new NotFoundException('Page not found');235 $ExceptionRenderer = new ExceptionRenderer($exception);236 $this->assertInstanceOf('Cake\Controller\ErrorController', $ExceptionRenderer->controller);237 $this->assertEquals($exception, $ExceptionRenderer->error);238 }239 /**240 * test that exception message gets coerced when debug = 0241 *242 * @return void243 */244 public function testExceptionMessageCoercion()245 {246 Configure::write('debug', false);247 $exception = new MissingActionException('Secret info not to be leaked');248 $ExceptionRenderer = $this->_mockResponse(new ExceptionRenderer($exception));249 $this->assertInstanceOf('Cake\Controller\ErrorController', $ExceptionRenderer->controller);250 $this->assertEquals($exception, $ExceptionRenderer->error);251 $result = $ExceptionRenderer->render()->body();252 $this->assertEquals('error400', $ExceptionRenderer->template);253 $this->assertContains('Not Found', $result);254 $this->assertNotContains('Secret info not to be leaked', $result);255 }256 /**257 * test that helpers in custom CakeErrorController are not lost258 *259 * @return void260 */261 public function testCakeErrorHelpersNotLost()262 {263 Configure::write('App.namespace', 'TestApp');264 $exception = new SocketException('socket exception');265 $renderer = $this->_mockResponse(new \TestApp\Error\TestAppsExceptionRenderer($exception));266 $result = $renderer->render();267 $this->assertContains('<b>peeled</b>', $result->body());268 }269 /**270 * test that unknown exception types with valid status codes are treated correctly.271 *272 * @return void273 */274 public function testUnknownExceptionTypeWithExceptionThatHasA400Code()275 {276 $exception = new MissingWidgetThingException('coding fail.');277 $ExceptionRenderer = new ExceptionRenderer($exception);278 $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')279 ->setMethods(['statusCode', '_sendHeader'])280 ->getMock();281 $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(404);282 $result = $ExceptionRenderer->render();283 $this->assertFalse(method_exists($ExceptionRenderer, 'missingWidgetThing'), 'no method should exist.');284 $this->assertContains('coding fail', $result->body(), 'Text should show up.');285 }286 /**287 * test that unknown exception types with valid status codes are treated correctly.288 *289 * @return void290 */291 public function testUnknownExceptionTypeWithNoCodeIsA500()292 {293 $exception = new \OutOfBoundsException('foul ball.');294 $ExceptionRenderer = new ExceptionRenderer($exception);295 $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')296 ->setMethods(['statusCode', '_sendHeader'])297 ->getMock();298 $ExceptionRenderer->controller->response->expects($this->once())299 ->method('statusCode')300 ->with(500);301 $result = $ExceptionRenderer->render();302 $this->assertContains('foul ball.', $result->body(), 'Text should show up as its debug mode.');303 }304 /**305 * test that unknown exceptions have messages ignored.306 *307 * @return void308 */309 public function testUnknownExceptionInProduction()310 {311 Configure::write('debug', false);312 $exception = new \OutOfBoundsException('foul ball.');313 $ExceptionRenderer = new ExceptionRenderer($exception);314 $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')315 ->setMethods(['statusCode', '_sendHeader'])316 ->getMock();317 $ExceptionRenderer->controller->response->expects($this->once())318 ->method('statusCode')319 ->with(500);320 $result = $ExceptionRenderer->render()->body();321 $this->assertNotContains('foul ball.', $result, 'Text should no show up.');322 $this->assertContains('Internal Error', $result, 'Generic message only.');323 }324 /**325 * test that unknown exception types with valid status codes are treated correctly.326 *327 * @return void328 */329 public function testUnknownExceptionTypeWithCodeHigherThan500()330 {331 $exception = new \OutOfBoundsException('foul ball.', 501);332 $ExceptionRenderer = new ExceptionRenderer($exception);333 $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')334 ->setMethods(['statusCode', '_sendHeader'])335 ->getMock();336 $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(501);337 $result = $ExceptionRenderer->render();338 $this->assertContains('foul ball.', $result->body(), 'Text should show up as its debug mode.');339 }340 /**341 * testerror400 method342 *343 * @return void344 */345 public function testError400()346 {347 Router::reload();348 $request = new ServerRequest('posts/view/1000');349 Router::setRequestInfo($request);350 $exception = new NotFoundException('Custom message');351 $ExceptionRenderer = new ExceptionRenderer($exception);352 $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')353 ->setMethods(['statusCode', '_sendHeader'])354 ->getMock();355 $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(404);356 $result = $ExceptionRenderer->render()->body();357 $this->assertContains('<h2>Custom message</h2>', $result);358 $this->assertRegExp("/<strong>'.*?\/posts\/view\/1000'<\/strong>/", $result);359 }360 /**361 * testerror400 method when returning as json362 *363 * @return void364 */365 public function testError400AsJson()366 {367 Router::reload();368 $request = new ServerRequest('posts/view/1000?sort=title&direction=desc');369 $request = $request->withHeader('Accept', 'application/json');370 $request = $request->withHeader('Content-Type', 'application/json');371 Router::setRequestInfo($request);372 $exception = new NotFoundException('Custom message');373 $exceptionLine = __LINE__ - 1;374 $ExceptionRenderer = new ExceptionRenderer($exception);375 $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Network\Response')376 ->setMethods(['statusCode', '_sendHeader'])377 ->getMock();378 $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(404);379 $result = $ExceptionRenderer->render()->body();380 $expected = [381 'message' => 'Custom message',382 'url' => '/posts/view/1000?sort=title&amp;direction=desc',383 'code' => 404,384 'file' => __FILE__,385 'line' => $exceptionLine386 ];387 $this->assertEquals($expected, json_decode($result, true));388 }389 /**390 * test that error400 only modifies the messages on Cake Exceptions.391 *392 * @return void393 */394 public function testerror400OnlyChangingCakeException()395 {396 Configure::write('debug', false);397 $exception = new NotFoundException('Custom message');398 $ExceptionRenderer = $this->_mockResponse(new ExceptionRenderer($exception));399 $result = $ExceptionRenderer->render();400 $this->assertContains('Custom message', $result->body());401 $exception = new MissingActionException(['controller' => 'PostsController', 'action' => 'index']);402 $ExceptionRenderer = $this->_mockResponse(new ExceptionRenderer($exception));403 $result = $ExceptionRenderer->render();404 $this->assertContains('Not Found', $result->body());405 }406 /**407 * test that error400 doesn't expose XSS408 *409 * @return void410 */411 public function testError400NoInjection()412 {413 Router::reload();414 $request = new ServerRequest('pages/<span id=333>pink</span></id><script>document.body.style.background = t=document.getElementById(333).innerHTML;window.alert(t);</script>');415 Router::setRequestInfo($request);416 $exception = new NotFoundException('Custom message');417 $ExceptionRenderer = $this->_mockResponse(new ExceptionRenderer($exception));418 $result = $ExceptionRenderer->render()->body();419 $this->assertNotContains('<script>document', $result);420 $this->assertNotContains('alert(t);</script>', $result);421 }422 /**423 * testError500 method424 *425 * @return void426 */427 public function testError500Message()428 {429 $exception = new InternalErrorException('An Internal Error Has Occurred.');430 $ExceptionRenderer = new ExceptionRenderer($exception);431 $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')432 ->setMethods(['statusCode', '_sendHeader'])433 ->getMock();434 $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(500);435 $result = $ExceptionRenderer->render();436 $this->assertContains('<h2>An Internal Error Has Occurred.</h2>', $result->body());437 $this->assertContains('An Internal Error Has Occurred.</p>', $result->body());438 }439 /**440 * testExceptionResponseHeader method441 *442 * @return void443 */444 public function testExceptionResponseHeader()445 {446 $exception = new MethodNotAllowedException('Only allowing POST and DELETE');447 $exception->responseHeader(['Allow: POST, DELETE']);448 $ExceptionRenderer = new ExceptionRenderer($exception);449 $result = $ExceptionRenderer->render();450 $headers = $result->header();451 $this->assertArrayHasKey('Allow', $headers);452 $this->assertEquals('POST, DELETE', $headers['Allow']);453 }454 /**455 * testMissingController method456 *457 * @return void458 */459 public function testMissingController()460 {461 $exception = new MissingControllerException([462 'class' => 'Posts',463 'prefix' => '',464 'plugin' => '',465 ]);466 $ExceptionRenderer = $this->_mockResponse(new MyCustomExceptionRenderer($exception));467 $result = $ExceptionRenderer->render()->body();468 $this->assertEquals('missingController', $ExceptionRenderer->template);469 $this->assertContains('Missing Controller', $result);470 $this->assertContains('<em>PostsController</em>', $result);471 }472 /**473 * Returns an array of tests to run for the various Cake Exception classes.474 *475 * @return array476 */477 public static function exceptionProvider()478 {479 return [480 [481 new MissingActionException([482 'controller' => 'PostsController',483 'action' => 'index',484 'prefix' => '',485 'plugin' => '',486 ]),487 [488 '/Missing Method in PostsController/',489 '/<em>PostsController::index\(\)<\/em>/'490 ],491 404492 ],493 [494 new MissingTemplateException(['file' => '/posts/about.ctp']),495 [496 "/posts\/about.ctp/"497 ],498 500499 ],500 [501 new MissingLayoutException(['file' => 'layouts/my_layout.ctp']),502 [503 "/Missing Layout/",504 "/layouts\/my_layout.ctp/"505 ],506 500507 ],508 [509 new MissingHelperException(['class' => 'MyCustomHelper']),510 [511 '/Missing Helper/',512 '/<em>MyCustomHelper<\/em> could not be found./',513 '/Create the class <em>MyCustomHelper<\/em> below in file:/',514 '/(\/|\\\)MyCustomHelper.php/'515 ],516 500517 ],518 [519 new MissingBehaviorException(['class' => 'MyCustomBehavior']),520 [521 '/Missing Behavior/',522 '/Create the class <em>MyCustomBehavior<\/em> below in file:/',523 '/(\/|\\\)MyCustomBehavior.php/'524 ],525 500526 ],527 [528 new MissingComponentException(['class' => 'SideboxComponent']),529 [530 '/Missing Component/',531 '/Create the class <em>SideboxComponent<\/em> below in file:/',532 '/(\/|\\\)SideboxComponent.php/'533 ],534 500535 ],536 [537 new MissingDatasourceConfigException(['name' => 'MyDatasourceConfig']),538 [539 '/Missing Datasource Configuration/',540 '/<em>MyDatasourceConfig<\/em> was not found/'541 ],542 500543 ],544 [545 new MissingDatasourceException(['class' => 'MyDatasource', 'plugin' => 'MyPlugin']),546 [547 '/Missing Datasource/',548 '/<em>MyPlugin.MyDatasource<\/em> could not be found./'549 ],550 500551 ],552 [553 new MissingMailerActionException([554 'mailer' => 'UserMailer',555 'action' => 'welcome',556 'prefix' => '',557 'plugin' => '',558 ]),559 [560 '/Missing Method in UserMailer/',561 '/<em>UserMailer::welcome\(\)<\/em>/'562 ],563 404564 ],565 [566 new Exception('boom'),567 [568 '/Internal Error/'569 ],570 500571 ],572 [573 new RuntimeException('another boom'),574 [575 '/Internal Error/'576 ],577 500578 ],579 [580 new CakeException('base class'),581 ['/Internal Error/'],582 500583 ]584 ];585 }586 /**587 * Test the various Cake Exception sub classes588 *589 * @dataProvider exceptionProvider590 * @return void591 */592 public function testCakeExceptionHandling($exception, $patterns, $code)593 {594 $ExceptionRenderer = new ExceptionRenderer($exception);595 $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')596 ->setMethods(['statusCode', '_sendHeader'])597 ->getMock();598 $ExceptionRenderer->controller->response->expects($this->once())599 ->method('statusCode')600 ->with($code);601 $result = $ExceptionRenderer->render()->body();602 foreach ($patterns as $pattern) {603 $this->assertRegExp($pattern, $result);604 }605 }606 /**607 * Test that class names not ending in Exception are not mangled.608 *609 * @return void610 */611 public function testExceptionNameMangling()612 {613 $exceptionRenderer = new MyCustomExceptionRenderer(new MissingWidgetThing());614 $result = $exceptionRenderer->render()->body();615 $this->assertContains('widget thing is missing', $result);616 }617 /**618 * Test exceptions being raised when helpers are missing.619 *620 * @return void621 */622 public function testMissingRenderSafe()623 {624 $exception = new MissingHelperException(['class' => 'Fail']);625 $ExceptionRenderer = new ExceptionRenderer($exception);626 $ExceptionRenderer->controller = $this->getMockBuilder('Cake\Controller\Controller')627 ->setMethods(['render'])628 ->getMock();629 $ExceptionRenderer->controller->helpers = ['Fail', 'Boom'];630 $ExceptionRenderer->controller->request = new ServerRequest;631 $ExceptionRenderer->controller->expects($this->at(0))632 ->method('render')633 ->with('missingHelper')634 ->will($this->throwException($exception));635 $response = $this->getMockBuilder('Cake\Http\Response')->getMock();636 $response->expects($this->once())637 ->method('body')638 ->with($this->stringContains('Helper class Fail'));639 $ExceptionRenderer->controller->response = $response;640 $ExceptionRenderer->render();641 sort($ExceptionRenderer->controller->helpers);642 $this->assertEquals(['Form', 'Html'], $ExceptionRenderer->controller->helpers);643 }644 /**645 * Test that exceptions in beforeRender() are handled by outputMessageSafe646 *647 * @return void648 */649 public function testRenderExceptionInBeforeRender()650 {651 $exception = new NotFoundException('Not there, sorry');652 $ExceptionRenderer = new ExceptionRenderer($exception);653 $ExceptionRenderer->controller = $this->getMockBuilder('Cake\Controller\Controller')654 ->setMethods(['beforeRender'])655 ->getMock();656 $ExceptionRenderer->controller->request = new ServerRequest;657 $ExceptionRenderer->controller->expects($this->any())658 ->method('beforeRender')659 ->will($this->throwException($exception));660 $response = $this->getMockBuilder('Cake\Http\Response')->getMock();661 $response->expects($this->once())662 ->method('body')663 ->with($this->stringContains('Not there, sorry'));664 $ExceptionRenderer->controller->response = $response;665 $ExceptionRenderer->render();666 }667 /**668 * Test that missing layoutPath don't cause other fatal errors.669 *670 * @return void671 */672 public function testMissingLayoutPathRenderSafe()673 {674 $this->called = false;675 $exception = new NotFoundException();676 $ExceptionRenderer = new ExceptionRenderer($exception);677 $ExceptionRenderer->controller = new Controller();678 $ExceptionRenderer->controller->helpers = ['Fail', 'Boom'];679 $ExceptionRenderer->controller->eventManager()->on(680 'Controller.beforeRender',681 function (Event $event) {682 $this->called = true;683 $event->subject()->viewBuilder()->setLayoutPath('boom');684 }685 );686 $ExceptionRenderer->controller->request = new ServerRequest;687 $response = $this->getMockBuilder('Cake\Http\Response')->getMock();688 $response->expects($this->once())689 ->method('body')690 ->with($this->stringContains('Not Found'));691 $response->expects($this->once())692 ->method('type')693 ->with('html');694 $ExceptionRenderer->controller->response = $response;695 $ExceptionRenderer->render();696 $this->assertTrue($this->called, 'Listener added was not triggered.');697 $this->assertEquals('', $ExceptionRenderer->controller->viewBuilder()->layoutPath());698 $this->assertEquals('Error', $ExceptionRenderer->controller->viewBuilder()->templatePath());699 }700 /**701 * Test that missing plugin disables Controller::$plugin if the two are the same plugin.702 *703 * @return void704 */705 public function testMissingPluginRenderSafe()706 {707 $exception = new NotFoundException();708 $ExceptionRenderer = new ExceptionRenderer($exception);709 $ExceptionRenderer->controller = $this->getMockBuilder('Cake\Controller\Controller')710 ->setMethods(['render'])711 ->getMock();712 $ExceptionRenderer->controller->plugin = 'TestPlugin';713 $ExceptionRenderer->controller->request = $this->getMockBuilder('Cake\Http\ServerRequest')->getMock();714 $exception = new MissingPluginException(['plugin' => 'TestPlugin']);715 $ExceptionRenderer->controller->expects($this->once())716 ->method('render')717 ->with('error400')718 ->will($this->throwException($exception));719 $response = $this->getMockBuilder('Cake\Http\Response')->getMock();720 $response->expects($this->once())721 ->method('body')722 ->with($this->logicalAnd(723 $this->logicalNot($this->stringContains('test plugin error500')),724 $this->stringContains('Not Found')725 ));726 $ExceptionRenderer->controller->response = $response;727 $ExceptionRenderer->render();728 }729 /**730 * Test that missing plugin doesn't disable Controller::$plugin if the two aren't the same plugin.731 *732 * @return void733 */734 public function testMissingPluginRenderSafeWithPlugin()735 {736 Plugin::load('TestPlugin');737 $exception = new NotFoundException();738 $ExceptionRenderer = new ExceptionRenderer($exception);739 $ExceptionRenderer->controller = $this->getMockBuilder('Cake\Controller\Controller')740 ->setMethods(['render'])741 ->getMock();742 $ExceptionRenderer->controller->plugin = 'TestPlugin';743 $ExceptionRenderer->controller->request = $this->getMockBuilder('Cake\Http\ServerRequest')->getMock();744 $exception = new MissingPluginException(['plugin' => 'TestPluginTwo']);745 $ExceptionRenderer->controller->expects($this->once())746 ->method('render')747 ->with('error400')748 ->will($this->throwException($exception));749 $response = $this->getMockBuilder('Cake\Http\Response')->getMock();750 $response->expects($this->once())751 ->method('body')752 ->with($this->logicalAnd(753 $this->stringContains('test plugin error500'),754 $this->stringContains('Not Found')755 ));756 $ExceptionRenderer->controller->response = $response;757 $ExceptionRenderer->render();758 Plugin::unload();759 }760 /**761 * Test that exceptions can be rendered when a request hasn't been registered762 * with Router763 *764 * @return void765 */766 public function testRenderWithNoRequest()767 {768 Router::reload();769 $this->assertNull(Router::getRequest(false));770 $exception = new Exception('Terrible');771 $ExceptionRenderer = new ExceptionRenderer($exception);772 $result = $ExceptionRenderer->render();773 $this->assertContains('Internal Error', $result->body());774 $this->assertEquals(500, $result->statusCode());775 }776 /**777 * Test that rendering exceptions triggers shutdown events.778 *779 * @return void780 */781 public function testRenderShutdownEvents()782 {783 $fired = [];784 $listener = function (Event $event) use (&$fired) {785 $fired[] = $event->name();786 };787 $events = EventManager::instance();788 $events->attach($listener, 'Controller.shutdown');789 $events->attach($listener, 'Dispatcher.afterDispatch');790 $exception = new Exception('Terrible');791 $renderer = new ExceptionRenderer($exception);792 $renderer->render();793 $expected = ['Controller.shutdown', 'Dispatcher.afterDispatch'];794 $this->assertEquals($expected, $fired);795 }796 /**797 * Test that rendering exceptions triggers events798 * on filters attached to dispatcherfactory799 *800 * @return void801 */802 public function testRenderShutdownEventsOnDispatcherFactory()803 {804 $filter = $this->getMockBuilder('Cake\Routing\DispatcherFilter')805 ->setMethods(['afterDispatch'])806 ->getMock();807 $filter->expects($this->at(0))808 ->method('afterDispatch');809 DispatcherFactory::add($filter);810 $exception = new Exception('Terrible');811 $renderer = new ExceptionRenderer($exception);812 $renderer->render();813 }814 /**815 * test that subclass methods fire shutdown events.816 *817 * @return void818 */819 public function testSubclassTriggerShutdownEvents()820 {821 $fired = [];822 $listener = function (Event $event) use (&$fired) {823 $fired[] = $event->name();824 };825 $events = EventManager::instance();826 $events->attach($listener, 'Controller.shutdown');827 $events->attach($listener, 'Dispatcher.afterDispatch');828 $exception = new MissingWidgetThingException('Widget not found');829 $renderer = $this->_mockResponse(new MyCustomExceptionRenderer($exception));830 $renderer->render();831 $expected = ['Controller.shutdown', 'Dispatcher.afterDispatch'];832 $this->assertEquals($expected, $fired);833 }834 /**835 * Tests the output of rendering a PDOException836 *837 * @return void838 */839 public function testPDOException()840 {841 $exception = new \PDOException('There was an error in the SQL query');842 $exception->queryString = 'SELECT * from poo_query < 5 and :seven';843 $exception->params = ['seven' => 7];844 $ExceptionRenderer = new ExceptionRenderer($exception);845 $ExceptionRenderer->controller->response = $this->getMockBuilder('Cake\Http\Response')846 ->setMethods(['statusCode', '_sendHeader'])847 ->getMock();848 $ExceptionRenderer->controller->response->expects($this->once())->method('statusCode')->with(500);849 $result = $ExceptionRenderer->render()->body();850 $this->assertContains('Database Error', $result);851 $this->assertContains('There was an error in the SQL query', $result);852 $this->assertContains(h('SELECT * from poo_query < 5 and :seven'), $result);853 $this->assertContains("'seven' => (int) 7", $result);854 }855}...

Full Screen

Full Screen

Handler.php

Source:Handler.php Github

copy

Full Screen

...37 * @var \Illuminate\Contracts\Container\Container38 */39 protected $container;40 /**41 * A list of the exception types that are not reported.42 *43 * @var array44 */45 protected $dontReport = [];46 /**47 * A list of the internal exception types that should not be reported.48 *49 * @var array50 */51 protected $internalDontReport = [52 AuthenticationException::class,53 AuthorizationException::class,54 HttpException::class,55 HttpResponseException::class,56 ModelNotFoundException::class,57 TokenMismatchException::class,58 ValidationException::class,59 ];60 /**61 * A list of the inputs that are never flashed for validation exceptions.62 *63 * @var array64 */65 protected $dontFlash = [66 'password',67 'password_confirmation',68 ];69 /**70 * Create a new exception handler instance.71 *72 * @param \Illuminate\Contracts\Container\Container $container73 * @return void74 */75 public function __construct(Container $container)76 {77 $this->container = $container;78 }79 /**80 * Report or log an exception.81 *82 * @param \Exception $e83 * @return mixed84 *85 * @throws \Exception86 */87 public function report(Exception $e)88 {89 if ($this->shouldntReport($e)) {90 return;91 }92 if (method_exists($e, 'report')) {93 return $e->report();94 }95 try {96 $logger = $this->container->make(LoggerInterface::class);97 } catch (Exception $ex) {98 throw $e;99 }100 $logger->error(101 $e->getMessage(),102 array_merge($this->context(), ['exception' => $e]103 ));104 }105 /**106 * Determine if the exception should be reported.107 *108 * @param \Exception $e109 * @return bool110 */111 public function shouldReport(Exception $e)112 {113 return ! $this->shouldntReport($e);114 }115 /**116 * Determine if the exception is in the "do not report" list.117 *118 * @param \Exception $e119 * @return bool120 */121 protected function shouldntReport(Exception $e)122 {123 $dontReport = array_merge($this->dontReport, $this->internalDontReport);124 return ! is_null(Arr::first($dontReport, function ($type) use ($e) {125 return $e instanceof $type;126 }));127 }128 /**129 * Get the default context variables for logging.130 *131 * @return array132 */133 protected function context()134 {135 try {136 return array_filter([137 'userId' => Auth::id(),138 'email' => Auth::user() ? Auth::user()->email : null,139 ]);140 } catch (Throwable $e) {141 return [];142 }143 }144 /**145 * Render an exception into a response.146 *147 * @param \Illuminate\Http\Request $request148 * @param \Exception $e149 * @return \Symfony\Component\HttpFoundation\Response150 */151 public function render($request, Exception $e)152 {153 if (method_exists($e, 'render') && $response = $e->render($request)) {154 return Router::toResponse($request, $response);155 } elseif ($e instanceof Responsable) {156 return $e->toResponse($request);157 }158 $e = $this->prepareException($e);159 if ($e instanceof HttpResponseException) {160 return $e->getResponse();161 } elseif ($e instanceof AuthenticationException) {162 return $this->unauthenticated($request, $e);163 } elseif ($e instanceof ValidationException) {164 return $this->convertValidationExceptionToResponse($e, $request);165 }166 return $request->expectsJson()167 ? $this->prepareJsonResponse($request, $e)168 : $this->prepareResponse($request, $e);169 }170 /**171 * Prepare exception for rendering.172 *173 * @param \Exception $e174 * @return \Exception175 */176 protected function prepareException(Exception $e)177 {178 if ($e instanceof ModelNotFoundException) {179 $e = new NotFoundHttpException($e->getMessage(), $e);180 } elseif ($e instanceof AuthorizationException) {181 $e = new AccessDeniedHttpException($e->getMessage(), $e);182 } elseif ($e instanceof TokenMismatchException) {183 $e = new HttpException(419, $e->getMessage(), $e);184 }185 return $e;186 }187 /**188 * Convert an authentication exception into a response.189 *190 * @param \Illuminate\Http\Request $request191 * @param \Illuminate\Auth\AuthenticationException $exception192 * @return \Illuminate\Http\Response193 */194 protected function unauthenticated($request, AuthenticationException $exception)195 {196 return $request->expectsJson()197 ? response()->json(['message' => $exception->getMessage()], 401)198 : redirect()->guest(route('login'));199 }200 /**201 * Create a response object from the given validation exception.202 *203 * @param \Illuminate\Validation\ValidationException $e204 * @param \Illuminate\Http\Request $request205 * @return \Symfony\Component\HttpFoundation\Response206 */207 protected function convertValidationExceptionToResponse(ValidationException $e, $request)208 {209 if ($e->response) {210 return $e->response;211 }212 return $request->expectsJson()213 ? $this->invalidJson($request, $e)214 : $this->invalid($request, $e);215 }216 /**217 * Convert a validation exception into a response.218 *219 * @param \Illuminate\Http\Request $request220 * @param \Illuminate\Validation\ValidationException $exception221 * @return \Illuminate\Http\Response222 */223 protected function invalid($request, ValidationException $exception)224 {225 return redirect($exception->redirectTo ?? url()->previous())226 ->withInput($request->except($this->dontFlash))227 ->withErrors($exception->errors(), $exception->errorBag);228 }229 /**230 * Convert a validation exception into a JSON response.231 *232 * @param \Illuminate\Http\Request $request233 * @param \Illuminate\Validation\ValidationException $exception234 * @return \Illuminate\Http\JsonResponse235 */236 protected function invalidJson($request, ValidationException $exception)237 {238 return response()->json([239 'message' => $exception->getMessage(),240 'errors' => $exception->errors(),241 ], $exception->status);242 }243 /**244 * Prepare a response for the given exception.245 *246 * @param \Illuminate\Http\Request $request247 * @param \Exception $e248 * @return \Symfony\Component\HttpFoundation\Response249 */250 protected function prepareResponse($request, Exception $e)251 {252 if (! $this->isHttpException($e) && config('app.debug')) {253 return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);254 }255 if (! $this->isHttpException($e)) {256 $e = new HttpException(500, $e->getMessage());257 }258 return $this->toIlluminateResponse(259 $this->renderHttpException($e), $e260 );261 }262 /**263 * Create a Symfony response for the given exception.264 *265 * @param \Exception $e266 * @return \Symfony\Component\HttpFoundation\Response267 */268 protected function convertExceptionToResponse(Exception $e)269 {270 return SymfonyResponse::create(271 $this->renderExceptionContent($e),272 $this->isHttpException($e) ? $e->getStatusCode() : 500,273 $this->isHttpException($e) ? $e->getHeaders() : []274 );275 }276 /**277 * Get the response content for the given exception.278 *279 * @param \Exception $e280 * @return string281 */282 protected function renderExceptionContent(Exception $e)283 {284 try {285 return config('app.debug') && class_exists(Whoops::class)286 ? $this->renderExceptionWithWhoops($e)287 : $this->renderExceptionWithSymfony($e, config('app.debug'));288 } catch (Exception $e) {289 return $this->renderExceptionWithSymfony($e, config('app.debug'));290 }291 }292 /**293 * Render an exception to a string using "Whoops".294 *295 * @param \Exception $e296 * @return string297 */298 protected function renderExceptionWithWhoops(Exception $e)299 {300 return tap(new Whoops, function ($whoops) {301 $whoops->pushHandler($this->whoopsHandler());302 $whoops->writeToOutput(false);303 $whoops->allowQuit(false);304 })->handleException($e);305 }306 /**307 * Get the Whoops handler for the application.308 *309 * @return \Whoops\Handler\Handler310 */311 protected function whoopsHandler()312 {313 return (new WhoopsHandler)->forDebug();314 }315 /**316 * Render an exception to a string using Symfony.317 *318 * @param \Exception $e319 * @param bool $debug320 * @return string321 */322 protected function renderExceptionWithSymfony(Exception $e, $debug)323 {324 return (new SymfonyExceptionHandler($debug))->getHtml(325 FlattenException::create($e)326 );327 }328 /**329 * Render the given HttpException.330 *331 * @param \Symfony\Component\HttpKernel\Exception\HttpException $e332 * @return \Symfony\Component\HttpFoundation\Response333 */334 protected function renderHttpException(HttpException $e)335 {336 $this->registerErrorViewPaths();337 if (view()->exists($view = "errors::{$e->getStatusCode()}")) {338 return response()->view($view, [339 'errors' => new ViewErrorBag,340 'exception' => $e,341 ], $e->getStatusCode(), $e->getHeaders());342 }343 return $this->convertExceptionToResponse($e);344 }345 /**346 * Register the error template hint paths.347 *348 * @return void349 */350 protected function registerErrorViewPaths()351 {352 $paths = collect(config('view.paths'));353 View::replaceNamespace('errors', $paths->map(function ($path) {354 return "{$path}/errors";355 })->push(__DIR__.'/views')->all());356 }357 /**358 * Map the given exception into an Illuminate response.359 *360 * @param \Symfony\Component\HttpFoundation\Response $response361 * @param \Exception $e362 * @return \Illuminate\Http\Response363 */364 protected function toIlluminateResponse($response, Exception $e)365 {366 if ($response instanceof SymfonyRedirectResponse) {367 $response = new RedirectResponse(368 $response->getTargetUrl(), $response->getStatusCode(), $response->headers->all()369 );370 } else {371 $response = new Response(372 $response->getContent(), $response->getStatusCode(), $response->headers->all()373 );374 }375 return $response->withException($e);376 }377 /**378 * Prepare a JSON response for the given exception.379 *380 * @param \Illuminate\Http\Request $request381 * @param \Exception $e382 * @return \Illuminate\Http\JsonResponse383 */384 protected function prepareJsonResponse($request, Exception $e)385 {386 return new JsonResponse(387 $this->convertExceptionToArray($e),388 $this->isHttpException($e) ? $e->getStatusCode() : 500,389 $this->isHttpException($e) ? $e->getHeaders() : [],390 JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES391 );392 }393 /**394 * Convert the given exception to an array.395 *396 * @param \Exception $e397 * @return array398 */399 protected function convertExceptionToArray(Exception $e)400 {401 return config('app.debug') ? [402 'message' => $e->getMessage(),403 'exception' => get_class($e),404 'file' => $e->getFile(),405 'line' => $e->getLine(),406 'trace' => collect($e->getTrace())->map(function ($trace) {407 return Arr::except($trace, ['args']);408 })->all(),409 ] : [410 'message' => $this->isHttpException($e) ? $e->getMessage() : 'Server Error',411 ];412 }413 /**414 * Render an exception to the console.415 *416 * @param \Symfony\Component\Console\Output\OutputInterface $output417 * @param \Exception $e418 * @return void419 */420 public function renderForConsole($output, Exception $e)421 {422 (new ConsoleApplication)->renderException($e, $output);423 }424 /**425 * Determine if the given exception is an HTTP exception.426 *427 * @param \Exception $e428 * @return bool429 */430 protected function isHttpException(Exception $e)431 {432 return $e instanceof HttpException;433 }434}...

Full Screen

Full Screen

FacebookRequestExceptionTest.php

Source:FacebookRequestExceptionTest.php Github

copy

Full Screen

...15 'error' => array(16 'code' => 100,17 'message' => 'errmsg',18 'error_subcode' => 0,19 'type' => 'exception'20 )21 );22 $json = json_encode($params);23 $exception = FacebookRequestException::create($json, $params, 401);24 $this->assertTrue($exception instanceof FacebookAuthorizationException);25 $this->assertEquals(100, $exception->getCode());26 $this->assertEquals(0, $exception->getSubErrorCode());27 $this->assertEquals('exception', $exception->getErrorType());28 $this->assertEquals('errmsg', $exception->getMessage());29 $this->assertEquals($json, $exception->getRawResponse());30 $this->assertEquals(401, $exception->getHttpStatusCode());31 $params['error']['code'] = 102;32 $json = json_encode($params);33 $exception = FacebookRequestException::create($json, $params, 401);34 $this->assertTrue($exception instanceof FacebookAuthorizationException);35 $this->assertEquals(102, $exception->getCode());36 $params['error']['code'] = 190;37 $json = json_encode($params);38 $exception = FacebookRequestException::create($json, $params, 401);39 $this->assertTrue($exception instanceof FacebookAuthorizationException);40 $this->assertEquals(190, $exception->getCode());41 $params['error']['type'] = 'OAuthException';42 $params['error']['code'] = 0;43 $params['error']['error_subcode'] = 458;44 $json = json_encode($params);45 $exception = FacebookRequestException::create($json, $params, 401);46 $this->assertTrue($exception instanceof FacebookAuthorizationException);47 $this->assertEquals(458, $exception->getSubErrorCode());48 $params['error']['error_subcode'] = 460;49 $json = json_encode($params);50 $exception = FacebookRequestException::create($json, $params, 401);51 $this->assertTrue($exception instanceof FacebookAuthorizationException);52 $this->assertEquals(460, $exception->getSubErrorCode());53 $params['error']['error_subcode'] = 463;54 $json = json_encode($params);55 $exception = FacebookRequestException::create($json, $params, 401);56 $this->assertTrue($exception instanceof FacebookAuthorizationException);57 $this->assertEquals(463, $exception->getSubErrorCode());58 $params['error']['error_subcode'] = 467;59 $json = json_encode($params);60 $exception = FacebookRequestException::create($json, $params, 401);61 $this->assertTrue($exception instanceof FacebookAuthorizationException);62 $this->assertEquals(467, $exception->getSubErrorCode());63 $params['error']['error_subcode'] = 0;64 $json = json_encode($params);65 $exception = FacebookRequestException::create($json, $params, 401);66 $this->assertTrue($exception instanceof FacebookAuthorizationException);67 $this->assertEquals(0, $exception->getSubErrorCode());68 }69 public function testServerExceptions()70 {71 $params = array(72 'error' => array(73 'code' => 1,74 'message' => 'errmsg',75 'error_subcode' => 0,76 'type' => 'exception'77 )78 );79 $json = json_encode($params);80 $exception = FacebookRequestException::create($json, $params, 500);81 $this->assertTrue($exception instanceof FacebookServerException);82 $this->assertEquals(1, $exception->getCode());83 $this->assertEquals(0, $exception->getSubErrorCode());84 $this->assertEquals('exception', $exception->getErrorType());85 $this->assertEquals('errmsg', $exception->getMessage());86 $this->assertEquals($json, $exception->getRawResponse());87 $this->assertEquals(500, $exception->getHttpStatusCode());88 $params['error']['code'] = 2;89 $json = json_encode($params);90 $exception = FacebookRequestException::create($json, $params, 401);91 $this->assertTrue($exception instanceof FacebookServerException);92 $this->assertEquals(2, $exception->getCode());93 }94 public function testThrottleExceptions()95 {96 $params = array(97 'error' => array(98 'code' => 4,99 'message' => 'errmsg',100 'error_subcode' => 0,101 'type' => 'exception'102 )103 );104 $json = json_encode($params);105 $exception = FacebookRequestException::create($json, $params, 401);106 $this->assertTrue($exception instanceof FacebookThrottleException);107 $this->assertEquals(4, $exception->getCode());108 $this->assertEquals(0, $exception->getSubErrorCode());109 $this->assertEquals('exception', $exception->getErrorType());110 $this->assertEquals('errmsg', $exception->getMessage());111 $this->assertEquals($json, $exception->getRawResponse());112 $this->assertEquals(401, $exception->getHttpStatusCode());113 $params['error']['code'] = 17;114 $json = json_encode($params);115 $exception = FacebookRequestException::create($json, $params, 401);116 $this->assertTrue($exception instanceof FacebookThrottleException);117 $this->assertEquals(17, $exception->getCode());118 $params['error']['code'] = 341;119 $json = json_encode($params);120 $exception = FacebookRequestException::create($json, $params, 401);121 $this->assertTrue($exception instanceof FacebookThrottleException);122 $this->assertEquals(341, $exception->getCode());123 }124 public function testUserIssueExceptions()125 {126 $params = array(127 'error' => array(128 'code' => 230,129 'message' => 'errmsg',130 'error_subcode' => 459,131 'type' => 'exception'132 )133 );134 $json = json_encode($params);135 $exception = FacebookRequestException::create($json, $params, 401);136 $this->assertTrue($exception instanceof FacebookAuthorizationException);137 $this->assertEquals(230, $exception->getCode());138 $this->assertEquals(459, $exception->getSubErrorCode());139 $this->assertEquals('exception', $exception->getErrorType());140 $this->assertEquals('errmsg', $exception->getMessage());141 $this->assertEquals($json, $exception->getRawResponse());142 $this->assertEquals(401, $exception->getHttpStatusCode());143 $params['error']['error_subcode'] = 464;144 $json = json_encode($params);145 $exception = FacebookRequestException::create($json, $params, 401);146 $this->assertTrue($exception instanceof FacebookAuthorizationException);147 $this->assertEquals(464, $exception->getSubErrorCode());148 }149 public function testPermissionExceptions()150 {151 $params = array(152 'error' => array(153 'code' => 10,154 'message' => 'errmsg',155 'error_subcode' => 0,156 'type' => 'exception'157 )158 );159 $json = json_encode($params);160 $exception = FacebookRequestException::create($json, $params, 401);161 $this->assertTrue($exception instanceof FacebookPermissionException);162 $this->assertEquals(10, $exception->getCode());163 $this->assertEquals(0, $exception->getSubErrorCode());164 $this->assertEquals('exception', $exception->getErrorType());165 $this->assertEquals('errmsg', $exception->getMessage());166 $this->assertEquals($json, $exception->getRawResponse());167 $this->assertEquals(401, $exception->getHttpStatusCode());168 $params['error']['code'] = 200;169 $json = json_encode($params);170 $exception = FacebookRequestException::create($json, $params, 401);171 $this->assertTrue($exception instanceof FacebookPermissionException);172 $this->assertEquals(200, $exception->getCode());173 $params['error']['code'] = 250;174 $json = json_encode($params);175 $exception = FacebookRequestException::create($json, $params, 401);176 $this->assertTrue($exception instanceof FacebookPermissionException);177 $this->assertEquals(250, $exception->getCode());178 $params['error']['code'] = 299;179 $json = json_encode($params);180 $exception = FacebookRequestException::create($json, $params, 401);181 $this->assertTrue($exception instanceof FacebookPermissionException);182 $this->assertEquals(299, $exception->getCode());183 }184 public function testClientExceptions()185 {186 $params = array(187 'error' => array(188 'code' => 506,189 'message' => 'errmsg',190 'error_subcode' => 0,191 'type' => 'exception'192 )193 );194 $json = json_encode($params);195 $exception = FacebookRequestException::create($json, $params, 401);196 $this->assertTrue($exception instanceof FacebookClientException);197 $this->assertEquals(506, $exception->getCode());198 $this->assertEquals(0, $exception->getSubErrorCode());199 $this->assertEquals('exception', $exception->getErrorType());200 $this->assertEquals('errmsg', $exception->getMessage());201 $this->assertEquals($json, $exception->getRawResponse());202 $this->assertEquals(401, $exception->getHttpStatusCode());203 }204 public function testOtherException()205 {206 $params = array(207 'error' => array(208 'code' => 42,209 'message' => 'ship love',210 'error_subcode' => 0,211 'type' => 'feature'212 )213 );214 $json = json_encode($params);215 $exception = FacebookRequestException::create($json, $params, 200);216 $this->assertTrue($exception instanceof FacebookOtherException);217 $this->assertEquals(42, $exception->getCode());218 $this->assertEquals(0, $exception->getSubErrorCode());219 $this->assertEquals('feature', $exception->getErrorType());220 $this->assertEquals('ship love', $exception->getMessage());221 $this->assertEquals($json, $exception->getRawResponse());222 $this->assertEquals(200, $exception->getHttpStatusCode());223 }224 public function testValidateThrowsException()225 {226 $bogusSession = new FacebookSession('invalid-token');227 $this->setExpectedException(228 'Facebook\\FacebookSDKException', 'Session has expired'229 );230 $bogusSession->validate();231 }232 public function testInvalidCredentialsException()233 {234 $bogusSession = new FacebookSession('invalid-token');235 $this->setExpectedException(236 'Facebook\\FacebookAuthorizationException', 'Invalid OAuth access token'...

Full Screen

Full Screen

ExceptionsTest.php

Source:ExceptionsTest.php Github

copy

Full Screen

...24use Exception;25class ExceptionsTest extends TestCase26{27 /**28 * Tests simple exceptions work.29 *30 * @dataProvider exceptionProvider31 * @param $class The exception class name32 * @param $defaultCode The default exception code33 * @return void34 */35 public function testSimpleException($class, $defaultCode)36 {37 $previous = new Exception();38 $exception = new $class('message', 100, $previous);39 $this->assertSame('message', $exception->getMessage());40 $this->assertSame(100, $exception->getCode());41 $this->assertSame($previous, $exception->getPrevious());42 $exception = new $class('message', null, $previous);43 $this->assertSame('message', $exception->getMessage());44 $this->assertSame($defaultCode, $exception->getCode());45 $this->assertSame($previous, $exception->getPrevious());46 }47 /**48 * Tests FatalErrorException works.49 *50 * @return void51 */52 public function testFatalErrorException()53 {54 $previous = new Exception();55 $exception = new FatalErrorException('message', 100, __FILE__, 1, $previous);56 $this->assertSame('message', $exception->getMessage());57 $this->assertSame(100, $exception->getCode());58 $this->assertSame(__FILE__, $exception->getFile());59 $this->assertSame(1, $exception->getLine());60 $this->assertSame($previous, $exception->getPrevious());61 $exception = new FatalErrorException('message', null, __FILE__, 1, $previous);62 $this->assertSame('message', $exception->getMessage());63 $this->assertSame(500, $exception->getCode());64 $this->assertSame(__FILE__, $exception->getFile());65 $this->assertSame(1, $exception->getLine());66 $this->assertSame($previous, $exception->getPrevious());67 }68 /**69 * Tests PHP7ErrorException works.70 *71 * @return void72 */73 public function testPHP7ErrorException()74 {75 $this->skipIf(version_compare(PHP_VERSION, '7.0.0', '<'));76 $previous = new Exception();77 $error = new Error('message', 100, $previous);78 $line = __LINE__ - 1;79 $exception = new PHP7ErrorException($error);80 $this->assertSame(100, $exception->getCode());81 $this->assertSame(__FILE__, $exception->getFile());82 $this->assertSame($line, $exception->getLine());83 $this->assertSame($previous, $exception->getPrevious());84 }85 /**86 * Tests PersistenceFailedException works.87 *88 * @return void89 */90 public function testPersistenceFailedException()91 {92 $previous = new Exception();93 $entity = new Entity();94 $exception = new PersistenceFailedException($entity, 'message', 100, $previous);95 $this->assertSame('message', $exception->getMessage());96 $this->assertSame(100, $exception->getCode());97 $this->assertSame($previous, $exception->getPrevious());98 $this->assertSame($entity, $exception->getEntity());99 $exception = new PersistenceFailedException(new Entity, 'message', null, $previous);100 $this->assertSame('message', $exception->getMessage());101 $this->assertSame(500, $exception->getCode());102 $this->assertSame($previous, $exception->getPrevious());103 }104 /**105 * Provides pairs of exception name and default code.106 *107 * @return array108 */109 public function exceptionProvider()110 {111 return [112 ['Cake\Console\Exception\ConsoleException', 500],113 ['Cake\Console\Exception\MissingHelperException', 500],114 ['Cake\Console\Exception\MissingShellException', 500],115 ['Cake\Console\Exception\MissingShellMethodException', 500],116 ['Cake\Console\Exception\MissingTaskException', 500],117 ['Cake\Console\Exception\StopException', 500],118 ['Cake\Controller\Exception\AuthSecurityException', 400],119 ['Cake\Controller\Exception\MissingActionException', 404],120 ['Cake\Controller\Exception\MissingComponentException', 500],121 ['Cake\Controller\Exception\SecurityException', 400],122 ['Cake\Core\Exception\Exception', 500],123 ['Cake\Core\Exception\MissingPluginException', 500],...

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1use \mageekguy\atoum\exceptions;2use \mageekguy\atoum\asserters;3use \mageekguy\atoum\test;4use \mageekguy\atoum\mock;5use \mageekguy\atoum\mock\php;6use \mageekguy\atoum\mock\php\method;7use \mageekguy\atoum\mock\php\method\call;8use \mageekguy\atoum\mock\php\method\call\adapter;9use \mageekguy\atoum\mock\php\method\call\adapter\invoker;10use \mageekguy\atoum\mock\php\method\call\adapter\invoker\reflection;11use \mageekguy\atoum\mock\php\method\call\adapter\invoker\reflection\class_;12use \mageekguy\atoum\mock\php\method\call\adapter\invoker\reflection\class_\method_;13use \mageekguy\atoum\mock\php\method\call\adapter\invoker\reflection\class_\method_\parameter;14use \mageekguy\atoum\mock\php\method\call\adapter\invoker\reflection\class_\method_\parameter\default_;

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1use \mageekguy\atoum\exception;2use \mageekguy\atoum\exceptions;3use \mageekguy\atoum\exceptions\logic;4use \mageekguy\atoum\exceptions\logic\invalidArgument;5use \mageekguy\atoum\exceptions\logic\invalidArgument\invalidType;6use \mageekguy\atoum\exceptions\logic\invalidArgument\invalidType\badValue;7use \mageekguy\atoum\exceptions\logic\invalidArgument\invalidType\badValue\badArrayValue;8use \mageekguy\atoum\exceptions\logic\invalidArgument\invalidType\badValue\badArrayValue\badArrayKey;9use \mageekguy\atoum\exceptions\logic\invalidArgument\invalidType\badValue\badArrayValue\badArrayKey\badArrayKeyAsString;10use \mageekguy\atoum\exceptions\logic\invalidArgument\invalidType\badValue\badArrayValue\badArrayKey\badArrayKeyAsString\badArrayKeyAsStringWithInvalidCharacters;11use \mageekguy\atoum\exceptions\logic\invalidArgument\invalidType\badValue\badArrayValue\badArrayKey\badArrayKeyAsString\badArrayKeyAsStringWithInvalidCharacters\badArrayKeyAsStringWithInvalidCharactersForPhpVariable;12use \mageekguy\atoum\exceptions\logic\invalidArgument\invalidType\badValue\badArrayValue\badArrayKey\badArrayKeyAsString\badArrayKeyAsStringWithInvalidCharacters\badArrayKeyAsStringWithInvalidCharactersForPhpVariable\badArrayKeyAsStringWithInvalidCharactersForPhpVariableStartingByDigit;

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1namespace atoum\atoum\tests\units\exceptions;2use atoum\atoum\exceptions;3{4}5namespace atoum\atoum\tests\units\exceptions;6use atoum\atoum\exceptions;7{8}9namespace atoum\atoum\tests\units\exceptions;10use atoum\atoum\exceptions;11{12}13namespace atoum\atoum\tests\units\exceptions;14use atoum\atoum\exceptions;15{16}17namespace atoum\atoum\tests\units\exceptions;18use atoum\atoum\exceptions;19{20}21namespace atoum\atoum\tests\units\exceptions;22use atoum\atoum\exceptions;23{24}25namespace atoum\atoum\tests\units\exceptions;26use atoum\atoum\exceptions;27{28}29namespace atoum\atoum\tests\units\exceptions;30use atoum\atoum\exceptions;31{32}33namespace atoum\atoum\tests\units\exceptions;34use atoum\atoum\exceptions;35{36}37namespace atoum\atoum\tests\units\exceptions;

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1use \mageekguy\atoum;2{3 public function testMethod()4 {5 ->if($this->testedInstance = new testedClass())6 ->exception(function() {7 $this->testedInstance->method();8 })9 ->isInstanceOf('Exception')10 ->hasMessage('message')11 ->hasCode('code')12 ;13 }14}15use \PHPUnit_Framework_TestCase;16{17 public function testMethod()18 {19 $this->setExpectedException('Exception', 'message', 'code');20 $this->testedInstance->method();21 }22}23use \mageekguy\atoum;24{25 public function testMethod()26 {27 ->if($this->testedInstance = new testedClass())28 ->exception(function() {29 $this->testedInstance->method();30 })31 ->isInstanceOf('Exception')32 ->hasMessage('message')33 ->hasCode('code')34 ;35 }36}37use \PHPUnit_Framework_TestCase;38{39 public function testMethod()40 {41 $this->setExpectedException('Exception', 'message', 'code');42 $this->testedInstance->method();43 }44}45use \mageekguy\atoum;46{47 public function testMethod()48 {49 ->if($this->testedInstance = new testedClass())50 ->exception(function() {51 $this->testedInstance->method();52 })53 ->isInstanceOf('Exception')54 ->hasMessage('message')55 ->hasCode('code')56 ;57 }58}59use \PHPUnit_Framework_TestCase;60{61 public function testMethod()62 {63 $this->setExpectedException('Exception', 'message',

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1use mageekguy\atoum\exceptions;2use Exception;3class myException extends exceptions\runtime {}4class myOtherException extends Exception {}5class myOtherException extends exceptions\logic {}6class myOtherException extends LogicException {}7class myOtherException extends exceptions\logic\invalidArgument {}8class myOtherException extends InvalidArgumentException {}9class myOtherException extends exceptions\logic\invalidArgument\outOfBounds {}10class myOtherException extends OutOfBoundsException {}11class myOtherException extends exceptions\logic\invalidArgument\outOfRange {}12class myOtherException extends OutOfRangeException {}13class myOtherException extends exceptions\logic\invalidArgument\invalidArgument {}14class myOtherException extends InvalidArgumentException {}15class myOtherException extends exceptions\logic\invalidArgument\invalidArgument {}16class myOtherException extends InvalidArgumentException {}17class myOtherException extends exceptions\logic\invalidArgument\invalidArgument {}18class myOtherException extends InvalidArgumentException {}19class myOtherException extends exceptions\logic\invalidArgument\invalidArgument {}20class myOtherException extends InvalidArgumentException {}21class myOtherException extends exceptions\logic\invalidArgument\invalidArgument {}22class myOtherException extends InvalidArgumentException {}23class myOtherException extends exceptions\logic\invalidArgument\invalidArgument {}24class myOtherException extends InvalidArgumentException {}

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1use \mageekguy\atoum\exceptions;2{3 public function test1()4 {5 $this->object(new \stdClass())6 ->isInstanceOf('stdClass')7 ;8 }9 public function test2()10 {11 $this->variable($this->getTestedClassName())12 ->isNull()13 ;14 }15 public function test3()16 {17 $this->exception(function() {18 throw new exceptions\runtime('test');19 })20 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')21 ->hasMessage('test')22 ;23 }24}25{26 public function test1()27 {28 $this->object(new \stdClass())29 ->isInstanceOf('stdClass')30 ;31 }32 public function test2()33 {34 $this->variable($this->getTestedClassName())35 ->isNull()36 ;37 }38 public function test3()39 {40 $this->exception(function() {41 throw new exceptions\runtime('test');42 })43 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')44 ->hasMessage('test')45 ;46 }47}48{49 public function test1()50 {51 $this->object(new \stdClass())52 ->isInstanceOf('stdClass')53 ;54 }55 public function test2()56 {57 $this->variable($this->getTestedClassName())58 ->isNull()59 ;60 }61 public function test3()62 {63 $this->exception(function() {64 throw new exceptions\runtime('test');65 })66 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')67 ->hasMessage('test')68 ;69 }70}71{72 public function test1()73 {74 $this->object(new \stdClass())75 ->isInstanceOf('stdClass')76 ;77 }78 public function test2()79 {80 $this->variable($this->getTestedClassName())81 ->isNull()82 ;83 }84 public function test3()85 {86 $this->exception(function() {

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1use \mageekguy\atoum\exceptions\logic;2{3 public function __construct()4 {5 throw new logic('Error message');6 }7}8$myClass = new MyClass();9use \mageekguy\atoum\exceptions\logic;10{11 public function __construct()12 {13 throw new logic('Error message');14 }15}16$myClass = new MyClass();17use \mageekguy\atoum\exceptions\logic;18{19 public function __construct()20 {21 throw new logic('Error message');22 }23}24$myClass = new MyClass();25use \mageekguy\atoum\exceptions\logic;26{27 public function __construct()28 {29 throw new logic('Error message');30 }31}32$myClass = new MyClass();33use \mageekguy\atoum\exceptions\logic;34{35 public function __construct()36 {37 throw new logic('Error message');38 }39}40$myClass = new MyClass();41use \mageekguy\atoum\exceptions\logic;42{43 public function __construct()44 {45 throw new logic('Error message');46 }47}48$myClass = new MyClass();49use \mageekguy\atoum\exceptions\logic;50{51 public function __construct()52 {53 throw new logic('Error message');54 }55}56$myClass = new MyClass();57use \mageekguy\atoum\exceptions\logic;58{59 public function __construct()60 {61 throw new logic('Error message');62 }63}64$myClass = new MyClass();

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1use \mageekguy\atoum\exceptions;2use \mageekguy\atoum\tests\units\test;3use \mageekguy\atoum\tests\units\test\adapter;4use \mageekguy\atoum\tests\units\test\adapter\invoker;5use \mageekguy\atoum\tests\units\test\adapter\invoker\php;6use \mageekguy\atoum\tests\units\test\adapter\invoker\php\mocker;7use \mageekguy\atoum\tests\units\test\adapter\invoker\php\mocker\exception;8use \mageekguy\atoum\tests\units\test\adapter\invoker\php\mocker\exception\invalidArgument;9{10 public function testMocker()11 {12 ->given(13 $adapter = new adapter(),14 $invoker = new invoker(),15 $mocker = new mocker($adapter, $invoker)16 ->exception(17 function() use ($mocker) {18 $mocker->invoke('test');19 }20 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')21 ->hasMessage('Mocker is not initialized')22 ->exception(23 function() use ($mocker) {24 $mocker->invoke('test', 1, 2, 3);25 }26 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')27 ->hasMessage('Mocker is not initialized')28 ;29 }30}

Full Screen

Full Screen

exception

Using AI Code Generation

copy

Full Screen

1atoum\exceptions;2{3 public function testMyTest()4 {5 ->if($this->newTestedInstance)6 ->object($this->testedInstance->test())7 ->isInstanceOf('atoum\test')8 ;9 }10}11Fatal error: Uncaught exception 'atoum\exceptions\runtime' with message 'Class 'atoum\test' not found' in 1.php:17 Stack trace: #0 1.php(17): atoum\exceptions\runtime::errorHandler(2, 'Class 'atoum\\te...', '/home/.../1.php', 17, Array) #1 1.php(17): atoum\test->test() #2 {main} thrown in 1.php on line 1712atoum\exceptions;13atoum\test;14{15 public function testMyTest()16 {17 ->if($this->newTestedInstance)18 ->object($this->testedInstance->test())19 ->isInstanceOf('atoum\test')20 ;21 }22}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful