titov_andrei
@titov_andrei
All my life I learn - and die a fool!

Как исправить ошибку при генерации тестовых данных?

$ php bin/console doctrine:fixtures:load

Fatal error: Could not check compatibility between App\DataFixtures\AppFixtures::load(Doctrine\Common\Persistence\ObjectManager $manager) and Doctrine\Common\DataFixtures\FixtureInterface::load(Doctrine\Persistence\ObjectManager $manager), because class Doctrine\Common\Persistence\ObjectManager is not available in E:\OpenServer\domains\blog\src\DataFixtures\AppFixtures.php on line 23

Call Stack:
    0.0004     409608   1. {main}() E:\OpenServer\domains\blog\bin\console:0
    0.0010     415176   2. require_once('E:\OpenServer\domains\blog\vendor\autoload_runtime.php') E:\OpenServer\domains\blog\bin\console:11
    2.1458    4732656   3. Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() E:\OpenServer\domains\blog\vendor\autoload_runtime.php:35
    2.1459    4732656   4. Symfony\Component\Console\Application->run($input = class Symfony\Component\Console\Input\ArgvInput { protected $definition = class Symfony\Component\Console\Input\InputDefinition { private $arguments = [...]; private $requiredCount = 0; private $lastArrayArgument = NULL; private $lastOptionalArgument = NULL; private $options = [...]; private $negations = [...]; private $shortcuts = [...] }; protected $stream = NULL; protected $options = []; protected $arguments = []; protected $interactive = TRUE; private $tokens = [0 => 'doctrine:fixtures:load']; private $parsed = NULL }, $output = class Symfony\Component\Console\Output\ConsoleOutput { private ${Symfony\Component\Console\Output\Output}verbosity = 32; private ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter { private $decorated = TRUE; private $styles = [...]; private $styleStack = class Symfony\Component\Console\Formatter\OutputFormatterStyleStack { ... } }; private ${Symfony\Component\Console\Output\StreamOutput}stream = resource(2) of type (stream); private $stderr = class Symfony\Component\Console\Output\StreamOutput { private ${Symfony\Component\Console\Output\Output}verbosity = 32; private ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter { ... }; private $stream = resource(3) of type (stream) }; private $consoleSectionOutputs = [] }) E:\OpenServer\domains\blog\vendor\symfony\runtime\Runner\Symfony\ConsoleApplicationRunner.php:54
    2.1462    4742240   5. Symfony\Bundle\FrameworkBundle\Console\Application->doRun($input = class Symfony\Component\Console\Input\ArgvInput { protected $definition = class Symfony\Component\Console\Input\InputDefinition { private $arguments = [...]; private $requiredCount = 0; private $lastArrayArgument = NULL; private $lastOptionalArgument = NULL; private $options = [...]; private $negations = [...]; private $shortcuts = [...] }; protected $stream = NULL; protected $options = []; protected $arguments = []; protected $interactive = TRUE; private $tokens = [0 => 'doctrine:fixtures:load']; private $parsed = NULL }, $output = class Symfony\Component\Console\Output\ConsoleOutput { private ${Symfony\Component\Console\Output\Output}verbosity = 32; private ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter { private $decorated = TRUE; private $styles = [...]; private $styleStack = class Symfony\Component\Console\Formatter\OutputFormatterStyleStack { ... } }; private ${Symfony\Component\Console\Output\StreamOutput}stream = resource(2) of type (stream); private $stderr = class Symfony\Component\Console\Output\StreamOutput { private ${Symfony\Component\Console\Output\Output}verbosity = 32; private ${Symfony\Component\Console\Output\Output}formatter = class Symfony\Component\Console\Formatter\OutputFormatter { ... }; private $stream = resource(3) of type (stream) }; private $consoleSectionOutputs = [] }) E:\OpenServer\domains\blog\vendor\symfony\console\Application.php:171
    2.1462    4742240   6. Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() E:\OpenServer\domains\blog\vendor\symfony\framework-bundle\Console\Application.php:74
    2.1463    4742240   7. Symfony\Component\HttpKernel\Kernel->boot() E:\OpenServer\domains\blog\vendor\symfony\framework-bundle\Console\Application.php:168
    2.1463    4742240   8. Symfony\Component\HttpKernel\Kernel->preBoot() E:\OpenServer\domains\blog\vendor\symfony\http-kernel\Kernel.php:128
    3.1736    5690152   9. Symfony\Component\HttpKernel\Kernel->initializeContainer() E:\OpenServer\domains\blog\vendor\symfony\http-kernel\Kernel.php:787
    3.5192    6898736  10. Symfony\Component\Config\ConfigCache->isFresh() E:\OpenServer\domains\blog\vendor\symfony\http-kernel\Kernel.php:454
    3.5192    6898736  11. Symfony\Component\Config\ResourceCheckerConfigCache->isFresh() E:\OpenServer\domains\blog\vendor\symfony\config\ConfigCache.php:60
    4.0566    7474248  12. Symfony\Component\Config\Resource\SelfCheckingResourceChecker->isFresh($resource = class Symfony\Component\Config\Resource\ReflectionClassResource { private $files = ['E:\OpenServer\domains\blog\src\DataFixtures\AppFixtures.php' => NULL]; private $className = 'App\\DataFixtures\\AppFixtures'; private $classReflector = NULL; private $excludedVendors = []; private $hash = '5dbf387dacc372ce0d0aed8d4bd99ceb' }, $timestamp = 1671220083) E:\OpenServer\domains\blog\vendor\symfony\config\ResourceCheckerConfigCache.php:98
    4.0566    7474328  13. Symfony\Component\Config\Resource\ReflectionClassResource->isFresh($timestamp = 1671220083) E:\OpenServer\domains\blog\vendor\symfony\config\Resource\SelfCheckingResourceChecker.php:44
    4.0632    7474328  14. Symfony\Component\Config\Resource\ReflectionClassResource->computeHash() E:\OpenServer\domains\blog\vendor\symfony\config\Resource\ReflectionClassResource.php:54
    4.0632    7474424  15. ReflectionClass->__construct($objectOrClass = 'App\\DataFixtures\\AppFixtures') E:\OpenServer\domains\blog\vendor\symfony\config\Resource\ReflectionClassResource.php:107
    4.0632    7474520  16. Symfony\Component\ErrorHandler\DebugClassLoader->loadClass($class = 'App\\DataFixtures\\AppFixtures') E:\OpenServer\domains\blog\vendor\symfony\config\Resource\ReflectionClassResource.php:107
    4.0861    7481192  17. include('E:\OpenServer\domains\blog\src\DataFixtures\AppFixtures.php') E:\OpenServer\domains\blog\vendor\symfony\error-handler\DebugClassLoader.php:285

Symfony\Component\ErrorHandler\Error\FatalError^ {#78
  #message: "Compile Error: Could not check compatibility between App\DataFixtures\AppFixtures::load(Doctrine\Common\Persistence\ObjectManager $manager) and Doctrine\Common\DataFixtures\FixtureInterface::load(Doctrine\Persistence\ObjectManager $manager), because class Doctrine\Common\Persistence\ObjectManager is not available"
  #code: 0
  #file: "E:\OpenServer\domains\blog\src\DataFixtures\AppFixtures.php"
  #line: 23
  -error: array:4 [
    "type" => 64
    "message" => "Could not check compatibility between App\DataFixtures\AppFixtures::load(Doctrine\Common\Persistence\ObjectManager $manager) and Doctrine\Common\DataFixtures\FixtureInterface::load(Doctrine\Persistence\ObjectManager $manager), because class Doctrine\Common\Persistence\ObjectManager is not available"
    "file" => "E:\OpenServer\domains\blog\src\DataFixtures\AppFixtures.php"
    "line" => 23
  ]
  trace: {
    E:\OpenServer\domains\blog\src\DataFixtures\AppFixtures.php:23 {
      ›
      › public function load(ObjectManager $manager)
      › {
    }
    E:\OpenServer\domains\blog\vendor\symfony\error-handler\DebugClassLoader.php:285 { …}
    E:\OpenServer\domains\blog\vendor\symfony\config\Resource\ReflectionClassResource.php:107 { …}
    E:\OpenServer\domains\blog\vendor\symfony\config\Resource\ReflectionClassResource.php:107 { …}
    E:\OpenServer\domains\blog\vendor\symfony\config\Resource\ReflectionClassResource.php:54 { …}
    E:\OpenServer\domains\blog\vendor\symfony\config\Resource\SelfCheckingResourceChecker.php:44 { …}
    E:\OpenServer\domains\blog\vendor\symfony\config\ResourceCheckerConfigCache.php:98 { …}
    E:\OpenServer\domains\blog\vendor\symfony\config\ConfigCache.php:60 { …}
    E:\OpenServer\domains\blog\vendor\symfony\http-kernel\Kernel.php:454 { …}
    E:\OpenServer\domains\blog\vendor\symfony\http-kernel\Kernel.php:787 { …}
    E:\OpenServer\domains\blog\vendor\symfony\http-kernel\Kernel.php:128 { …}
    E:\OpenServer\domains\blog\vendor\symfony\framework-bundle\Console\Application.php:168 { …}
    E:\OpenServer\domains\blog\vendor\symfony\framework-bundle\Console\Application.php:74 { …}
    E:\OpenServer\domains\blog\vendor\symfony\console\Application.php:171 { …}
    E:\OpenServer\domains\blog\vendor\symfony\runtime\Runner\Symfony\ConsoleApplicationRunner.php:54 { …}
    E:\OpenServer\domains\blog\vendor\autoload_runtime.php:35 { …}
    E:\OpenServer\domains\blog\bin\console:11 { …}
    E:\OpenServer\domains\blog\bin\console:0 { …}
  }
}

<?php

namespace App\DataFixtures;

use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Cocur\Slugify\Slugify;
use Faker\Factory;
use App\Entity\Post;

class AppFixtures extends Fixture
{
    private $faker;

    private $slug;

    public function __construct(Slugify $slugify)
    {
        $this->faker = Factory::create();
        $this->slug = $slugify;
    }

    public function load(ObjectManager $manager)
    {
        $this->loadPosts($manager);
    }

    public function loadPosts(ObjectManager $manager)
    {

        for ($i = 1; $i < 20; $i++) {
            $post = new Post();
            $post->setTitle($this->faker->text(100));
            $post->setSlug($this->slug->slugify($post->getTitle()));
            $post->setBody($this->faker->text(1000));
            $post->setCreatedAt($this->faker->dateTime);

            $manager->persist($post);
        }
        $manager->flush();
    }

}
  • Вопрос задан
  • 146 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы