Magento How-to: Testing Magento Modules
I’m sure a lot of Magento developers would agree that testing your models when creating a Magento module can be a bit difficult.
During the development of Meanbee’s Royalmail and Shipwire modules I have found the following script handy:
<?php require_once '../../../../Mage.php'; Varien_Profiler::enable(); Mage::setIsDeveloperMode(true); ini_set('display_errors', 1); umask(0); Mage::app(); $obj = Mage::getModel('shipwire/api_inventorysynch'); $obj->submitRequest(); ?>
I simply make a file, Test.php, in my module folder, app/code/community/Meanbee/Shipwire, for example, and then navigate to the file with my web browser, remembering to allow it through the .htaccess (and switch it back again). I then have access to the entire Magento class hierarchy along with any site specific settings to which I can perform arbitrary commands.
(EDIT: Remember that you could enable the profiler, set the development environment and enable the error reporting by placing those lines in your /index.php and feel the effects site wide.)
Pingback: Improving Magento’s Error Reporting | Nick Says
cheers
You have mentioned, “allow it through the .htaccess (and switch it back again)” several times in your posts. How is this done?
@Anthony:
.htaccesspermissions follow a hierarchy – the rules of the child are inherited from the parent. If we take this post as an example, we have two directories:app/app/code/community/Meanbee/Shipwire/In
app/there will be a file named.htaccesswhich says something along the lines of “DENY FROM ALL”. This will not allow the directory nor any files under it be displayed. If we have our Test.php inapp/code/community/Meanbee/Shipwire/then we would be unable to see it because of the inherited “DENY FROM ALL”.We can overcome this by placing another
.htaccessfile, this time inapp/code/community/Meanbee/Shipwire/, that reads “ALLOW FROM ALL”. This modifies the viewing permissions on the folders to disable viewing of files and directories underapp/except forapp/code/community/Meanbee/Shipwire/. We’ll then be able to see our Test.php!@Nick
Many thanks for the .htaccess tip