phpunit throwing exception when doesn't find file with name of testsuite

扶醉桌前 提交于 2019-12-12 03:13:51

问题


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:


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>


来源:https://stackoverflow.com/questions/9688420/phpunit-throwing-exception-when-doesnt-find-file-with-name-of-testsuite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!