betooliveira/codeception-magento

Codeception To Integrate with Magento

This package's canonical repository appears to be gone and the package has been frozen as a result.

0.0.11 2016-07-03 05:11 UTC

This package is not auto-updated.

Last update: 2019-02-21 18:04:01 UTC


README

Composer install

composer require betooliveira/codeception-magento

Config

codeception.yml

extensions:
    enabled:
        - Codeception\Extension\RunFailed
        - Magento\Codeception\Extension\Magento
    config:
        Magento\Codeception\Extension\Magento:
            magento-dir: 'src'

unit.suite.yml

class_name: UnitTester
modules:
    enabled:
        - Asserts
        - \Helper\Unit
        - \Magento\Codeception\Helper\Magento

Mock Models

    $modelMock = $this->getMockBuilder('Custom_Custom_Model_Custom')
        ->setMethods(array('getData'))
        ->getMock();

    $modelMock->expects($this->once())
        ->method('getData')
        ->will($this->returnValue(array('teste)));

    $this->tester->replaceModelByMock('custom/custom', $modelMock);
    
    $result = Mage::getModel('custom/custom);
		
	$this->tester->assertSame($modelMock, $result);

Mock Singletons

    $singletonMock = $this->getMockBuilder('Custom_Custom_Model_Custom')
        ->setMethods(array('getData'))
        ->getMock();

    $singletonMock->expects($this->once())
        ->method('getData')
        ->will($this->returnValue(array('teste)));

    $this->tester->replaceSingletonByMock('custom/custom', $singletonMock);
	
	$result = Mage::getSingleton('custom/custom);
		
	$this->tester->assertSame($singletonMock, $result);

Mock Helper

    $helperMock = $this->getMockBuilder('Custom_Custom_helper_Custom')
        ->setMethods(array('getData'))
        ->getMock();

    $helperMock->expects($this->once())
        ->method('getData')
        ->will($this->returnValue(array('teste)));

    $this->tester->replaceHelperByMock('custom/custom', $helperMock);
	
	$result = Mage::helper('custom/custom);
		
	$this->tester->assertSame($helperMock, $result);