I have a fixture to fill in the test user
namespace Tests\Fixture;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use App\Entity\User;
final class UserFixture extends Fixture
{
public function load(ObjectManager $manager): void
{
$userNonAdmin = new User();
$userNonAdmin->setUsername('uuuuusername');
$userNonAdmin->setPassword('$2y$10$qk4meHxphpa4qXef6QHC4uNQN/rFsa.iKWdS/8yB.bER1tdkSR6nS'); // hashed 123456
$userNonAdmin->setEmail('[email protected]');
$userNonAdmin->setRoles(['ROLE_USER']);
$manager->persist($userNonAdmin);
$manager->flush();
}
}
And a test that uses this fixture
namespace Tests\Acceptance\User;
use Tests\Fixture\UserFixture;
use Tests\Support\AcceptanceTester;
final class UserAuthCest
{
private const ENDPOINT = '/user/auth';
public function _before(AcceptanceTester $I): void
{
$I->loadFixtures([UserFixture::class]);
}
public function positiveTest(AcceptanceTester $I): void
{
$data = [
'username' => 'uuuuusername',
'password' => '123456'
];
$I->sendPost(self::ENDPOINT, $data);
$response = $I->grabResponse();
dd(json_decode($response, true));
}
}
But as a result, I get the error that the user has not been found, although if I get a UserRepository in the test and try to find the user using this username, then it finds the entity
public function positiveTest(AcceptanceTester $I): void
{
$data = [
'username' => 'uuuuusername',
'password' => '123456'
];
$I->sendPost(self::ENDPOINT, $data);
/** @var UserRepository $repository */
$repository = $I->grabRepository(UserRepository::class);
$user = $repository->findOneBy(['username' => 'uuuuusername']); // Entity exists
$response = $I->grabResponse();
dd(json_decode($response, true));
}
What am I doing wrong?
Symfony version: 6.3
Codeception version: 5.1.0
I found what the problem was, I had to fix the
tests/Acceptance.suite.ymlfileAnd create an extension to automatically clean up your test database