_bootstrap.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. error_reporting(~E_USER_NOTICE);
  7. define('PROJECT_ROOT', dirname(dirname(__DIR__)));
  8. $vendorAutoloadPath = realpath(PROJECT_ROOT . '/vendor/autoload.php');
  9. $mftfTestCasePath = realpath(PROJECT_ROOT . '/dev/tests/util/MftfTestCase.php');
  10. require_once $vendorAutoloadPath;
  11. require_once $mftfTestCasePath;
  12. // Set up AspectMock
  13. $kernel = \AspectMock\Kernel::getInstance();
  14. $kernel->init([
  15. 'debug' => true,
  16. 'includePaths' => [PROJECT_ROOT . DIRECTORY_SEPARATOR . 'src'],
  17. 'cacheDir' => PROJECT_ROOT .
  18. DIRECTORY_SEPARATOR .
  19. 'dev' .
  20. DIRECTORY_SEPARATOR .
  21. 'tests' .
  22. DIRECTORY_SEPARATOR .
  23. '.cache'
  24. ]);
  25. // set mftf appplication context
  26. \Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::create(
  27. true,
  28. \Magento\FunctionalTestingFramework\Config\MftfApplicationConfig::UNIT_TEST_PHASE,
  29. true,
  30. false
  31. );
  32. // Load needed framework env params
  33. $TEST_ENVS = [
  34. 'MAGENTO_BASE_URL' => 'http://baseurl:8080',
  35. 'MAGENTO_BACKEND_NAME' => 'admin',
  36. 'MAGENTO_ADMIN_USERNAME' => 'admin',
  37. 'MAGENTO_ADMIN_PASSWORD' => 'admin123',
  38. 'DEFAULT_TIMEZONE' => 'America/Los_Angeles'
  39. ];
  40. foreach ($TEST_ENVS as $key => $value) {
  41. $_ENV[$key] = $value;
  42. putenv("{$key}=${value}");
  43. }
  44. // Add our test module to the whitelist
  45. putenv('MODULE_WHITELIST=Magento_TestModule');
  46. // Define our own set of paths for the tests
  47. defined('FW_BP') || define('FW_BP', PROJECT_ROOT);
  48. $RELATIVE_TESTS_MODULE_PATH = DIRECTORY_SEPARATOR . 'verification';
  49. defined('TESTS_BP') || define('TESTS_BP', __DIR__);
  50. defined('TESTS_MODULE_PATH') || define('TESTS_MODULE_PATH', TESTS_BP . $RELATIVE_TESTS_MODULE_PATH);
  51. defined('MAGENTO_BP') || define('MAGENTO_BP', __DIR__);
  52. $utilDir = DIRECTORY_SEPARATOR . 'Util'. DIRECTORY_SEPARATOR . '*.php';
  53. //Load required util files from functional dir
  54. $functionalUtilFiles = glob(TESTS_BP . DIRECTORY_SEPARATOR . 'verification' . $utilDir);
  55. foreach (sortInterfaces($functionalUtilFiles) as $functionalUtilFile) {
  56. require($functionalUtilFile);
  57. }
  58. //Load required util files from unit dir
  59. $unitUtilFiles = glob(TESTS_BP . DIRECTORY_SEPARATOR . 'unit' . $utilDir);
  60. foreach (sortInterfaces($unitUtilFiles) as $unitUtilFile) {
  61. require($unitUtilFile);
  62. }
  63. // Mocks suite files location getter return to get files in verification/_suite Directory
  64. // This mocks the paths of the suite files but still parses the xml files
  65. $suiteDirectory = TESTS_BP . DIRECTORY_SEPARATOR . "verification" . DIRECTORY_SEPARATOR . "_suite";
  66. $paths = [
  67. $suiteDirectory . DIRECTORY_SEPARATOR . 'functionalSuite.xml',
  68. $suiteDirectory . DIRECTORY_SEPARATOR . 'functionalSuiteHooks.xml',
  69. $suiteDirectory . DIRECTORY_SEPARATOR . 'functionalSuiteExtends.xml'
  70. ];
  71. // create and return the iterator for these file paths
  72. $iterator = new Magento\FunctionalTestingFramework\Util\Iterator\File($paths);
  73. try {
  74. AspectMock\Test::double(
  75. Magento\FunctionalTestingFramework\Config\FileResolver\Root::class,
  76. ['get' => $iterator]
  77. )->make();
  78. } catch (Exception $e) {
  79. echo "Suite directory not mocked.";
  80. }
  81. function sortInterfaces($files)
  82. {
  83. $bottom = [];
  84. $top = [];
  85. foreach ($files as $file) {
  86. if (strstr(strtolower($file), 'interface')) {
  87. $top[] = $file;
  88. continue;
  89. }
  90. $bottom[] = $file;
  91. }
  92. return array_merge($top, $bottom);
  93. }