Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataFixtureTest.php
Go to the documentation of this file.
1 <?php
7 
13 class DataFixtureTest extends \PHPUnit\Framework\TestCase
14 {
18  protected $_object;
19 
20  protected function setUp()
21  {
22  $this->_object = $this->getMockBuilder(\Magento\TestFramework\Annotation\DataFixture::class)
23  ->setMethods(['_applyOneFixture'])
24  ->setConstructorArgs([__DIR__ . '/_files'])
25  ->getMock();
26  }
27 
28  public static function sampleFixtureOne()
29  {
30  }
31 
32  public static function sampleFixtureTwo()
33  {
34  }
35 
36  public static function sampleFixtureTwoRollback()
37  {
38  }
39 
43  public function testConstructorException()
44  {
45  new \Magento\TestFramework\Annotation\DataFixture(__DIR__ . '/non_existing_fixture_dir');
46  }
47 
49  {
50  $eventParam = new \Magento\TestFramework\Event\Param\Transaction();
51  $this->_object->startTestTransactionRequest($this, $eventParam);
52  $this->assertTrue($eventParam->isTransactionStartRequested());
53  $this->assertFalse($eventParam->isTransactionRollbackRequested());
54 
55  $eventParam = new \Magento\TestFramework\Event\Param\Transaction();
56  $this->_object->startTransaction($this);
57  $this->_object->startTestTransactionRequest($this, $eventParam);
58  $this->assertTrue($eventParam->isTransactionStartRequested());
59  }
60 
66  {
67  $eventParam = new \Magento\TestFramework\Event\Param\Transaction();
68  $this->_object->startTestTransactionRequest($this, $eventParam);
69  $this->assertTrue($eventParam->isTransactionStartRequested());
70  $this->assertFalse($eventParam->isTransactionRollbackRequested());
71 
72  $eventParam = new \Magento\TestFramework\Event\Param\Transaction();
73  $this->_object->startTransaction($this);
74  $this->_object->startTestTransactionRequest($this, $eventParam);
75  $this->assertTrue($eventParam->isTransactionStartRequested());
76  $this->assertFalse($eventParam->isTransactionRollbackRequested());
77  }
78 
84  public function testDisabledDbIsolation()
85  {
86  $eventParam = new \Magento\TestFramework\Event\Param\Transaction();
87  $this->_object->startTestTransactionRequest($this, $eventParam);
88  $this->assertFalse($eventParam->isTransactionStartRequested());
89  $this->assertFalse($eventParam->isTransactionRollbackRequested());
90 
91  $eventParam = new \Magento\TestFramework\Event\Param\Transaction();
92  $this->_object->startTransaction($this);
93  $this->_object->startTestTransactionRequest($this, $eventParam);
94  $this->assertFalse($eventParam->isTransactionStartRequested());
95  $this->assertFalse($eventParam->isTransactionRollbackRequested());
96  }
97 
103  {
104  $this->_object->startTestTransactionRequest($this, new \Magento\TestFramework\Event\Param\Transaction());
105  }
106 
112  {
113  $eventParam = new \Magento\TestFramework\Event\Param\Transaction();
114  $this->_object->endTestTransactionRequest($this, $eventParam);
115  $this->assertFalse($eventParam->isTransactionStartRequested());
116  $this->assertFalse($eventParam->isTransactionRollbackRequested());
117 
118  $eventParam = new \Magento\TestFramework\Event\Param\Transaction();
119  $this->_object->startTransaction($this);
120  $this->_object->endTestTransactionRequest($this, $eventParam);
121  $this->assertFalse($eventParam->isTransactionStartRequested());
122  $this->assertTrue($eventParam->isTransactionRollbackRequested());
123  }
124 
126  {
127  $this->_object->expects($this->once())->method('_applyOneFixture')->with([__CLASS__, 'sampleFixtureOne']);
128  $this->_object->startTransaction($this);
129  }
130 
136  {
137  $this->_object->expects($this->at(0))->method('_applyOneFixture')->with([__CLASS__, 'sampleFixtureTwo']);
138  $this->_object->expects(
139  $this->at(1)
140  )->method(
141  '_applyOneFixture'
142  )->with(
143  $this->stringEndsWith('path/to/fixture/script.php')
144  );
145  $this->_object->startTransaction($this);
146  }
147 
153  {
154  $this->_object->startTransaction($this);
155  $this->_object->expects(
156  $this->once()
157  )->method(
158  '_applyOneFixture'
159  )->with(
160  [__CLASS__, 'sampleFixtureTwoRollback']
161  );
162  $this->_object->rollbackTransaction();
163  }
164 
170  {
171  $this->_object->startTransaction($this);
172  $this->_object->expects(
173  $this->once()
174  )->method(
175  '_applyOneFixture'
176  )->with(
177  $this->stringEndsWith('sample_fixture_two_rollback.php')
178  );
179  $this->_object->rollbackTransaction();
180  }
181 }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60