How to start and cancel a database transaction to package a PHPUnit Magento package

I would like to use the transaction rollback method to isolate my database for unit testing purposes. Ideally, I would use a structure like this:

public static function setUpBeforeClass(){
    Mage_Core_Model_Resource_Transaction::beginTransaction();
}

public function testOne(){...}
public function testTwo(){...}

public static function tearDownAfterClass(){
    Mage_Core_Model_Resource_Transaction::rollBack();
}

Unfortunately, the class Mage_Core_Model_Resource_Transactiondoes not provide the public begin / rollbackTransaction function. I cannot find any public Magento functions to fulfill this requirement. Is there a Zend equivalent that will work?

I think I could rewrite Mage_Core_Model_Resource_Transactionand add public shells for protected methods, but I hesitate to redefine such a main class.

I also tried using

$this->model = Mage::getModel('model_being_tested');
$this->model->getResource()->beginTransaction(); 
...
$this->model->getResource()->rollBack();

and then use $this->modelin tests, but cannot be used in static functions.

? .

+3
1

, - Magento, , . , - , , . ( ), . Mage::app()->run(), .

, ... , , . mysql , .

UPDATE:

: http://www.ecomdev.org/2011/02/01/phpunit-and-magento-yes-you-can.html

+4

Source: https://habr.com/ru/post/1780555/


All Articles