How to use testErrorHandler method of foo class

Best Atoum code snippet using foo.testErrorHandler

ErrorHandlerTest.php

Source:ErrorHandlerTest.php Github

copy

Full Screen

1<?php2/**3 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)4 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)5 *6 * Licensed under The MIT License7 * For full copyright and license information, please see the LICENSE.txt8 * Redistributions of files must retain the above copyright notice9 *10 * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)11 * @link http://cakephp.org CakePHP(tm) Project12 * @since 1.2.013 * @license http://www.opensource.org/licenses/mit-license.php MIT License14 */15namespace Cake\Test\TestCase\Error;16use Cake\Core\Configure;17use Cake\Core\Plugin;18use Cake\Error;19use Cake\Error\ErrorHandler;20use Cake\Error\PHP7ErrorException;21use Cake\Log\Log;22use Cake\Network\Exception\ForbiddenException;23use Cake\Network\Exception\NotFoundException;24use Cake\Network\Request;25use Cake\Routing\Exception\MissingControllerException;26use Cake\Routing\Router;27use Cake\TestSuite\TestCase;28use ParseError;29/**30 * Testing stub.31 */32class TestErrorHandler extends ErrorHandler33{34 /**35 * Access the response used.36 *37 * @var \Cake\Network\Response38 */39 public $response;40 /**41 * Stub output clearing in tests.42 *43 * @return void44 */45 protected function _clearOutput()46 {47 // noop48 }49 /**50 * Stub sending responses51 *52 * @return void53 */54 protected function _sendResponse($response)55 {56 $this->response = $response;57 }58}59/**60 * ErrorHandlerTest class61 */62class ErrorHandlerTest extends TestCase63{64 protected $_restoreError = false;65 /**66 * setup create a request object to get out of router later.67 *68 * @return void69 */70 public function setUp()71 {72 parent::setUp();73 Router::reload();74 $request = new Request();75 $request->base = '';76 $request->env('HTTP_REFERER', '/referer');77 Router::setRequestInfo($request);78 Configure::write('debug', true);79 $this->_logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();80 Log::reset();81 Log::config('error_test', [82 'engine' => $this->_logger83 ]);84 }85 /**86 * tearDown87 *88 * @return void89 */90 public function tearDown()91 {92 parent::tearDown();93 Log::reset();94 if ($this->_restoreError) {95 restore_error_handler();96 restore_exception_handler();97 }98 }99 /**100 * test error handling when debug is on, an error should be printed from Debugger.101 *102 * @return void103 */104 public function testHandleErrorDebugOn()105 {106 $errorHandler = new ErrorHandler();107 $errorHandler->register();108 $this->_restoreError = true;109 ob_start();110 $wrong = $wrong + 1;111 $result = ob_get_clean();112 $this->assertRegExp('/<pre class="cake-error">/', $result);113 $this->assertRegExp('/<b>Notice<\/b>/', $result);114 $this->assertRegExp('/variable:\s+wrong/', $result);115 }116 /**117 * provides errors for mapping tests.118 *119 * @return void120 */121 public static function errorProvider()122 {123 return [124 [E_USER_NOTICE, 'Notice'],125 [E_USER_WARNING, 'Warning'],126 ];127 }128 /**129 * test error mappings130 *131 * @dataProvider errorProvider132 * @return void133 */134 public function testErrorMapping($error, $expected)135 {136 $errorHandler = new ErrorHandler();137 $errorHandler->register();138 $this->_restoreError = true;139 ob_start();140 trigger_error('Test error', $error);141 $result = ob_get_clean();142 $this->assertContains('<b>' . $expected . '</b>', $result);143 }144 /**145 * test error prepended by @146 *147 * @return void148 */149 public function testErrorSuppressed()150 {151 $errorHandler = new ErrorHandler();152 $errorHandler->register();153 $this->_restoreError = true;154 ob_start();155 //@codingStandardsIgnoreStart156 @include 'invalid.file';157 //@codingStandardsIgnoreEnd158 $result = ob_get_clean();159 $this->assertTrue(empty($result));160 }161 /**162 * Test that errors go into Cake Log when debug = 0.163 *164 * @return void165 */166 public function testHandleErrorDebugOff()167 {168 Configure::write('debug', false);169 $errorHandler = new ErrorHandler();170 $errorHandler->register();171 $this->_restoreError = true;172 $this->_logger->expects($this->once())173 ->method('log')174 ->with(175 $this->matchesRegularExpression('(notice|debug)'),176 'Notice (8): Undefined variable: out in [' . __FILE__ . ', line ' . (__LINE__ + 3) . ']' . "\n\n"177 );178 $out = $out + 1;179 }180 /**181 * Test that errors going into Cake Log include traces.182 *183 * @return void184 */185 public function testHandleErrorLoggingTrace()186 {187 Configure::write('debug', false);188 $errorHandler = new ErrorHandler(['trace' => true]);189 $errorHandler->register();190 $this->_restoreError = true;191 $this->_logger->expects($this->once())192 ->method('log')193 ->with(194 $this->matchesRegularExpression('(notice|debug)'),195 $this->logicalAnd(196 $this->stringContains('Notice (8): Undefined variable: out in '),197 $this->stringContains('Trace:'),198 $this->stringContains(__NAMESPACE__ . '\ErrorHandlerTest::testHandleErrorLoggingTrace()'),199 $this->stringContains('Request URL:'),200 $this->stringContains('Referer URL:')201 )202 );203 $out = $out + 1;204 }205 /**206 * test handleException generating a page.207 *208 * @return void209 */210 public function testHandleException()211 {212 $error = new NotFoundException('Kaboom!');213 $errorHandler = new TestErrorHandler();214 $errorHandler->handleException($error);215 $this->assertContains('Kaboom!', $errorHandler->response->body(), 'message missing.');216 }217 /**218 * test handleException generating log.219 *220 * @return void221 */222 public function testHandleExceptionLog()223 {224 $errorHandler = new TestErrorHandler([225 'log' => true,226 'trace' => true,227 ]);228 $error = new NotFoundException('Kaboom!');229 $this->_logger->expects($this->at(0))230 ->method('log')231 ->with('error', $this->logicalAnd(232 $this->stringContains('[Cake\Network\Exception\NotFoundException] Kaboom!'),233 $this->stringContains('ErrorHandlerTest->testHandleExceptionLog')234 ));235 $this->_logger->expects($this->at(1))236 ->method('log')237 ->with('error', $this->logicalAnd(238 $this->stringContains('[Cake\Network\Exception\NotFoundException] Kaboom!'),239 $this->logicalNot($this->stringContains('ErrorHandlerTest->testHandleExceptionLog'))240 ));241 $errorHandler->handleException($error);242 $this->assertContains('Kaboom!', $errorHandler->response->body(), 'message missing.');243 $errorHandler = new TestErrorHandler([244 'log' => true,245 'trace' => false,246 ]);247 $errorHandler->handleException($error);248 }249 /**250 * test logging attributes with/without debug251 *252 * @return void253 */254 public function testHandleExceptionLogAttributes()255 {256 $errorHandler = new TestErrorHandler([257 'log' => true,258 'trace' => true,259 ]);260 $error = new MissingControllerException(['class' => 'Derp']);261 $this->_logger->expects($this->at(0))262 ->method('log')263 ->with('error', $this->logicalAnd(264 $this->stringContains(265 '[Cake\Routing\Exception\MissingControllerException] ' .266 'Controller class Derp could not be found.'267 ),268 $this->stringContains('Exception Attributes:'),269 $this->stringContains('Request URL:'),270 $this->stringContains('Referer URL:')271 ));272 $this->_logger->expects($this->at(1))273 ->method('log')274 ->with('error', $this->logicalAnd(275 $this->stringContains(276 '[Cake\Routing\Exception\MissingControllerException] ' .277 'Controller class Derp could not be found.'278 ),279 $this->logicalNot($this->stringContains('Exception Attributes:'))280 ));281 $errorHandler->handleException($error);282 Configure::write('debug', false);283 $errorHandler->handleException($error);284 }285 /**286 * test handleException generating log.287 *288 * @return void289 */290 public function testHandleExceptionLogSkipping()291 {292 $notFound = new NotFoundException('Kaboom!');293 $forbidden = new ForbiddenException('Fooled you!');294 $this->_logger->expects($this->once())295 ->method('log')296 ->with(297 'error',298 $this->stringContains('[Cake\Network\Exception\ForbiddenException] Fooled you!')299 );300 $errorHandler = new TestErrorHandler([301 'log' => true,302 'skipLog' => ['Cake\Network\Exception\NotFoundException'],303 ]);304 $errorHandler->handleException($notFound);305 $this->assertContains('Kaboom!', $errorHandler->response->body(), 'message missing.');306 $errorHandler->handleException($forbidden);307 $this->assertContains('Fooled you!', $errorHandler->response->body(), 'message missing.');308 }309 /**310 * tests it is possible to load a plugin exception renderer311 *312 * @return void313 */314 public function testLoadPluginHandler()315 {316 Plugin::load('TestPlugin');317 $errorHandler = new TestErrorHandler([318 'exceptionRenderer' => 'TestPlugin.TestPluginExceptionRenderer',319 ]);320 $error = new NotFoundException('Kaboom!');321 $errorHandler->handleException($error);322 $result = $errorHandler->response;323 $this->assertEquals('Rendered by test plugin', $result);324 }325 /**326 * test handleFatalError generating a page.327 *328 * These tests start two buffers as handleFatalError blows the outer one up.329 *330 * @return void331 */332 public function testHandleFatalErrorPage()333 {334 $line = __LINE__;335 $errorHandler = new TestErrorHandler();336 Configure::write('debug', true);337 $errorHandler->handleFatalError(E_ERROR, 'Something wrong', __FILE__, $line);338 $result = $errorHandler->response->body();339 $this->assertContains('Something wrong', $result, 'message missing.');340 $this->assertContains(__FILE__, $result, 'filename missing.');341 $this->assertContains((string)$line, $result, 'line missing.');342 Configure::write('debug', false);343 $errorHandler->handleFatalError(E_ERROR, 'Something wrong', __FILE__, $line);344 $result = $errorHandler->response->body();345 $this->assertNotContains('Something wrong', $result, 'message must not appear.');346 $this->assertNotContains(__FILE__, $result, 'filename must not appear.');347 $this->assertContains('An Internal Error Has Occurred.', $result);348 }349 /**350 * test handleFatalError generating log.351 *352 * @return void353 */354 public function testHandleFatalErrorLog()355 {356 $this->_logger->expects($this->at(0))357 ->method('log')358 ->with('error', $this->logicalAnd(359 $this->stringContains(__FILE__ . ', line ' . (__LINE__ + 9)),360 $this->stringContains('Fatal Error (1)'),361 $this->stringContains('Something wrong')362 ));363 $this->_logger->expects($this->at(1))364 ->method('log')365 ->with('error', $this->stringContains('[Cake\Error\FatalErrorException] Something wrong'));366 $errorHandler = new TestErrorHandler(['log' => true]);367 $errorHandler->handleFatalError(E_ERROR, 'Something wrong', __FILE__, __LINE__);368 }369 /**370 * Tests Handling a PHP7 error371 *372 * @return void373 */374 public function testHandlePHP7Error()375 {376 $this->skipIf(!class_exists('Error'), 'Requires PHP7');377 $error = new PHP7ErrorException(new ParseError('Unexpected variable foo'));378 $errorHandler = new TestErrorHandler();379 $errorHandler->handleException($error);380 $this->assertContains('Unexpected variable foo', $errorHandler->response->body(), 'message missing.');381 }382 /**383 * Data provider for memory limit changing.384 *385 * @return array386 */387 public function memoryLimitProvider()388 {389 return [390 // start, adjust, expected391 ['256M', 4, '262148K'],392 ['262144K', 4, '262148K'],393 ['1G', 128, '1048704K'],394 ];395 }396 /**397 * Test increasing the memory limit.398 *399 * @dataProvider memoryLimitProvider400 * @return void401 */402 public function testIncreaseMemoryLimit($start, $adjust, $expected)403 {404 $initial = ini_get('memory_limit');405 $this->skipIf(strlen($initial) === 0, 'Cannot read memory limit, and cannot test increasing it.');406 // phpunit.xml often has -1 as memory limit407 ini_set('memory_limit', $start);408 $errorHandler = new TestErrorHandler();409 $this->assertNull($errorHandler->increaseMemoryLimit($adjust));410 $new = ini_get('memory_limit');411 $this->assertEquals($expected, $new, 'memory limit did not get increased.');412 ini_set('memory_limit', $initial);413 }414}...

Full Screen

Full Screen

testErrorHandler

Using AI Code Generation

copy

Full Screen

1$foo = new foo();2$foo->testErrorHandler();3$foo = new foo();4$foo->testErrorHandler();5$foo = new foo();6$foo->testErrorHandler();7$foo = new foo();8$foo->testErrorHandler();9$foo = new foo();10$foo->testErrorHandler();11$foo = new foo();12$foo->testErrorHandler();13$foo = new foo();14$foo->testErrorHandler();15$foo = new foo();16$foo->testErrorHandler();17$foo = new foo();18$foo->testErrorHandler();19$foo = new foo();20$foo->testErrorHandler();21$foo = new foo();22$foo->testErrorHandler();23$foo = new foo();24$foo->testErrorHandler();25$foo = new foo();26$foo->testErrorHandler();27$foo = new foo();28$foo->testErrorHandler();29$foo = new foo();30$foo->testErrorHandler();31$foo = new foo();32$foo->testErrorHandler();33$foo = new foo();34$foo->testErrorHandler();

Full Screen

Full Screen

testErrorHandler

Using AI Code Generation

copy

Full Screen

1$foo = new Foo();2$foo->testErrorHandler();3$foo = new Foo();4$foo->testErrorHandler();5$foo = new Foo();6$foo->testErrorHandler();7$foo = new Foo();8$foo->testErrorHandler();9$foo = new Foo();10$foo->testErrorHandler();11$foo = new Foo();12$foo->testErrorHandler();13$foo = new Foo();14$foo->testErrorHandler();15$foo = new Foo();16$foo->testErrorHandler();17$foo = new Foo();18$foo->testErrorHandler();19$foo = new Foo();20$foo->testErrorHandler();21$foo = new Foo();22$foo->testErrorHandler();23$foo = new Foo();24$foo->testErrorHandler();25$foo = new Foo();26$foo->testErrorHandler();27$foo = new Foo();28$foo->testErrorHandler();29$foo = new Foo();30$foo->testErrorHandler();31$foo = new Foo();32$foo->testErrorHandler();33$foo = new Foo();34$foo->testErrorHandler();

Full Screen

Full Screen

testErrorHandler

Using AI Code Generation

copy

Full Screen

1$foo = new foo();2$foo->testErrorHandler();3$foo = new foo();4$foo->testErrorHandler();5Fatal error: Call to a member function testErrorHandler() on a non-object in /var/www/html/1.php on line 36Fatal error: Call to a member function testErrorHandler() on a non-object in /var/www/html/2.php on line 3

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.

Most used method in foo

Trigger testErrorHandler code on LambdaTest Cloud Grid

Execute automation tests with testErrorHandler on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

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