PHPunit 没有在 Travis CI 上执行测试

标签 php phpunit composer-php travis-ci

我第一次学习 PHPUnit 教程,我的测试在本地运行良好。但是,在 Travis CI 上运行我的测试时,没有执行任何测试,我的构建以 0 退出。

我的目录结构和完整代码可以在 repo 上看到.

Travis CI 构建日志 (Full build log)

1.51s$ curl -s http://getcomposer.org/installer | php
#!/usr/bin/env php
All settings correct for using Composer
Downloading...
Composer successfully installed to: /home/travis/build/idavidmcdonald/phpunit-tutorial/composer.phar
Use it: php composer.phar
before_script.2
0.33s$ php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
0.08s$ vendor/bin/phpunit --debug
PHPUnit 3.7.14 by Sebastian Bergmann.
Configuration read from /home/travis/build/idavidmcdonald/phpunit-tutorial/phpunit.xml
Time: 13 ms, Memory: 2.00Mb
No tests executed!
The command "vendor/bin/phpunit --debug" exited with 0.
Done. Your build exited with 0.

phpunit.xml:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="vendor/autoload.php">
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory>phpunittutorial/tests/</directory>
        </testsuite>
    </testsuites>
</phpunit>

.travis.yml:

language: php

php:
  - 5.4
  - 5.5

before_script:
  - curl -s http://getcomposer.org/installer | php
  - php composer.phar install

script: vendor/bin/phpunit --debug

我的测试在本地成功运行,但是可能我的 phpunit.xml 文件某处有问题?

最佳答案

包含您的测试的目录不正确。

正确的路径是phpUnitTutorial/tests。请注意,Windows 不关心区分大小写,但世界上其他所有人都关心。最好的办法是始终对路径使用小写字母,或者仔细检查你在任何地方都使用了正确的大小写(PSR-0 和 PSR-4 需要与类名大小写相同的路径名,通常包括大写字母).

顺便说一下:您应该升级到更新版本的 PHPUnit。那个旧的 3.7 系列现在已经很多年没有更新了,而且向 4.x 的过渡也不是太陡峭 - 你应该这样做。

关于PHPunit 没有在 Travis CI 上执行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30280278/

相关文章:

运行我的第一个测试时 PHPunit Framework TypeError

composer-php - 旧版自动更新,需要注意

composer-php - Composer不会安装“require-dev”软件包

php - MYSQL显示连接2个表后未连接的值

javascript - Ajax 请求和竞争条件(客户端和服务器端)

php - ErrorDocument 404/404.php 在 PHP 的 .htaccess 文件中不起作用

php - 测试异常 PHPUnit

php - MySql 随机化最后 10 行

php - TypeError: class::functionName() 的返回值必须是/Interface 的实例,返回 null

php - Laravel artisan 迁移失败