You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an UserFixture class that injects UserPasswordEncoderInterface but when I execute the doctrine:mongodb:fixtures:load the interface is not injected on the class causing a error.
Current behavior
The interface UserPasswordEncoderInterface is not injected on the fixture throwing a FatalThrowableError
How to reproduce
Create an User document that implements UserInterface, just with the interface methods.
Create a fixture that inserts an user password interface:
<?php
namespace App\DataFixtures\MongoDB;
use App\Document\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class UserFixtures extends Fixture
{
private $passwordEncoder;
public function __construct(UserPasswordEncoderInterface $passwordEncoder)
{
$this->passwordEncoder = $passwordEncoder;
}
public function load(ObjectManager $manager)
{
$user = new User();
$user->setEmail('admin@admin.com');
$user->setPassword($this->passwordEncoder->encodePassword(
$user,
'admin123'
));
$manager->persist($user);
$manager->flush();
}
}
Result:
/var/www/html $ php bin/console doctrine:mongodb:fixtures:load --append -vvv
21:07:05 INFO [php] User Deprecated: The "Symfony\Component\HttpKernel\Kernel::getRootDir()" method is deprecated since Symfony 4.2, use getProjectDir() instead.
[
"exception" => ErrorException {
#message: "User Deprecated: The "Symfony\Component\HttpKernel\Kernel::getRootDir()" method is deprecated since Symfony 4.2, use getProjectDir() instead."
#code: 0
#file: "./vendor/symfony/http-kernel/Kernel.php"
#line: 326
#severity: E_USER_DEPRECATED
trace: {
./vendor/symfony/http-kernel/Kernel.php:326 { …}
./vendor/doctrine/mongodb-odm-bundle/Command/LoadDataFixturesDoctrineODMCommand.php:95 { …}
./vendor/symfony/console/Command/Command.php:255 { …}
./vendor/symfony/console/Application.php:939 { …}
./vendor/symfony/framework-bundle/Console/Application.php:87 { …}
./vendor/symfony/console/Application.php:273 { …}
./vendor/symfony/framework-bundle/Console/Application.php:73 { …}
./vendor/symfony/console/Application.php:149 { …}
./bin/console:42 {
› $application = new Application($kernel);
› $application->run($input);
›
}
}
}
]
In UserFixtures.php line 14:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Too few arguments to function App\DataFixtures\MongoDB\UserFixtures::__construct(), 0 passed in /var/www/html/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Loader.php on line 19
3 and exactly 1 expected
Exception trace:
() at /var/www/html/src/DataFixtures/MongoDB/UserFixtures.php:14
App\DataFixtures\MongoDB\UserFixtures->__construct() at /var/www/html/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Loader.php:193
Doctrine\Common\DataFixtures\Loader->createFixture() at /var/www/html/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Loader.php:373
Doctrine\Common\DataFixtures\Loader->loadFromIterator() at /var/www/html/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Loader.php:65
Doctrine\Common\DataFixtures\Loader->loadFromDirectory() at /var/www/html/vendor/doctrine/mongodb-odm-bundle/Command/LoadDataFixturesDoctrineODMCommand.php:105
Doctrine\Bundle\MongoDBBundle\Command\LoadDataFixturesDoctrineODMCommand->execute() at /var/www/html/vendor/symfony/console/Command/Command.php:255
Symfony\Component\Console\Command\Command->run() at /var/www/html/vendor/symfony/console/Application.php:939
Symfony\Component\Console\Application->doRunCommand() at /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:87
Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /var/www/html/vendor/symfony/console/Application.php:273
Symfony\Component\Console\Application->doRun() at /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:73
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/html/vendor/symfony/console/Application.php:149
Symfony\Component\Console\Application->run() at /var/www/html/bin/console:42
doctrine:mongodb:fixtures:load [--fixtures [FIXTURES]] [-b|--bundles [BUNDLES]] [--append] [--dm DM] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>
Expected behavior
The interface be injected on the fixture to create the User normally.
The text was updated successfully, but these errors were encountered:
I've transferred the issue over, no need to close and re-open.
To answer your question, in 3.5 fixtures have to be ContainerAware to access services. Fixture services were added in #529, to be released in 3.6.0. With 4.0.0, fixture services will be the only type of fixture remaining, just like in DoctrineFixturesBundle.
Bug Report
Summary
I have an
UserFixture
class that injects UserPasswordEncoderInterface but when I execute thedoctrine:mongodb:fixtures:load
the interface is not injected on the class causing a error.Current behavior
The interface
UserPasswordEncoderInterface
is not injected on the fixture throwing a FatalThrowableErrorHow to reproduce
Result:
Expected behavior
The interface be injected on the fixture to create the User normally.
The text was updated successfully, but these errors were encountered: