PHPUnit Selenium2Testcase无法使用数据提供程序

时间:2016-05-04 08:20:59

标签: php phpunit

我有以下PHP单元测试用例。

出于检查目的,我注释了实际测试(即使->url()调用它也不起作用)

<?php

class BasicTest extends \PHPUnit_Extensions_Selenium2TestCase
{
    static $browsers = array(
        'chrome28win7' =>
            array(
                'browserName' => 'chrome',
                'desiredCapabilities' => array(
                    'version' => '28',
                    'os' => 'Windows',
                    'os_version' => '7',
                    'resolution' => '1280x1024',
                ),
            ),

    );

    /**
     * @dataProvider urlDataProvider
     * @param $path
     */
    public function testUrlScreenshot($path)
    {
        return; // for checking
        $this->url(env('BROWSER_BASE') . $path);
    }

    public static function urlDataProvider()
    {
        $list = <<<EOL
datenschutz.html
impressum.html
EOL;
        $plainArray = explode("\n", $list);

        $result = array();

        foreach($plainArray as $entry) {
            $result = array($entry);
        }
        return $result;
    }
}

我收到以下异常:

/usr/bin/php /home/example/local-workspace/example/vendor/phpunit/phpunit/phpunit --configuration /home/example/local-workspace/example/phpunit.xml --filter "/::testUrlScreenshot( .*)?$/" BasicTest /home/example/local-workspace/example/tests/frontend/BasicTest.php --teamcity
Testing started at 10:18 ...
PHP Fatal error:  Call to undefined method PHPUnit_Framework_WarningTestCase::setupSpecificBrowser() in /home/example/local-workspace/example/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumBrowserSuite.php on line 95
PHP Stack trace:
PHP   1. {main}() /home/example/local-workspace/example/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /home/example/local-workspace/example/vendor/phpunit/phpunit/phpunit:47
PHP   3. PHPUnit_TextUI_Command->run() /home/example/local-workspace/example/vendor/phpunit/phpunit/src/TextUI/Command.php:110
PHP   4. PHPUnit_Runner_BaseTestRunner->getTest() /home/example/local-workspace/example/vendor/phpunit/phpunit/src/TextUI/Command.php:133
PHP   5. ReflectionMethod->invoke() /home/example/local-workspace/example/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:87
PHP   6. PHPUnit_Extensions_Selenium2TestCase::suite() /home/example/local-workspace/example/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:87
PHP   7. PHPUnit_Extensions_SeleniumTestSuite::fromTestCaseClass() /home/example/local-workspace/example/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:371
PHP   8. PHPUnit_Extensions_SeleniumBrowserSuite->setupSpecificBrowser() /home/example/local-workspace/example/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumTestSuite.php:142
PHP   9. PHPUnit_Extensions_SeleniumBrowserSuite->browserOnAllTests() /home/example/local-workspace/example/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumBrowserSuite.php:86
PHP  10. PHPUnit_Extensions_SeleniumBrowserSuite->browserOnAllTests() /home/example/local-workspace/example/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumBrowserSuite.php:93

如果我不使用dataProvider注释,我可以运行测试。这是为什么?是`@dataProvider

1 个答案:

答案 0 :(得分:1)

该异常实际上掩盖了另一个错误。

调试显示了这一点:

enter image description here

所以PHP单元引发了一个错误,因为我的数据集无效(数据集需要是一个数组数组),这使得PHPUnit试图在异常类上调用setupSpecificBrowser()

修复数据集修复了错误。