DataProviderFromFile.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\TestFramework\Annotation;
  7. use Magento\TestFramework\Deploy\CliCommand;
  8. use Magento\TestFramework\Deploy\TestModuleManager;
  9. use Magento\TestFramework\TestCase\MutableDataInterface;
  10. /**
  11. * Handler for applying reinstallMagento annotation.
  12. */
  13. class DataProviderFromFile
  14. {
  15. /**
  16. * @var TestModuleManager
  17. */
  18. private $moduleManager;
  19. /**
  20. * @var CliCommand
  21. */
  22. private $cliCommand;
  23. /**
  24. * CopyModules constructor.
  25. */
  26. public function __construct()
  27. {
  28. $this->moduleManager = new TestModuleManager();
  29. $this->cliCommand = new CliCommand($this->moduleManager);
  30. }
  31. /**
  32. * Start test.
  33. *
  34. * @param \PHPUnit\Framework\TestCase $test
  35. * @throws \Exception
  36. */
  37. public function startTest(\PHPUnit\Framework\TestCase $test)
  38. {
  39. $annotations = $test->getAnnotations();
  40. //This annotation can be declared only on method level
  41. if (isset($annotations['method']['dataProviderFromFile']) && $test instanceof MutableDataInterface) {
  42. $data = include TESTS_MODULES_PATH . "/" . $annotations['method']['dataProviderFromFile'][0];
  43. $test->setData($data);
  44. } else if (!$test instanceof MutableDataInterface) {
  45. throw new \Exception("Test type do not supports @dataProviderFromFile annotation");
  46. }
  47. }
  48. /**
  49. * Finish test.
  50. *
  51. * @param \PHPUnit\Framework\TestCase $test
  52. * @throws \Exception
  53. */
  54. public function endTest(\PHPUnit\Framework\TestCase $test)
  55. {
  56. if ($test instanceof MutableDataInterface) {
  57. $test->flushData();
  58. }
  59. }
  60. }