1

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

  • possible duplicate of How run unittest using EcomDev_PHPUnit module? – Marius Jul 25 '13 at 6:54
  • @Marius : It is not...Well I did see that post but the solution did not work, hence not an duplicate...And that question was about initial set up and this is about how exactly to write tests using EcomDev_PHPUnit after set up... – g0c00l.g33k Jul 25 '13 at 6:59
3

I suggest you read the documentation of the module which can be found here

http://www.ecomdev.org/wp-content/uploads/2011/05/EcomDev_PHPUnit-0.2.0-Manual.pdf

Anyway, to answer your question, your configuration is not correct. In your config.xml you should tell EcomDev_PHPUnit about your module, like this:

<config>
    ...
    <phpunit>
        <suite>
            <modules>
                <Webservice_Clientservice />
            </modules>
        </suite>
    </phpunit>
    ...
</config>

Now you can run your tests by calling

phpunit --group Webservice_Clientservice
  • Oops I am sorry I forgot to mention that..I do have that configuration in my config.xml..I will update my question – g0c00l.g33k Jul 25 '13 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.