Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Transaction Class Reference

Public Member Functions

 __construct (\Magento\TestFramework\EventManager $eventManager)
 
 startTest (\PHPUnit\Framework\TestCase $test)
 
 endTest (\PHPUnit\Framework\TestCase $test)
 
 endTestSuite ()
 

Protected Member Functions

 _processTransactionRequests ($eventName, \PHPUnit\Framework\TestCase $test)
 
 _startTransaction (\PHPUnit\Framework\TestCase $test)
 
 _rollbackTransaction ()
 
 _getEventParam ()
 

Protected Attributes

 $_eventManager
 
 $_eventParam
 
 $_isTransactionActive = false
 

Detailed Description

Definition at line 12 of file Transaction.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\TestFramework\EventManager  $eventManager)

Constructor

Parameters
\Magento\TestFramework\EventManager$eventManager

Definition at line 34 of file Transaction.php.

35  {
36  $this->_eventManager = $eventManager;
37  }

Member Function Documentation

◆ _getEventParam()

_getEventParam ( )
protected

Retrieve clean instance of transaction event parameter

Returns
\Magento\TestFramework\Event\Param\Transaction

Definition at line 140 of file Transaction.php.

141  {
142  /* reset object state instead of instantiating new object over and over again */
143  if (!$this->_eventParam) {
144  $this->_eventParam = new \Magento\TestFramework\Event\Param\Transaction();
145  } else {
146  $this->_eventParam->__construct();
147  }
148  return $this->_eventParam;
149  }

◆ _processTransactionRequests()

_processTransactionRequests (   $eventName,
\PHPUnit\Framework\TestCase  $test 
)
protected

Query whether there are any requests for transaction operations and performs them

Parameters
string$eventName
\PHPUnit\Framework\TestCase$test

Definition at line 73 of file Transaction.php.

74  {
75  $param = $this->_getEventParam();
76  $this->_eventManager->fireEvent($eventName . 'TransactionRequest', [$test, $param]);
77  if ($param->isTransactionRollbackRequested()) {
78  $this->_rollbackTransaction();
79  }
80  if ($param->isTransactionStartRequested()) {
81  $this->_startTransaction($test);
82  }
83  }
_startTransaction(\PHPUnit\Framework\TestCase $test)
Definition: Transaction.php:90

◆ _rollbackTransaction()

_rollbackTransaction ( )
protected

Rollback transaction and fire 'rollbackTransaction' event

Definition at line 110 of file Transaction.php.

111  {
112  if ($this->_isTransactionActive) {
113  $this->_getConnection()->rollbackTransparentTransaction();
114  $this->_isTransactionActive = false;
115  $this->_eventManager->fireEvent('rollbackTransaction');
116  $this->_getConnection()->closeConnection();
117  }
118  }

◆ _startTransaction()

_startTransaction ( \PHPUnit\Framework\TestCase  $test)
protected

Start transaction and fire 'startTransaction' event

Parameters
\PHPUnit\Framework\TestCase$test

Definition at line 90 of file Transaction.php.

91  {
92  if (!$this->_isTransactionActive) {
93  $this->_getConnection()->beginTransparentTransaction();
94  $this->_isTransactionActive = true;
95  try {
96  $this->_eventManager->fireEvent('startTransaction', [$test]);
97  } catch (\Exception $e) {
98  $test->getTestResultObject()->addFailure(
99  $test,
100  new \PHPUnit\Framework\AssertionFailedError((string)$e),
101  0
102  );
103  }
104  }
105  }

◆ endTest()

endTest ( \PHPUnit\Framework\TestCase  $test)

Handler for 'endTest' event

Parameters
\PHPUnit\Framework\TestCase$test

Definition at line 54 of file Transaction.php.

55  {
56  $this->_processTransactionRequests('endTest', $test);
57  }
_processTransactionRequests($eventName, \PHPUnit\Framework\TestCase $test)
Definition: Transaction.php:73

◆ endTestSuite()

endTestSuite ( )

Handler for 'endTestSuite' event

Definition at line 62 of file Transaction.php.

◆ startTest()

startTest ( \PHPUnit\Framework\TestCase  $test)

Handler for 'startTest' event

Parameters
\PHPUnit\Framework\TestCase$test

Definition at line 44 of file Transaction.php.

45  {
46  $this->_processTransactionRequests('startTest', $test);
47  }
_processTransactionRequests($eventName, \PHPUnit\Framework\TestCase $test)
Definition: Transaction.php:73

Field Documentation

◆ $_eventManager

$_eventManager
protected

Definition at line 17 of file Transaction.php.

◆ $_eventParam

$_eventParam
protected

Definition at line 22 of file Transaction.php.

◆ $_isTransactionActive

$_isTransactionActive = false
protected

Definition at line 27 of file Transaction.php.


The documentation for this class was generated from the following file: