I am trying to implement a web service client for one of my module and I would like to test it using EcomDev_PHPUnit. So, I have a "Test" folder inside my module with following structure...
- Webservice
-- Clientservice
---Model
----Callservice.php
--- Test
----Model
-----Callservice.php
My "Callservice.php"
has a "httpRequest()"
function that does Mage::log("Hello world!");
And as I am testing a service, I don't need any fixtures as of now...
But when I try to run "phpunit UnitTests.php"...I see a series of errors.The first few lines are about EcomDev_PHPUnitTest module I think we can ignore it safely. The other errors says that
Warning
There is no module with name: webservice_clientservice
My config.xml top most few lines are as follows,
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Webservice_Clientservice>
<version>0.1.0</version>
</Webservice_Clientservice>
</modules>
...
...
<phpunit>
<suite>
<modules>
<Webservice_Clientservice />
</modules>
<groups>
<model>Model</model>
</groups>
</suite>
</phpunit>
</config>
My module xml file is Webservice_Clientservice.xml as follows,
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Webservice_Clientservice>
<active>true</active>
<codePool>community</codePool>
<depends>
</depends>
</Webservice_Clientservice>
</modules>
</config>
And when I use phpunit --filter <> UnitTests.php, I see the below -
PHPUnit 3.7.22 by Sebastian Bergmann.
Time: 1 second, Memory: 14.75Mb
No tests executed!
That leaves me perfectly confused. How do I write test cases(without test suites and later with test suites) in EcomDev_PHPUnit? Any pointers or same modules would be really great. Thanks!
Well it worked with the following:
I had missed a file "phpunit.xml.dist"
in the magento root directory, not just that. I had to comment out a few lines in UnitTests.php
in the magento root directory too - after which it looks as below -
<?php
//bootstrap.php already does this, not sure why we would need it here again
/*require 'app/Mage.php';
if (version_compare(PHP_VERSION, '5.3', '<')) {
exit('Magento Unit Tests can be runned only on PHP version over 5.3');
}
if (!Mage::isInstalled()) {
exit('Magento Unit Tests can be runned only on installed version');
}
$_SERVER['SCRIPT_NAME'] = dirname(__FILE__) . DS . 'index.php';
$_SERVER['SCRIPT_FILENAME'] = dirname(__FILE__) . DS . 'index.php';
Mage::app('admin');
Mage::getConfig()->init();*/
class UnitTests extends EcomDev_PHPUnit_Test_Suite
{
}
so now I see the log entry in mage system.log :)
Well, I am not yet sure if this is the right way...comments welcome