12 use PHPUnit\Framework\Exception;
26 private $_appliedFixtures = [];
37 throw new \Magento\Framework\Exception\LocalizedException(
51 \PHPUnit\Framework\TestCase $test,
52 \
Magento\TestFramework\Event\Param\Transaction $param
57 $param->requestTransactionStart();
71 \PHPUnit\Framework\TestCase $test,
72 \
Magento\TestFramework\Event\Param\Transaction $param
75 if ($this->_appliedFixtures && $this->
_getFixtures($test)) {
77 $param->requestTransactionRollback();
110 protected function _getFixtures(\PHPUnit\Framework\TestCase $test, $scope =
null)
112 if ($scope ===
null) {
113 $annotations = $this->getAnnotations($test);
115 $annotations = $test->getAnnotations()[$scope];
118 if (!empty($annotations[
'magentoDataFixture'])) {
119 foreach ($annotations[
'magentoDataFixture'] as $fixture) {
120 if (strpos($fixture,
'\\') !==
false) {
122 throw new \Magento\Framework\Exception\LocalizedException(
123 new \
Magento\Framework\
Phrase(
'Directory separator "\\" is prohibited in fixture declaration.')
126 $fixtureMethod = [get_class($test), $fixture];
127 if (is_callable($fixtureMethod)) {
130 $result[] = $this->_fixtureBaseDir .
'/' . $fixture;
141 private function getAnnotations(\PHPUnit\Framework\TestCase $test)
143 $annotations = $test->getAnnotations();
144 return array_replace($annotations[
'class'], $annotations[
'method']);
155 $annotations = $this->getAnnotations($test);
170 if (is_callable($fixture)) {
175 }
catch (\Exception $e) {
178 "Error in fixture: %s.\n %s\n %s",
179 json_encode($fixture),
181 $e->getTraceAsString()
198 foreach ($fixtures as $oneFixture) {
200 if (in_array($oneFixture, $this->_appliedFixtures,
true)) {
204 $this->_appliedFixtures[] = $oneFixture;
213 $appliedFixtures = array_reverse($this->_appliedFixtures);
214 foreach ($appliedFixtures as $fixture) {
215 if (is_callable($fixture)) {
216 $fixture[1] .=
'Rollback';
217 if (is_callable($fixture)) {
227 if (file_exists($rollbackScript)) {
232 $this->_appliedFixtures = [];
__construct($fixtureBaseDir)
_getFixtures(\PHPUnit\Framework\TestCase $test, $scope=null)
call_user_func($callable, $param)
_applyOneFixture($fixture)
const MAGENTO_DB_ISOLATION
startTestTransactionRequest(\PHPUnit\Framework\TestCase $test, \Magento\TestFramework\Event\Param\Transaction $param)
_applyFixtures(array $fixtures)
getDbIsolationState(\PHPUnit\Framework\TestCase $test)
startTransaction(\PHPUnit\Framework\TestCase $test)
endTestTransactionRequest(\PHPUnit\Framework\TestCase $test, \Magento\TestFramework\Event\Param\Transaction $param)