2

我正在使用LiipFunctionalTestBundleAliceBundle来测试我的 Symfony 3.4 应用程序和夹具。

一切工作正常,但这种特殊情况:从Liip WebTestCase扩展中的测试加载的夹具中访问应用程序参数。

让我们考虑一下这个设置:

配置.yml

parameters:
    img_url: 'http://images.url'

我的fixture.yml

AppBundle\Entity\Item:
    Item-0:
        name: 'First Item'
        image: '<{img_url}>/item0.png'

我的测试.php

use Liip\FunctionalTestBundle\Test\WebTestCase;

class MyTest extends WebTestCase
{
# ...

    public function testMy()
    {
        echo $this->getContainer()->getParameter('img_url');
        $this->loadFixtureFiles(['my-fixture.yml']);
        # ...
    }

这是测试的结果:

$ phpunit --filter /MyTest::testMy$/
http://images.url
Nelmio\Alice\Throwable\Exception\Generator\Resolver\UnresolvableValueDuringGenerationException:
  Could not resolve value during the generation process
[...]
Nelmio\Alice\Throwable\Exception\Generator\Resolver\UnresolvableValueException:
  Could not find the parameter "img_url"
[...]

但是,我的夹具可以从命令行成功加载:

$ console hautelook:fixtures:load -vv
13:37:42 INFO      [app] fixtures found ["files" => ["my-fixture.yml"]] []
13:37:42 INFO      [app] Purging database with purge mode "DELETE_MODE". [] []
13:37:42 INFO      [app] [...]
13:37:42 INFO      [app] fixtures loaded [] []

为什么我的夹具不能从测试中访问参数?
我该如何调试呢?

4

0 回答 0