DeploymentConfig.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\TestFramework\Isolation;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. use Magento\Framework\App\DeploymentConfig\Reader;
  9. /**
  10. * A listener that watches for integrity of deployment configuration
  11. */
  12. class DeploymentConfig
  13. {
  14. /**
  15. * Deployment configuration reader
  16. *
  17. * @var Reader
  18. */
  19. private $reader;
  20. /**
  21. * Initial value of deployment configuration
  22. *
  23. * @var mixed
  24. */
  25. private $config;
  26. /**
  27. * Memorizes the initial value of configuration reader and the configuration value
  28. *
  29. * Assumption: this is done once right before executing very first test suite.
  30. * It is assumed that deployment configuration is valid at this point
  31. *
  32. * @return void
  33. */
  34. public function startTestSuite()
  35. {
  36. if (null === $this->reader) {
  37. $this->reader = Bootstrap::getObjectManager()->get(\Magento\Framework\App\DeploymentConfig\Reader::class);
  38. $this->config = $this->reader->load();
  39. }
  40. }
  41. /**
  42. * Checks if deployment configuration has been changed by a test
  43. *
  44. * Changing deployment configuration violates isolation between tests, so further tests may become broken.
  45. * To fix this issue, find out why this test changes deployment configuration.
  46. * If this is intentional, then it must be reverted to the previous state within the test.
  47. * After that, the application needs to be wiped out and reinstalled.
  48. *
  49. * @param \PHPUnit\Framework\TestCase $test
  50. * @return void
  51. */
  52. public function endTest(\PHPUnit\Framework\TestCase $test)
  53. {
  54. $config = $this->reader->load();
  55. if ($this->config != $config) {
  56. $error = "\n\nERROR: deployment configuration is corrupted. The application state is no longer valid.\n"
  57. . 'Further tests may fail.'
  58. . " This test failure may be misleading, if you are re-running it on a corrupted application.\n"
  59. . $test->toString() . "\n";
  60. $test->fail($error);
  61. }
  62. }
  63. }