DocBlock.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\TestFramework\Bootstrap;
  7. use Magento\TestFramework\Application;
  8. /**
  9. * Bootstrap of the custom DocBlock annotations
  10. *
  11. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  12. */
  13. class DocBlock
  14. {
  15. /**
  16. * @var string
  17. */
  18. protected $_fixturesBaseDir;
  19. /**
  20. * @param string $fixturesBaseDir
  21. */
  22. public function __construct($fixturesBaseDir)
  23. {
  24. $this->_fixturesBaseDir = $fixturesBaseDir;
  25. }
  26. /**
  27. * Activate custom DocBlock annotations along with more-or-less permanent workarounds
  28. * @param Application $application
  29. */
  30. public function registerAnnotations(Application $application)
  31. {
  32. $eventManager = new \Magento\TestFramework\EventManager($this->_getSubscribers($application));
  33. \Magento\TestFramework\Event\PhpUnit::setDefaultEventManager($eventManager);
  34. \Magento\TestFramework\Event\Magento::setDefaultEventManager($eventManager);
  35. }
  36. /**
  37. * Get list of subscribers.
  38. *
  39. * Note: order of registering (and applying) annotations is important.
  40. * To allow config fixtures to deal with fixture stores, data fixtures should be processed first.
  41. * ConfigFixture applied twice because data fixtures could clean config and clean custom settings
  42. *
  43. * @param Application $application
  44. * @return array
  45. */
  46. protected function _getSubscribers(Application $application)
  47. {
  48. return [
  49. new \Magento\TestFramework\Workaround\Segfault(),
  50. new \Magento\TestFramework\Workaround\Cleanup\TestCaseProperties(),
  51. new \Magento\TestFramework\Workaround\Cleanup\StaticProperties(),
  52. new \Magento\TestFramework\Isolation\WorkingDirectory(),
  53. new \Magento\TestFramework\Isolation\DeploymentConfig(),
  54. new \Magento\TestFramework\Annotation\AppIsolation($application),
  55. new \Magento\TestFramework\Annotation\IndexerDimensionMode($application),
  56. new \Magento\TestFramework\Isolation\AppConfig(),
  57. new \Magento\TestFramework\Annotation\ConfigFixture(),
  58. new \Magento\TestFramework\Annotation\DataFixtureBeforeTransaction($this->_fixturesBaseDir),
  59. new \Magento\TestFramework\Event\Transaction(
  60. new \Magento\TestFramework\EventManager(
  61. [
  62. new \Magento\TestFramework\Annotation\DbIsolation(),
  63. new \Magento\TestFramework\Annotation\DataFixture($this->_fixturesBaseDir),
  64. ]
  65. )
  66. ),
  67. new \Magento\TestFramework\Annotation\ComponentRegistrarFixture($this->_fixturesBaseDir),
  68. new \Magento\TestFramework\Annotation\AppArea($application),
  69. new \Magento\TestFramework\Annotation\Cache($application),
  70. new \Magento\TestFramework\Annotation\AdminConfigFixture(),
  71. new \Magento\TestFramework\Annotation\ConfigFixture(),
  72. ];
  73. }
  74. }