dongying7847 2014-09-10 14:56
浏览 65
已采纳

Phalcon:如何运行示例单元测试?

I tried to run an example from here: http://docs.phalconphp.com/en/latest/reference/unit-testing.html

I created composer file:

{
    "require": {
        "phalcon/incubator": "dev-master"
    }
}

After composer installation I've tried to run phpunit and got an error:

PHP Fatal error:  Class 'Codeception\TestCase\Test' not found in /www/tests/vendor/phalcon/incubator/codeception/unit/Phalcon/Validation/Validator/Db/UniquenessTest.php on line 9

I added new dependency:

composer require "codeception/codeception:*"

It added many dependencies.

After that I got another error:

PHP Warning:  require_once(tests/data/app/data.php): failed to open stream: No such file or directory in www/tests/vendor/codeception/codeception/tests/unit/Codeception/Module/FacebookTest.php on line 3

I changed

require_once(tests/data/app/data.php)

to

require_once(__DIR__ . '/../../../../tests/data/app/data.php')

in follow follow files:

www/tests/vendor/codeception/codeception/tests/unit/Codeception/Module/WebDriverTest.php
www/tests/vendor/codeception/codeception/tests/unit/Codeception/Module/WFacebookTest.php
www/tests/vendor/codeception/codeception/tests/unit/Codeception/Module/PhpBrowserTest.php

Ok. Phpunit running...I've got next error:

PHP Fatal error:  Class 'WebDriverTestCase' not found in `www/tests/vendor/facebook/webdriver/tests/functional/BaseTest.php on line 16`

Ok.. I tried to include:

require_once __DIR__ . '/WebDriverTestCase.php';

to

www/tests/vendor/facebook/webdriver/tests/functional/BaseTest.php

Now I have following error which I cannot fix:

PHP Fatal error:  Uncaught exception 'PHPUnit_Framework_Exception' with message 'Class "PHPUnit_Extensions_RepeatedTest" does not extend PHPUnit_Framework_TestCase.' in www/tests/vendor/phpunit/phpunit/src/Framework/TestSuite.php:195
Stack trace:
#0 /www/tests/vendor/phpunit/phpunit/src/Framework/TestSuite.php(324): PHPUnit_Framework_TestSuite->__construct(Object(ReflectionClass))
#1 /www/tests/vendor/phpunit/phpunit/src/Framework/TestSuite.php(409): PHPUnit_Framework_TestSuite->addTestSuite(Object(ReflectionClass))
#2 /www/tests/vendor/phpunit/phpunit/src/Framework/TestSuite.php(435): PHPUnit_Framework_TestSuite->addTestFile('/Users/anthony/...')
#3 phar:///usr/local/zend/bin/phpunit/phpunit/Util/Configuration.php(911): PHPUnit_Framework_TestSuite->addTestFiles(Array)
#4 phar:///usr/local/zend/bin/phpunit/phpunit/Util/Configuration.php(825): PHPUnit_Util_Configura in /www/tests/UnitTestCase.php on line 61

I thought composer should make your life easer by it seems doesn't. Is it ok I have to change some code in vendor libraries?!... where I'm doing wrong? I just need to use phpunit in phalcon...

  • 写回答

1条回答 默认 最新

  • duankuaizhe8257 2014-09-10 15:33
    关注

    By the time I finished reading the question I was expecting to see "Ok… I took a gun and shoot twice in a stomach…" I am a little uncertain if you are trying to run tests from incubator or Phalcon, or your own. I am assuming your own.

    First of all incubator is an interesting repository, but it's probably the last thing you need to use in your project. It's meant to make your life easier, but most stuff are experimental there and act more as an inspiration rather than a solution (imho). It's supported by less involved people and the reason why it doesn't work might also be the difference in PHPUnit versions (incubator uses 3.7, the rest of the contemporary world uses 4.2, which have some incompatibilities).

    Phalcon works perfectly fine with PHPUnit out of the box. To run basic tests all you need is to install and configure PHPUnit as per documentation. The simplest phpunit.xml can look like this:

    <phpunit bootstrap="../../public/bootstrap.php">
        <testsuite name="Default">
            <directory>../../src/php</directory>
        </testsuite>
    </phpunit>
    

    I suggest get rid of incubator (at least for your tests until you successfully configure PHPUnit) and follow the standard documentation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵