bootstrap.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. use Magento\Framework\App\Utility\Files;
  7. use Magento\Framework\Component\ComponentRegistrar;
  8. use Magento\Framework\Component\DirSearch;
  9. use Magento\Framework\Filesystem\Directory\ReadFactory;
  10. use Magento\Framework\Filesystem\DriverPool;
  11. use Magento\Framework\View\Design\Theme\ThemePackageList;
  12. use Magento\Framework\View\Design\Theme\ThemePackageFactory;
  13. require __DIR__ . '/autoload.php';
  14. if (!defined('TESTS_TEMP_DIR')) {
  15. define('TESTS_TEMP_DIR', __DIR__ . DIRECTORY_SEPARATOR . 'tmp');
  16. }
  17. setCustomErrorHandler();
  18. $componentRegistrar = new ComponentRegistrar();
  19. $dirSearch = new DirSearch($componentRegistrar, new ReadFactory(new DriverPool()));
  20. $themePackageList = new ThemePackageList($componentRegistrar, new ThemePackageFactory());
  21. $serializer = new \Magento\Framework\Serialize\Serializer\Json();
  22. $regexIteratorFactory = new Magento\Framework\App\Utility\RegexIteratorFactory();
  23. \Magento\Framework\App\Utility\Files::setInstance(
  24. new Files($componentRegistrar, $dirSearch, $themePackageList, $serializer, $regexIteratorFactory)
  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. $errName = isset($errorNames[$errNo]) ? $errorNames[$errNo] : "";
  52. throw new \PHPUnit\Framework\Exception(
  53. sprintf("%s: %s in %s:%s.", $errName, $errStr, $errFile, $errLine),
  54. $errNo
  55. );
  56. }
  57. }
  58. );
  59. }