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 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛