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