相关疑难解决方法(0)

如何在phpunit中引用外部数据提供程序?

我正在尝试使用PHPUnit中的通用数据提供程序来运行一些测试。

参见以下测试:

    namespace AppBundle\Tests\Controller;

    use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
    use AppBundle\Tests\DataProvider\XmlDataProvider;

    class DefaultControllerTest extends WebTestCase
    {
        /**
         * @dataProvider XmlDataProvider::xmlProvider
         * @covers ReceiveController::receiveAction()
         * @param string
         */
        public function testReceive($xml)
        {
            $client = static::createClient([], ['HTTP_HOST' => 'mt.host']);
            $client->request(
                'POST',
                '/receive',
                [],
                [],
                [],
                $xml
            );

            $response = $client->getResponse();
            $this->assertEquals(200, $response->getStatusCode());
        }
    }
Run Code Online (Sandbox Code Playgroud)

现在,我需要一个外部数据提供程序类:

namespace AppBundle\Tests\DataProvider;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class XmlDataProvider extends WebTestCase
{
    /**
     * @dataProvider
     */
    public static function xmlProvider()
    {
        return array([
            'xml1' => '<?xml version="1.0" encoding="UTF-8"?><myTestableXml></myTestableXml>'
        ]);
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我运行phpunit时,我得到:

1)警告为AppBundle …

php tdd phpunit symfony composer-php

3
推荐指数
1
解决办法
1038
查看次数

标签 统计

composer-php ×1

php ×1

phpunit ×1

symfony ×1

tdd ×1