phpunit在找不到名称为testsuite的文件时引发异常 [英] phpunit throwing exception when doesn't find file with name of testsuite

查看:149
本文介绍了phpunit在找不到名称为testsuite的文件时引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注问题.

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.

正如他所说,即使按照建议的这里:出于某种原因,有一些脚本正在寻找一个名为我命名为测试套件(MyApp.php或其他名称)的文件.

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.

但是,在给定的时间里,在阅读了以下有关以下问题的问题之后如何运行特定的phpunit xml testsuite ,我决定尝试在testsuite部分中显式插入文件.

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.

我的phpunit.xml现在是:

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.

我不知道为什么xml目录定义不能引导测试框架找到现有测试.

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

推荐答案

PHP致命错误:带有消息的未捕获异常'PHPUnit_Framework_Exception' "$ TEST_SUITE_NAME.php"和"$ TEST_SUITE_NAME.php"都不能 打开."在...

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

这是PHPUnits 非常神秘的说法

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? :(

简而言之:

扫描xml中的内容后,我没有找到任何测试!

您的情况为什么会发生这种情况?

Why does that happen in your case?

PHPUnit查找以 Test.php 结尾的文件,但您的文件以 TestS.php 结尾.多余的"S"表示PHPUnit在扫描目录时不会拾取文件.这也是为什么添加文件标签会有所帮助的原因.

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.

将其重命名为ModelTest.php,您可以删除文件标签:)

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

或者,如果您想保留文件名,请使用以下方式告知PHPUnit您的命名模式:

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

  <directory suffix="Tests.php">./</directory>

这篇关于phpunit在找不到名称为testsuite的文件时引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆