Codeception / Codeception/module-datafactory
Can't use existing entities with DataFactory
- Linguagem predominante
- PHP
- Estrelas
- 9
- Forks
- 7
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
#### What are you trying to achieve?
According to https://codeception.com/docs/modules/DataFactory.html you can create a new entity which is related to an existing entity. I can't get this functionality to work.
#### What do you get instead?
```bash
[Doctrine\ORM\ORMInvalidArgumentException] A new entity was found through the relationship 'HMRX\CoreBundle\Entity\AccountHolder#accountRole' that was not configured to cascade persist operations for entity: HMRX\CoreBundle\Entity\AccountRole@000000004c9582ff000000009565e70e. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'HMRX\CoreBundle\Entity\AccountRole#__toString()' to get a clue.
```
> Provide test source code if related
```php
public function shouldUseAFakeAccountHolder(AcceptanceTester $I) {
$I->have(AccountHolder::class);
}
```
```php
class Factories extends \Codeception\Module {
public function _beforeSuite($settings = []) {
/** @var EntityManager $em */
$em = $this->getModule('Doctrine2')->_getEntityManager();
$factory = $this->getModule('DataFactory');
$factory->_define(AccountHolder::class, [
'accountRole' => $em->getRepository(AccountRole::class)->findOneBy(['name' => 'ROLE_PHARMACIST']),
]);
}
}
```
### Details
```yml
# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'https://localhost/'
browser: chrome # 'chrome' or 'firefox'
capabilities:
chromeOptions:
w3c: false
- \Helper\Acceptance
- Doctrine2:
depends: Symfony
- DataFactory:
depends: Doctrine2
factories: tests/_support/Factories
- \Helper\Factories
```
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Direção de pesquisa
Comece com a configuração de DataFactory e Doctrine2 mostrada na issue, especialmente tests/_support/Factories e a definição de _beforeSuite para AccountHolder. Reproduza o teste de aceitação usando a entidade AccountRole existente e confirme então que a criação de AccountHolder funciona sem a ORMInvalidArgumentException relatada.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- php
- Domínio
- database, testing-qa
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 35/100