I've been implementing foundry with a functional test. I've gotten most of it to work except the ResetDatabase is not happening.
My functional test is set up as such:
class AssetControllerCest extends WebTestCase
{
use ResetDatabase;
use Factories;
/**
* Check to see that an internal user with proper permission has access to index lists.
*/
public function indexWithInternalUserPermission(FunctionalTester $I)
{
// create 10 Assets
AssetFactory::new()->createMany(20);
$repository = AssetFactory::repository();
$repository->assertCount(20);
And my GlobalStory is doing some initial population when it's loaded by the bootstrap.php such as:
final class GlobalStory extends Story
{
private ManagerRegistry $managerRegistry;
public function __construct(ManagerRegistry $managerRegistry)
{
$this->managerRegistry = $managerRegistry;
}
public function build(): void
{
// add all of the type entities we need for testing
// set the generator to type none
$entityManager = $this->managerRegistry->getManagerForClass(App::class);
$metadata = $entityManager->getClassMetaData(App::class);
$metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE);
// add apps
$appNames = [
1 => 'Backend',
2 => 'Frontend',
3 => 'API',
4 => 'QuoteTracker',
];
The first time I run the test, it runs and passes:
functional Controller/AssetControllerCest:indexWithInternalUserPermission
But on the second or additional run, I get an error which indicates it's re-running the GlobalStory setup, but failing because there are already entities in the database.
There was 1 error:
---------
1) AssetControllerCest: Index with internal user permission
Test tests/functional/Controller/AssetControllerCest.php:indexWithInternalUserPermission
[Doctrine\DBAL\Exception\UniqueConstraintViolationException] An exception occurred while executing 'INSERT INTO app (name, created_at, updated_at, id) VALUES (?, ?, ?, ?)' with params ["Backend", "2020-10-09 14:47:05", "2020-10-09 14:47:05", 1]:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'app.PRIMARY'
Is there anything else that needs to be done to enable the resetDatabase?
In my functional suite setup, I didn't have Doctrine2 cleanup enabled, so I tried that, but that didn't make any difference.
I wasn't clear on whether that process would be compatible with Foundry.