PHPUnit Empty test?

I have a simple setup for a unit test but I am always getting an error that the test suite is empty. I have:

<?php

require_once '../scripts/init_core.php';

class TandyUnitTest extends PHPUnit_Framework_TestCase {
    /**
     * @group shipping
     */
    public function ShippingCharge() {
        $ship_options = Model::init('ship_options');
        var_dump($ship_options);
    }
}


WIth the attached PHPUnit settings. Why isn't the function 'ShippingCharge not getting executed?

Thank you.

Kevin



Attachment(s):
phpunitsettings.jpg
13 comments

Hi there,

PHPUnit needs to know what methods are tests and what are other/normal methods (helpers). For that -- http://phpunit.de/manual/current/en/writing-tests-for-phpunit.html

1) Individual tests (methods) should start with test as part of the name (i.e. testShippingCharge)

/**
 * @group shipping
 */
public function testShippingCharge()


2) or have @test in their PHPDoc comment

/**
 * @test
 * @group shipping
 */
public function ShippingCharge()



Another common convention is to have file names with tests to be ended with Test (i.e. MySpecialClassTest.php)

0

I changed the declaration like:

class TandyUnitTest extends PHPUnit_Framework_TestCase {
    /**
     * @test
     * @group shipping
     */
    public function testShippingCharge() {
        $ship_options = Model::init('ship_options');
        var_dump($ship_options);
    }
}


And I still don't see the testShippingCharge method executing and I see a message at the bottom of the IDE indicating that there is an "Empty test suite". Also there is a red message on the left hand pane of the IDE indicating the "Test framework quit unexpectedly".

Thank you.
0

Sorry -- not enough info. Therefore: screenshots please (of whole IDE where all details are shown).

Even better:

  1. create brand new project
  2. place ALL required files there (do not test your own code -- just test basic "1+2=3")
  3. try to make it working

  • If it works -- see how it differs to your original one and adjust accordingly.
  • If it does NOT -- zip whole project and attach here
0

I am working on getting a "simple project" working. In the mean time I have attached the applicable screenshots.



Attachment(s):
UnitTest2.jpg
UnitTest1.jpg
0

This simple project shows the same symptoms.



Attachment(s):
BasicUnitTest.zip
0

1) Works for me.

I'm using v8 EAP build as your v7.1.3 does NOT support latest PHPUnit versions (PhpStorm v7.1.3 supports 3.7 max; the PHAR files downloadable using that link (from within IDE) are v4.x).

What PHPUnit version do you use there (mine is latest 4.1.3 as seen from screenshot)?

screen01.png

2) Your screenshot -- you are trying to debug (instead of just running) + it is for your real project.

A) Could you use "run" instead of "debug"
B) Could you show the same but for test project please?

0

I am using 4.1.3. What version should I use?

Same result when I "run" and don't debug. Both in the real project and the test project.

Thank you.



Attachment(s):
UnitTest3.jpg
0

I tried PHPUnit 3.7.37 and it still didn't work.

0
I am using 4.1.3. What version should I use?

. . .


Quoting myself:

PhpStorm v7.1.3 supports 3.7 max;


Therefore: to use PHPUnit v4.x you need to use PhpStorm v8 EAP build -- PhpStorm EAP

0

In such case I do not know what may be wrong here.

  • Check your idea.log .. or PHP's own error log.
  • Try disabling debugger extension (and all other non-bundled extensions -- maybe they interfere somehow)
  • Does PHPUnit work from console/terminal?
0

Definitely check PHP's error log -- ths "Test framework quit unexpectedly" could mean that PHP cannot find/load requested class or similar.

... But then ... it should work on test project where no external dependencies present...

No other ideas, unfortunately.

0

Where is the idea log?

What would be the command line arguments for PHPUnit.phar?

Thank you.

0

Please sign in to leave a comment.