Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/digitalpianism/testframework
A simple test framework repo for Magento 1
https://github.com/digitalpianism/testframework
Last synced: 3 months ago
JSON representation
A simple test framework repo for Magento 1
- Host: GitHub
- URL: https://github.com/digitalpianism/testframework
- Owner: digitalpianism
- Created: 2016-06-27T11:05:29.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-13T13:02:38.000Z (over 6 years ago)
- Last Synced: 2024-07-12T17:56:11.859Z (4 months ago)
- Language: PHP
- Size: 14.6 KB
- Stars: 49
- Watchers: 8
- Forks: 14
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- mageres - Digital Pianism Test Framework - A simple framework to be used to create unit and integration tests on Magento 1 (Testing / Free)
README
# Digital Pianism Test Framework
A simple test framework module that can be used to create unit and integration tests on Magento 1.
## Prepare your module for your tests
- Create a `Test` folder under your module folder
- Under this `Test` folder create the following files:`phpunit.xml` with the following content:
.
Note that you can change most of the file here, the important part being the `bootstrap.php` file declaration.
`bootstrap.php` with the following content:
setResponse($stubResponse);
// Possible parameter
// Mage::app()->getRequest()->setParam('myparameter', 'myvalue');// Use the controller helper
$controllerTestHelper = new \DigitalPianism_TestFramework_Helper_ControllerTestHelper($this);// Dispatch a GET request
$controllerTestHelper->dispatchGetRequest('route', 'controller', 'action');
// Dispatch a POST request
//$controllerTestHelper->dispatchPostRequest('route', 'controller', 'action');
}public function testSomething()
{
// Get the body
$body = Mage::app()->getResponse()->getBody(true);// Get the headers
$headers = Mage::app()->getResponse()->getHeaders();// Get a block
$block = Mage::app()->getLayout()->getBlock('block_name');// Do your tests here
}
}## Using test doubles
As you may have noticed, the `bootstrap.php` injects a custom instance of the config class `DigitalPianism_TestFramework_Model_Config`
This class declares several new methods:
- `setModelTestDouble` for model test doubles
- `setResourceModelTestDouble` for resource model test doubles
- `setHelperTestDouble` for helper test doublesTo use test doubles you can do the following in your `setUp` method.
Let's say you want to check what template ID is assigned to `Mage_Core_Model_Email_Template_Mailer` when the new customer account email is sent:
$mailer = Mage::getModel('core/email_template_mailer');
Mage::getConfig()->setModelTestDouble('core/email_template_mailer', $mailer);$customer->sendNewAccountEmail();
$this->assertSame($expectedEmailTemplateId, $mailer->getTemplateId());
## Fixtures
You can create fixtures programmatically in your code.
A good recommendation to avoid having to manually delete your fixtures is to call `Mage::getSingleton('core/resource')->getConnection('core_write')->beginTransaction();` in the `setUp` method and then call `Mage::getSingleton('core/resource')->getConnection('core_write')->rollBack();` in the `tearDown` method