Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 2147ae6

Browse files
committedMay 23, 2016
Merge branch 'hotfix/errorHandling' of https://github.com/heiglandreas/zend-ldap into hotfix/47
2 parents f1a18f3 + baaa8e1 commit 2147ae6

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed
 

‎src/ErrorHandler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected static function getErrorHandler()
7070
*/
7171
public function startErrorHandling($level = E_WARNING)
7272
{
73-
// Do nothing!
73+
set_error_handler(function ($errNo, $errString) {});
7474
}
7575

7676
/**
@@ -83,7 +83,7 @@ public function startErrorHandling($level = E_WARNING)
8383
*/
8484
public function stopErrorHandling($throw = false)
8585
{
86-
// Do nothing;
86+
restore_error_handler();
8787
}
8888

8989
/**

‎test/ErrorHandlerTest.php

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace ZendTest\Ldap;
11+
12+
use Zend\Ldap\ErrorHandler;
13+
14+
/**
15+
* @group Zend_Ldap
16+
*/
17+
class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
18+
{
19+
protected $dummyErrorHandler;
20+
21+
protected $currentErrorHandler = [
22+
'PHPUnit_Util_ErrorHandler',
23+
'handleError',
24+
];
25+
26+
public function setup()
27+
{
28+
$this->dummyErrorHandler = function ($errno, $error) {};
29+
}
30+
public function testErrorHandlerSettingWorks()
31+
{
32+
$errorHandler = new ErrorHandler();
33+
34+
$this->assertEquals($this->currentErrorHandler, set_error_handler($this->dummyErrorHandler));
35+
$errorHandler->startErrorHandling();
36+
$this->assertEquals($this->dummyErrorHandler, set_error_handler($this->dummyErrorHandler));
37+
38+
restore_error_handler();
39+
restore_error_handler();
40+
}
41+
42+
public function testErrorHandlerREmovalWorks()
43+
{
44+
$errorHandler = new ErrorHandler();
45+
46+
$this->assertEquals($this->currentErrorHandler, set_error_handler($this->dummyErrorHandler));
47+
$errorHandler->stopErrorHandling();
48+
$this->assertEquals($this->currentErrorHandler, set_error_handler($this->dummyErrorHandler));
49+
50+
restore_error_handler();
51+
}
52+
}

‎test/bootstrap.php

-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
*/
1616
require __DIR__ . '/../vendor/autoload.php';
1717

18-
/**
19-
* Setting the ZendTest\Ldap\ErrorHandler as default ErrorHandler
20-
*/
21-
Zend\Ldap\ErrorHandler::setErrorHandler(new ZendTest\Ldap\ErrorHandler());
22-
2318
/**
2419
* Start output buffering, if enabled
2520
*/

0 commit comments

Comments
 (0)
This repository has been archived.