phpunit throwing exception when doesn't find f

2019-08-22 09:18发布

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条回答
对你真心纯属浪费
2楼-- · 2019-08-22 09:36

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>
查看更多
登录 后发表回答