测试 Symfony 定制制造商制造商捆绑包

问题描述

我正在尝试使用 Symfony make bundle 制作定制制作器。

maker 命令如下所示:

<?PHP

namespace App\Maker;

use Doctrine\Common\Annotations\Annotation;
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;


final class MakeCustomEntity extends AbstractMaker
{
  public static function getCommandName(): string
  {
    return 'make:custom-entity';
  }

  public static function getCommandDescription(): string
  {
    return 'Creates a new entity';
  }

  public function configureCommand(Command $command,InputConfiguration $inputConf)
  {
    $command
      ->addArgument('entity-class',InputArgument::OPTIONAL,sprintf('Choose a name for your entity class (e.g. <fg=yellow>%s</>)',Str::asClassName(Str::getRandomTerm())));
  }

  public function generate(InputInterface $input,ConsoleStyle $io,Generator $generator)
  {

  }

  public function configureDependencies(DependencyBuilder $dependencies)
  {
    $dependencies->addClassDependency(
      Annotation::class,'doctrine/annotations'
    );
  }
}

到目前为止一切顺利,定制工具在列出所有命令时都会出现。

但是我想为这个 maker 编写一个测试(灵感来自我在 bundles github 上找到的测试):

<?PHP

namespace Tests\Maker;

use App\Maker\MakeCustomEntity;
use Symfony\Bundle\MakerBundle\Test\MakerTestCase;
use Symfony\Bundle\MakerBundle\Test\MakerTestDetails;

class MakeCustomEntityTest extends MakerTestCase
{
  public function getTestDetails()
  {
    yield 'entity_full_custom_namespace' => [
      MakerTestDetails::createTest(
        $this->getMakerInstance(MakeCustomEntity::class),[
          // entity class name
          '\App\Domain\Entity\Test\Test',]
      )
        ->assert(function (string $output,string $directory) {
          $this->assertStringContainsstring('created: src/Domain/Entity/Test/Test.PHP',$output);
        }),];
  }
}

当我尝试运行此测试时,我收到以下警告,即使应该失败,测试也不会失败:

The data provider specified for Tests\Maker\MakeCustomEntityTest::testExecute is invalid.
You have requested a non-existent service "maker.maker.make_custom_entity". Did you mean one of these: "maker.maker.make_authenticator",...

这是测试定制制造商的正确方法吗?我应该怎么做才能避免这种情况?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...