Xtest

Simple Magento Testing Framework

Powererd code-x GmbH & webguys.de

## Features - Magento Testing Framework - created for integration tests - Based on PHPUnit and Selenium - Supports Frontend and Backend tests - Available on GitHub (OpenSource)

Area driven testing

  • Frontend
    • Selenium support
    • Take responsive screenshots
    • Simple login as customer
    • Dispatch routes and check html contents
  • Backend
    • Automatically logged in as admin

Mocking

Mock Models


$mock = $this->getModelMock('catalog/product', array('isAvailable') );
$mock->expects($this->any())
    ->method('isAvailable')
    ->willReturn($productIsAvailable);
$this->addModelMock('catalog/product', $mock);

or Helpers


$mock = $this->getHelperMock('codex_demo', array('getDemoMethod'));
$mock->expects($this->any())
    ->method('getDemoMethod')
    ->willReturn('some value');
$this->addHelperMock('codex_demo', $mock);

Doubles

  • Like permanent mocks
  • Useful for external references (like API models)

class Codex_Demo_Model_Weather extends Varien_Object
{
    protected function _apiCall($city, $country)
    {
        return file_get_contents('http://api.openweathermap.org/data/2.5/weather?q='.$city.','.$country);
    }
}
class Codex_Demo_Test_Double_Model_Weather extends Codex_Demo_Model_Weather
{
    protected function _apiCall($city, $country)
    {
        return '{ "coord": { "lon": 8.75, "lat": 51.72 }, "sys": { "type": 3, "id": 177301, "message": 0.0283, "country": "DE", "sunrise": 1425190178, "sunset": 1425229494 }, "weather": [ { "id": 803, "main": "Clouds", "description": "broken clouds", "icon": "04d" } ], "base": "cmc stations", "main": { "temp": 283.41, "humidity": 65, "pressure": 1001, "temp_min": 283.15, "temp_max": 283.55 }, "wind": { "speed": 1, "gust": 3, "deg": 180 }, "rain": { "3h": 0 }, "clouds": { "all": 64 }, "dt": 1425221237, "id": 2855745, "name": "Paderborn", "cod": 200 }';
    }
}
## Fixtures - Easily create xml based test objects like - customers - quotes - orders - ... - XML based (xtest.xml) - Separated from production xml - Overridable (Magento like)

Examples


/** @var $orderFixture Codex_Xtest_Xtest_Fixture_Order */
$orderFixture = Xtest::getXtest('xtest/fixture_order');
$testOrder = $orderFixture->getTest();

/** @var $customerFixture Codex_Xtest_Xtest_Fixture_Customer */
$customerFixture = Xtest::getXtest('xtest/fixture_customer');
$testCustomer = $customerFixture->getTest()

Mail-Tests

  • No outgoing mails in tests environments
  • Mailqueue catches all mails
  • Tests if mails have been invoked correctly

/** @var $mailqueue Codex_Xtest_Xtest_Helper_Mailqueue */
$mailqueue = Xtest::getXtest('xtest/helper_mailqueue');

$this->assertMailTemplateIdSent($yourTemplateId);
$this->assertMailsSent($yourMailsSentCount);

Happy testing!


cd htdocs/tests
php phpunit.phar ../app/code/local/