0

ここでは、この例を使用してDependencyInjectionのテストユニットを実行していますが、テストすると、次のエラーが発生します。

Myapp\MyBundle\Tests\DependencyInjection\MybundleExtensionTest::test Load
Argument 1 passed to Myapp\MyBundle\DependencyInjection\Configuration::buil
dPathNode() must be an instance of Myapp\MyBundle\DependencyInjection\NodeD
efinition, instance of Symfony\Component\Config\Definition\Builder\ArrayNodeDefi
nition given, called in E:\wamp\www\testingUnit\src\Myapp\MyBundle\Dependen
cyInjection\Configuration.php on line 33 and defined

DependencyInjection / MyappMybundleExtensions.php

<?php
namespace Myapp\Mybundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Config\Definition\Processor;


class MybundleExtension extends Extension
{
/**
 * Build the extension services
 *
 * @param array $configs
 * @param ContainerBuilder $container
 */

public function load(array $configs, ContainerBuilder $container)
{
    $processor = new Processor();
    $configuration = new Configuration();

    $config = $this->processConfiguration($configuration, $configs);

    $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
    $loader->load('file.yml');

    $config = $processor->processConfiguration($configuration, $configs);


    $container->setParameter('FashionWeb\ProductBundle\Controller\FamilyController::showFamilyAction', $config['action']);
}

}

Tests / DependencyInjection / MyappMyBundleExtensionsTest.php

 namespace Myapp\Mybundle\Tests\DependencyInjection;

  use Symfony\Component\DependencyInjection\ContainerBuilder;

  class Myapp\MybundleExtensionTest extends \PHPUnit_Framework_TestCase
 {
public function testLoad()
{

    $container = new ContainerBuilder();

    $extension = new MyappMybundleExtension();

    $extension->load(array(), $container);


    $this->assertEquals('FashionWeb\ProductBundle\Controller\FamilyController::showFamilyAction', $container->getParameter('myapp_mybundle.action'), sprintf('%s parameter is correct', 'myapp_mybundle.action'));

}

}
4

1 に答える 1

1

Configuration.php ファイルに含まれていuse Symfony\Component\Config\Definition\Builder\NodeDefinition;ますか?

use ステートメントが欠落しているためにエラーが発生したようです。

于 2012-09-19T16:35:15.033 に答える