0

I was following Jon´s screencast about Unit Testing with PhpUnit and ZF when I got the exact same error that ratzip described in this question.

As he commented, I also had the same problem even after creating tests as suggested here: for some reason, there was some script looking for a file named as I named my test suite (MyApp.php or whatever...).

I looked around but wasn´t able to find where I should create this file and what it should contains.

But, in a given moment, after had read this question about how to run a specific phpunit xml testsuite, I decided to try to explicity insert a file in the testsuite section.

My phpunit.xml now is:

<phpunit bootstrap="./application/bootstrap.php" colors="true">
<testsuites>
    <testsuite name="MyApp">
        <file>./application/(path_to_model_inside_module)/ModelTests.php</file>
        <directory>./</directory>       
    </testsuite>
</testsuites>

<filter>

    <whitelist>
        <directory suffix=".php">../application/</directory>
        <exclude>
            <directory suffix=".phtml">../application/</directory>
        </exclude>
    </whitelist>

</filter>

And even if it seems a little despaired, that error is not happening anymore and the test is working now.

BUt I'm feeling unconfortable about it as I can't understand what was the problem before and why this explicitation of a file "fixed" it.

I can't figure why the xml directory definition wasn't able to guide the testing framework to find the existing test.

1 Answer 1

1

PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Neither "$TEST_SUITE_NAME.php" nor "$TEST_SUITE_NAME.php" could be opened.' in ...

This is PHPUnits very cryptic way of saying

He buddy! Small issue over here: I was trying to find some tests to execute but I didn't find any so I tried to load a file named like the test suite and not even that exists. I can't execute any tests.. can you help me out here? :(

In short it is saying:

After scanning the stuff in your xml I didn't find any tests!

Why does that happen in your case?

PHPUnit looks for files ending in Test.php but your file ends in TestS.php. The extra "S" means PHPUnit will NOT pick up the file when scanning the directory. This is also why adding the file tag helps.

Rename it do ModelTest.php and you can get rid of the file tag :)

Or if you want to keep your filenames tell PHPUnit about your naming schema using:

  <directory suffix="Tests.php">./</directory>
Sign up to request clarification or add additional context in comments.

3 Comments

txs @edorian, for pointing the extra 'S'... this probably was part of my problem... I have also found some other tips at the answer for quite the same question at stackoverflow.com/questions/7045834/… had create a "/tests/TheSuiteNameTest.php", named the suite as TheSuiteName, and the error was gone...
@RodrigoAoCubo you should not need a "TestSuiteName.php" or anything like that anymore. That was used back in the day to orchestrate test suites but has be replaced by the xml configuration.
you're right, I had remove the "TestSuitName.php" file and it still works now that I don't have that trailing 's'. Txs again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.