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 python动态规划:N根火柴摆出的最大数字
  • ¥20 (标签-excel)
  • ¥200 求idea10和MyEclipse7.1
  • ¥20 vb6.0截取当前窗体保存为jpg文件
  • ¥20 苹果手机不使用大疆sdk怎么获取遥控器控制信息或如何接入大疆sdk并且成功上架sdk
  • ¥20 woocommerce 注册按键重定向
  • ¥100 求书法图像文字切割代码
  • ¥15 同一个波形探测距离不同的目标,为什么fft之后得到的频谱图会发生移动,不应该时移不改变幅度谱吗(标签-matlab)(相关搜索:matlab仿真)
  • ¥15 Proteus仿真程序只能执行一次
  • ¥15 语音识别websocket报错