Skip to content

Commit f502455

Browse files
committed
MAGETWO-53858: Uncaught 'undefined property' notices in REST tests
1 parent c4e5f20 commit f502455

File tree

5 files changed

+166
-48
lines changed

5 files changed

+166
-48
lines changed

dev/tests/api-functional/framework/bootstrap.php

+25-24
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,32 @@ function setCustomErrorHandler()
112112
{
113113
set_error_handler(
114114
function ($errNo, $errStr, $errFile, $errLine) {
115-
$errorNames = [
116-
E_ERROR => 'Error',
117-
E_WARNING => 'Warning',
118-
E_PARSE => 'Parse',
119-
E_NOTICE => 'Notice',
120-
E_CORE_ERROR => 'Core Error',
121-
E_CORE_WARNING => 'Core Warning',
122-
E_COMPILE_ERROR => 'Compile Error',
123-
E_COMPILE_WARNING => 'Compile Warning',
124-
E_USER_ERROR => 'User Error',
125-
E_USER_WARNING => 'User Warning',
126-
E_USER_NOTICE => 'User Notice',
127-
E_STRICT => 'Strict',
128-
E_RECOVERABLE_ERROR => 'Recoverable Error',
129-
E_DEPRECATED => 'Deprecated',
130-
E_USER_DEPRECATED => 'User Deprecated',
131-
];
115+
if (error_reporting()) {
116+
$errorNames = [
117+
E_ERROR => 'Error',
118+
E_WARNING => 'Warning',
119+
E_PARSE => 'Parse',
120+
E_NOTICE => 'Notice',
121+
E_CORE_ERROR => 'Core Error',
122+
E_CORE_WARNING => 'Core Warning',
123+
E_COMPILE_ERROR => 'Compile Error',
124+
E_COMPILE_WARNING => 'Compile Warning',
125+
E_USER_ERROR => 'User Error',
126+
E_USER_WARNING => 'User Warning',
127+
E_USER_NOTICE => 'User Notice',
128+
E_STRICT => 'Strict',
129+
E_RECOVERABLE_ERROR => 'Recoverable Error',
130+
E_DEPRECATED => 'Deprecated',
131+
E_USER_DEPRECATED => 'User Deprecated',
132+
];
132133

133-
$errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
134+
$errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
134135

135-
throw new \PHPUnit_Framework_Exception(
136-
sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
137-
$errNo
138-
);
139-
},
140-
E_ALL
136+
throw new \PHPUnit_Framework_Exception(
137+
sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
138+
$errNo
139+
);
140+
}
141+
}
141142
);
142143
}

dev/tests/functional/bootstrap.php

+39
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,42 @@
1212
require_once __DIR__ . '/../../../app/bootstrap.php';
1313
restore_error_handler();
1414
require_once __DIR__ . '/vendor/autoload.php';
15+
16+
setCustomErrorHandler();
17+
18+
/**
19+
* Set custom error handler
20+
*/
21+
function setCustomErrorHandler()
22+
{
23+
set_error_handler(
24+
function ($errNo, $errStr, $errFile, $errLine) {
25+
if (error_reporting()) {
26+
$errorNames = [
27+
E_ERROR => 'Error',
28+
E_WARNING => 'Warning',
29+
E_PARSE => 'Parse',
30+
E_NOTICE => 'Notice',
31+
E_CORE_ERROR => 'Core Error',
32+
E_CORE_WARNING => 'Core Warning',
33+
E_COMPILE_ERROR => 'Compile Error',
34+
E_COMPILE_WARNING => 'Compile Warning',
35+
E_USER_ERROR => 'User Error',
36+
E_USER_WARNING => 'User Warning',
37+
E_USER_NOTICE => 'User Notice',
38+
E_STRICT => 'Strict',
39+
E_RECOVERABLE_ERROR => 'Recoverable Error',
40+
E_DEPRECATED => 'Deprecated',
41+
E_USER_DEPRECATED => 'User Deprecated',
42+
];
43+
44+
$errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
45+
46+
throw new \PHPUnit_Framework_Exception(
47+
sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
48+
$errNo
49+
);
50+
}
51+
}
52+
);
53+
}

dev/tests/integration/framework/bootstrap.php

+25-24
Original file line numberDiff line numberDiff line change
@@ -99,31 +99,32 @@ function setCustomErrorHandler()
9999
{
100100
set_error_handler(
101101
function ($errNo, $errStr, $errFile, $errLine) {
102-
$errorNames = [
103-
E_ERROR => 'Error',
104-
E_WARNING => 'Warning',
105-
E_PARSE => 'Parse',
106-
E_NOTICE => 'Notice',
107-
E_CORE_ERROR => 'Core Error',
108-
E_CORE_WARNING => 'Core Warning',
109-
E_COMPILE_ERROR => 'Compile Error',
110-
E_COMPILE_WARNING => 'Compile Warning',
111-
E_USER_ERROR => 'User Error',
112-
E_USER_WARNING => 'User Warning',
113-
E_USER_NOTICE => 'User Notice',
114-
E_STRICT => 'Strict',
115-
E_RECOVERABLE_ERROR => 'Recoverable Error',
116-
E_DEPRECATED => 'Deprecated',
117-
E_USER_DEPRECATED => 'User Deprecated',
118-
];
102+
if (error_reporting()) {
103+
$errorNames = [
104+
E_ERROR => 'Error',
105+
E_WARNING => 'Warning',
106+
E_PARSE => 'Parse',
107+
E_NOTICE => 'Notice',
108+
E_CORE_ERROR => 'Core Error',
109+
E_CORE_WARNING => 'Core Warning',
110+
E_COMPILE_ERROR => 'Compile Error',
111+
E_COMPILE_WARNING => 'Compile Warning',
112+
E_USER_ERROR => 'User Error',
113+
E_USER_WARNING => 'User Warning',
114+
E_USER_NOTICE => 'User Notice',
115+
E_STRICT => 'Strict',
116+
E_RECOVERABLE_ERROR => 'Recoverable Error',
117+
E_DEPRECATED => 'Deprecated',
118+
E_USER_DEPRECATED => 'User Deprecated',
119+
];
119120

120-
$errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
121+
$errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
121122

122-
throw new \PHPUnit_Framework_Exception(
123-
sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
124-
$errNo
125-
);
126-
},
127-
E_ALL
123+
throw new \PHPUnit_Framework_Exception(
124+
sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
125+
$errNo
126+
);
127+
}
128+
}
128129
);
129130
}

dev/tests/static/framework/bootstrap.php

+39
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,48 @@
1414

1515
require __DIR__ . '/autoload.php';
1616

17+
setCustomErrorHandler();
18+
1719
$componentRegistrar = new ComponentRegistrar();
1820
$dirSearch = new DirSearch($componentRegistrar, new ReadFactory(new DriverPool()));
1921
$themePackageList = new ThemePackageList($componentRegistrar, new ThemePackageFactory());
2022
\Magento\Framework\App\Utility\Files::setInstance(
2123
new Files($componentRegistrar, $dirSearch, $themePackageList)
2224
);
25+
26+
/**
27+
* Set custom error handler
28+
*/
29+
function setCustomErrorHandler()
30+
{
31+
set_error_handler(
32+
function ($errNo, $errStr, $errFile, $errLine) {
33+
if (error_reporting()) {
34+
$errorNames = [
35+
E_ERROR => 'Error',
36+
E_WARNING => 'Warning',
37+
E_PARSE => 'Parse',
38+
E_NOTICE => 'Notice',
39+
E_CORE_ERROR => 'Core Error',
40+
E_CORE_WARNING => 'Core Warning',
41+
E_COMPILE_ERROR => 'Compile Error',
42+
E_COMPILE_WARNING => 'Compile Warning',
43+
E_USER_ERROR => 'User Error',
44+
E_USER_WARNING => 'User Warning',
45+
E_USER_NOTICE => 'User Notice',
46+
E_STRICT => 'Strict',
47+
E_RECOVERABLE_ERROR => 'Recoverable Error',
48+
E_DEPRECATED => 'Deprecated',
49+
E_USER_DEPRECATED => 'User Deprecated',
50+
];
51+
52+
$errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
53+
54+
throw new \PHPUnit_Framework_Exception(
55+
sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
56+
$errNo
57+
);
58+
}
59+
}
60+
);
61+
}

dev/tests/unit/framework/bootstrap.php

+38
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,46 @@
1313
require_once __DIR__ . '/autoload.php';
1414
require BP . '/app/functions.php';
1515

16+
setCustomErrorHandler();
1617

1718
\Magento\Framework\Phrase::setRenderer(new \Magento\Framework\Phrase\Renderer\Placeholder());
1819

1920
error_reporting(E_ALL);
2021
ini_set('display_errors', 1);
22+
23+
/**
24+
* Set custom error handler
25+
*/
26+
function setCustomErrorHandler()
27+
{
28+
set_error_handler(
29+
function ($errNo, $errStr, $errFile, $errLine) {
30+
if (error_reporting()) {
31+
$errorNames = [
32+
E_ERROR => 'Error',
33+
E_WARNING => 'Warning',
34+
E_PARSE => 'Parse',
35+
E_NOTICE => 'Notice',
36+
E_CORE_ERROR => 'Core Error',
37+
E_CORE_WARNING => 'Core Warning',
38+
E_COMPILE_ERROR => 'Compile Error',
39+
E_COMPILE_WARNING => 'Compile Warning',
40+
E_USER_ERROR => 'User Error',
41+
E_USER_WARNING => 'User Warning',
42+
E_USER_NOTICE => 'User Notice',
43+
E_STRICT => 'Strict',
44+
E_RECOVERABLE_ERROR => 'Recoverable Error',
45+
E_DEPRECATED => 'Deprecated',
46+
E_USER_DEPRECATED => 'User Deprecated',
47+
];
48+
49+
$errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
50+
51+
throw new \PHPUnit_Framework_Exception(
52+
sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
53+
$errNo
54+
);
55+
}
56+
}
57+
);
58+
}

0 commit comments

Comments
 (0)