AliceDataFixtures: Entity of type [EntityClass] is missing an assigned ID for field 'id'
After a fresh upgrade to v1.1, I have this error on a functional test:
PHPUnit 7.2.7 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 5.74 seconds, Memory: 149.00MB
There was 1 failure:
1) Tests\AppBundle\Command\DomainNameExpireCheckCommandTest::test
Failed asserting that '\n
In ORMException.php line 87:\n
\n
Entity of type AppBundle\Entity\Ticket is missing an assigned ID for field 'id'. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instea \n
d you need to adjust the metadata mapping accordingly. \n
\n
\n
nexy:domain-name:expire-check [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>\n
\n
' contains "Expire ticket created for expiring.com.".
/code/tests/AppBundle/Command/DomainNameExpireCheckCommandTest.php:98
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
Git bisect revealed this commit: 7053c75de4d5a91c5bd7db43918a907706c7c990 coming from #89.
The Ticket entity id field:
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table
* @ORM\Entity(repositoryClass="AppBundle\Repository\TicketRepository")
* @ORM\EntityListeners({"AppBundle\Listener\Entity\TicketEntityListener"})
*/
class Ticket
{
/**
* @var int
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
The test file:
use AppBundle\Entity\DomainName;
use AppBundle\Entity\Purchase;
use Doctrine\ORM\EntityManagerInterface;
use PowerDNSBundle\Doctrine\ORM\PowerDNSEntityManager;
use PowerDNSBundle\Entity\PowerDNSDomain;
use Tests\AppBundle\Controller\WebTestCase;
final class DomainNameAutoRenewCommandTest extends WebTestCase
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var PowerDNSEntityManager
*/
private $powerDnsManager;
protected function setUp(): void
{
parent::setUp();
$this->entityManager = $this->getContainer()->get('doctrine.orm.default_entity_manager');
$this->powerDnsManager = $this->getContainer()->get(PowerDNSEntityManager::class);
$purchase = (new Purchase())
->setVersion(1)
->setPrice(15.4)
->setNextInvoiceDate(new \DateTime('tomorrow'))
->setProduct($this->getReference('product_domain_name'))
->setCustomer($this->getReference('user_default'))
->setAccounting($this->getReference('accounting_fr'))
;
$domainName = (new DomainName())
->setFqdn('renewal.com')
->setAutoRenew(true)
->setStatus(DomainName::STATE_CREATED)
->setExpirationDate(new \DateTime('+1 week'))
->setOwnerContact('TEST45-GANDI')
->setAdministratorContact('TEST45-GANDI')
->setBillingContact('TEST45-GANDI')
->setTechnicianContact('TEST45-GANDI')
->setPurchase($purchase)
;
$this->entityManager->persist($purchase);
$this->entityManager->persist($domainName);
$this->entityManager->flush();
$powerDnsDomain = (new PowerDNSDomain())
->setName($domainName->getFqdn())
->setOwner($this->getReference('user_default'))
->setDomainName($domainName)
->setDomainNameId($domainName->getId())
;
$this->powerDnsManager->persist($powerDnsDomain);
$this->powerDnsManager->flush();
}
public function test(): void
{
$output = $this->runCommand('nexy:domain-name:auto-renew');
$this->assertContains('Renewing renewal.com.', $output);
$output = $this->runCommand('nexy:domain-name:auto-renew');
$this->assertNotContains('Renewing renewal.com.', $output);
}
/**
* {@inheritdoc}
*/
protected function getFixturesFiles(): array
{
return \array_merge(parent::getFixturesFiles(), [
__DIR__.'/../../fixtures/orm/product.yml',
__DIR__.'/../../fixtures/orm/accounting.yml',
]);
}
}
Tell me if you need anything more to investigate.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 20 (11 by maintainers)
I’ll try to take a look at it next week