diff --git a/bin/ece-tools b/bin/ece-tools index ece7a97714..543e6be0f8 100755 --- a/bin/ece-tools +++ b/bin/ece-tools @@ -4,7 +4,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -require_once __DIR__ . '/../autoload.php'; +require_once __DIR__ . '/../bootstrap.php'; $application = \Magento\MagentoCloud\App\Bootstrap::create()->createApplication(); $application->run(); diff --git a/bootstrap.php b/bootstrap.php new file mode 100644 index 0000000000..26a66ed25a --- /dev/null +++ b/bootstrap.php @@ -0,0 +1,12 @@ +createApplication(); $application->setDefaultCommand('build'); diff --git a/m2-ece-deploy b/m2-ece-deploy index 0cac6e51e2..0775973da4 100755 --- a/m2-ece-deploy +++ b/m2-ece-deploy @@ -4,7 +4,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -require_once __DIR__ . '/autoload.php'; +require_once __DIR__ . '/bootstrap.php'; $application = \Magento\MagentoCloud\App\Bootstrap::create()->createApplication(); $application->setDefaultCommand('deploy'); diff --git a/m2-ece-scd-dump b/m2-ece-scd-dump index 27e4ab16d2..4888d31cdb 100755 --- a/m2-ece-scd-dump +++ b/m2-ece-scd-dump @@ -4,7 +4,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -require_once __DIR__ . '/autoload.php'; +require_once __DIR__ . '/bootstrap.php'; $application = \Magento\MagentoCloud\App\Bootstrap::create()->createApplication(); $application->setDefaultCommand('dump'); diff --git a/src/App/ErrorHandler.php b/src/App/ErrorHandler.php new file mode 100644 index 0000000000..d5e2d1656a --- /dev/null +++ b/src/App/ErrorHandler.php @@ -0,0 +1,66 @@ + 'Error', + E_WARNING => 'Warning', + E_PARSE => 'Parse Error', + E_NOTICE => 'Notice', + E_CORE_ERROR => 'Core Error', + E_CORE_WARNING => 'Core Warning', + E_COMPILE_ERROR => 'Compile Error', + E_COMPILE_WARNING => 'Compile Warning', + E_USER_ERROR => 'User Error', + E_USER_WARNING => 'User Warning', + E_USER_NOTICE => 'User Notice', + E_STRICT => 'Strict Notice', + E_RECOVERABLE_ERROR => 'Recoverable Error', + E_DEPRECATED => 'Deprecated Functionality', + E_USER_DEPRECATED => 'User Deprecated Functionality', + ]; + + /** + * Custom error handler. + * + * @param int $errorNo + * @param string $errorStr + * @param string $errorFile + * @param int $errorLine + * @return bool + * @throws \Exception + */ + public function handle($errorNo, $errorStr, $errorFile, $errorLine) + { + if (strpos($errorStr, 'DateTimeZone::__construct') !== false) { + /** + * There's no way to distinguish between caught system exceptions and warnings. + */ + return false; + } + + $errorNo = $errorNo & error_reporting(); + + if ($errorNo == 0) { + return false; + } + + $msg = isset($this->errorPhrases[$errorNo]) ? $this->errorPhrases[$errorNo] : "Unknown error ({$errorNo})"; + $msg .= ": {$errorStr} in {$errorFile} on line {$errorLine}"; + + throw new \Exception($msg); + } +} diff --git a/src/Test/Unit/App/ErrorHandlerTest.php b/src/Test/Unit/App/ErrorHandlerTest.php new file mode 100644 index 0000000000..c2482b58c2 --- /dev/null +++ b/src/Test/Unit/App/ErrorHandlerTest.php @@ -0,0 +1,60 @@ +handler = new ErrorHandler(); + } + + public function testHandleDatetime() + { + $this->assertFalse( + $this->handler->handle(1, 'DateTimeZone::__construct', 'some_file.php', 1) + ); + } + + public function testHandleNoError() + { + $this->assertFalse( + $this->handler->handle(0, 'Some string', 'some_file.php', 1) + ); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Error: Some string in some_file.php on line 1 + */ + public function testHandleWithException() + { + $this->handler->handle(1, 'Some string', 'some_file.php', 1); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Unknown error (3): Some string in some_file.php on line 1 + */ + public function testHandleWithUnknownException() + { + $this->handler->handle(3, 'Some string', 'some_file.php', 1); + } +} diff --git a/tests/integration/bootstrap.php b/tests/integration/bootstrap.php index a731c283fc..1b23a715e5 100644 --- a/tests/integration/bootstrap.php +++ b/tests/integration/bootstrap.php @@ -3,6 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -require __DIR__ . '/../../autoload.php'; +require __DIR__ . '/../../bootstrap.php'; \Magento\MagentoCloud\Test\Integration\Bootstrap::create()->run(); diff --git a/tests/unit/phpunit.xml.dist b/tests/unit/phpunit.xml.dist index de58085e9c..ba8cb4378b 100644 --- a/tests/unit/phpunit.xml.dist +++ b/tests/unit/phpunit.xml.dist @@ -4,7 +4,7 @@ xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd" colors="true" columns="max" - bootstrap="../../autoload.php" + bootstrap="../../bootstrap.php" beStrictAboutTestsThatDoNotTestAnything="false" >