12 use PHPUnit\Framework\Exception;
26 private $_appliedFixtures = [];
37 throw new \Magento\Framework\Exception\LocalizedException(
49 public function startTest(\PHPUnit\Framework\TestCase $test)
61 public function endTest(\PHPUnit\Framework\TestCase $test)
64 if ($this->_appliedFixtures && $this->
_getFixtures($test)) {
77 protected function _getFixtures(\PHPUnit\Framework\TestCase $test, $scope =
null)
79 if ($scope ===
null) {
80 $annotations = $this->getAnnotations($test);
82 $annotations = $test->getAnnotations()[$scope];
85 if (!empty($annotations[
'magentoDataFixtureBeforeTransaction'])) {
86 foreach ($annotations[
'magentoDataFixtureBeforeTransaction'] as $fixture) {
87 if (strpos($fixture,
'\\') !==
false) {
89 throw new \Magento\Framework\Exception\LocalizedException(
90 new \
Magento\Framework\
Phrase(
'Directory separator "\\" is prohibited in fixture declaration.')
93 $fixtureMethod = [get_class($test), $fixture];
94 if (is_callable($fixtureMethod)) {
97 $result[] = $this->_fixtureBaseDir .
'/' . $fixture;
108 private function getAnnotations(\PHPUnit\Framework\TestCase $test)
110 $annotations = $test->getAnnotations();
111 return array_replace($annotations[
'class'], $annotations[
'method']);
122 $annotations = $this->getAnnotations($test);
137 if (is_callable($fixture)) {
142 }
catch (\Exception $e) {
145 "Error in fixture: %s.\n %s\n %s",
146 json_encode($fixture),
148 $e->getTraceAsString()
165 foreach ($fixtures as $oneFixture) {
167 if (in_array($oneFixture, $this->_appliedFixtures,
true)) {
171 $this->_appliedFixtures[] = $oneFixture;
180 foreach ($this->_appliedFixtures as $fixture) {
181 if (is_callable($fixture)) {
182 $fixture[1] .=
'Rollback';
183 if (is_callable($fixture)) {
193 if (file_exists($rollbackScript)) {
198 $this->_appliedFixtures = [];
call_user_func($callable, $param)
_getFixtures(\PHPUnit\Framework\TestCase $test, $scope=null)
const MAGENTO_DB_ISOLATION
endTest(\PHPUnit\Framework\TestCase $test)
_applyFixtures(array $fixtures)
_applyOneFixture($fixture)
__construct($fixtureBaseDir)
startTest(\PHPUnit\Framework\TestCase $test)
getDbIsolationState(\PHPUnit\Framework\TestCase $test)