Skip to content

[DataFactory] Entity from database missing on persist operation #8

@amigian74

Description

@amigian74

I'm trying to create a new user entity using DataFactory. The status of the user is another entity and retrieved from the test database using the entity manager.

public function _beforeSuite($settings = [])
    {
        parent::_beforeSuite($settings);
        $factory = $this->getModule("DataFactory");
        $em = $this->getModule("Doctrine2")->_getEntityManager();

        $factory->_define(User::class, [
            "username" => Faker::name(),
            "roles" => ["ROLE_USER"],
            "status" => $em->getRepository(Status::class)->findOneBy([ 'id' => Status::ACTIVE ]),
            "password" => ""
        ]);
    }

When trying to create a new user it fails.

There was 1 error:

---------
1) UserCest: Try to delete user
 Test  tests/api/UserCest.php:tryToDeleteUser



  [Doctrine\ORM\ORMInvalidArgumentException] A new entity was found through the relationship 'App\Entity\User#status' that was not configured to cascade persist operations for entity: App\Entity\Status@00000000163eb841000000007b52f6a7. 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 'App\Entity\Status#__toString()' to get a clue.




Scenario Steps:

 2. $I->have("App\Entity\User") at tests/api/UserCest.php:38
 1. $I->amHttpAuthenticated("test","pits1Test!") at tests/api/UserCest.php:8

Codeception/Codeception#1  /var/www/envi/vendor/doctrine/orm/lib/Doctrine/ORM/ORMInvalidArgumentException.php:114
Codeception/Codeception#2  /var/www/envi/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:3492
Codeception/Codeception#3  /var/www/envi/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:383
Codeception/Codeception#4  /var/www/envi/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:376
Codeception/Codeception#5  /var/www/envi/var/cache/test/Container046J49q/App_KernelTestDebugContainer.php:13207
Codeception/Codeception#6  /var/www/envi/vendor/league/factory-muffin/src/Stores/RepositoryStore.php:98
Codeception/Codeception#7  /var/www/envi/vendor/league/factory-muffin/src/Stores/RepositoryStore.php:78
Codeception/Codeception#8  /var/www/envi/vendor/league/factory-muffin/src/Stores/AbstractStore.php:61
Codeception/Codeception#9  /var/www/envi/vendor/league/factory-muffin/src/FactoryMuffin.php:108
Codeception/Codeception#10 Codeception\Module\DataFactory->have
public function tryToDeleteUser(ApiTester $I)
    {
        $userId = $I->have('App\Entity\User');
        ...
    }

Details

  • Codeception version: 4.1.6
  • PHP Version: 7.2.34
  • Operating System: Ubuntu/Windows
  • Installation type: Composer
  • List of installed packages
behat/gherkin                        v4.8.0    Gherkin DSL parser for PHP
codeception/codeception              4.1.6     BDD-style testing framework
codeception/lib-asserts              1.13.2    Assertion methods used by Codeception core and Asserts module
codeception/lib-innerbrowser         1.4.0     Parent library for all Codeception framework modules and PhpBrowser
codeception/module-asserts           1.3.1     Codeception module containing various assertions
codeception/module-datafactory       1.0.1     DataFactory module for Codeception
codeception/module-db                1.1.0     DB module for Codeception
codeception/module-doctrine2         1.1.1     Doctrine2 module for Codeception
codeception/module-phpbrowser        1.0.2     Codeception module for testing web application over HTTP
codeception/module-rest              1.2.7     REST module for Codeception
codeception/module-symfony           1.5.0     Codeception module for Symfony framework
codeception/module-webdriver         1.2.0     WebDriver module for Codeception
codeception/phpunit-wrapper          8.1.4     PHPUnit classes used by Codeception
codeception/stub                     3.7.0     Flexible Stub wrapper for PHPUnit's Mock Builder
composer/package-versions-deprecated 1.11.99.1 Composer plugin that provides efficient querying for installed package versions (no runtime IO)
doctrine/annotations                 1.11.1    Docblock Annotations Parser
doctrine/cache                       1.10.2    PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.
doctrine/collections                 1.6.7     PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.
doctrine/common                      3.1.1     PHP Doctrine Common project is a library that provides additional functionality that other Doctrine projects depend on such as better reflection support, proxies and much more.  
doctrine/data-fixtures               1.5.0     Data Fixtures for all Doctrine Object Managers
doctrine/dbal                        2.10.4    Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
doctrine/doctrine-bundle             2.2.3     Symfony DoctrineBundle
doctrine/doctrine-fixtures-bundle    3.4.0     Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle  3.0.2     Symfony DoctrineMigrationsBundle
doctrine/event-manager               1.1.1     The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.
doctrine/inflector                   2.0.3     PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.
doctrine/instantiator                1.4.0     A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                       1.2.1     PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                  3.1.0     PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying chang...  
doctrine/orm                         2.8.2     Object-Relational-Mapper for PHP
doctrine/persistence                 2.1.0     The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.
doctrine/sql-formatter               1.1.1     a PHP SQL highlighting library
egulias/email-validator              2.1.25    A library for validating emails against several RFCs
facile-it/doctrine-mysql-come-back   v1.8      Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal
fakerphp/faker                       v1.13.0   Faker is a PHP library that generates fake data for you.
friendsofphp/proxy-manager-lts       v1.0.3    Adding support for a wider range of PHP versions to ocramius/proxy-manager
guzzlehttp/guzzle                    7.2.0     Guzzle is a PHP HTTP client library
guzzlehttp/promises                  1.4.0     Guzzle promises library
guzzlehttp/psr7                      1.7.0     PSR-7 message implementation that also provides common utility methods
justinrainbow/json-schema            5.2.10    A library to validate a json schema.
laminas/laminas-code                 3.4.1     Extensions to the PHP Reflection API, static code scanning, and code generation
laminas/laminas-eventmanager         3.2.1     Trigger and listen to events within a PHP application
laminas/laminas-zendframework-bridge 1.1.1     Alias legacy ZF class names to Laminas Project equivalents.
league/factory-muffin                v3.3.0    The goal of this package is to enable the rapid creation of objects for the purpose of testing.
league/factory-muffin-faker          v2.3.0    The goal of this package is to wrap faker to make it super easy to use with factory muffin.
monolog/monolog                      2.2.0     Sends your logs to files, sockets, inboxes, databases and various web services
myclabs/deep-copy                    1.10.2    Create deep copies (clones) of your objects
nikic/php-parser                     v4.10.4   A PHP parser written in PHP
phar-io/manifest                     2.0.1     Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                      3.0.4     Library for handling version information and constraints
php-webdriver/webdriver              1.9.0     A PHP client for Selenium WebDriver. Previously facebook/webdriver.
phpdocumentor/reflection-common      2.2.0     Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock    5.2.2     With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver          1.4.0     A PSR-5 based resolver of Class names, Types and Structural Element Names
phpspec/prophecy                     1.12.2    Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage            7.0.14    Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator            2.0.3     FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template            1.2.1     Simple template engine.
phpunit/php-timer                    2.1.3     Utility class for timing
phpunit/php-token-stream             3.1.2     Wrapper around PHP's tokenizer extension.
phpunit/phpunit                      8.5.14    The PHP Unit Testing framework.
psr/cache                            1.0.1     Common interface for caching libraries
psr/container                        1.0.0     Common Container Interface (PHP FIG PSR-11)
psr/event-dispatcher                 1.0.0     Standard interfaces for event handling.
psr/http-client                      1.0.1     Common interface for HTTP clients
psr/http-message                     1.0.1     Common interface for HTTP messages
psr/log                              1.1.3     Common interface for logging libraries
ralouphie/getallheaders              3.0.3     A polyfill for getallheaders.
sebastian/code-unit-reverse-lookup   1.0.2     Looks up which function or method a line of code belongs to
sebastian/comparator                 3.0.3     Provides the functionality to compare PHP values for equality
sebastian/diff                       3.0.3     Diff implementation
sebastian/environment                4.2.4     Provides functionality to handle HHVM/PHP environments
sebastian/exporter                   3.1.3     Provides the functionality to export PHP variables for visualization
sebastian/global-state               3.0.1     Snapshotting of global state
sebastian/object-enumerator          3.0.4     Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector           1.1.2     Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context          3.0.1     Provides functionality to recursively process PHP variables
sebastian/resource-operations        2.0.2     Provides a list of PHP built-in functions that operate on resources
sebastian/type                       1.1.4     Collection of value objects that represent the types of the PHP type system
sebastian/version                    2.0.1     Library that helps with managing the version number of Git-hosted PHP projects
sensio/framework-extra-bundle        v5.6.1    This bundle provides a way to configure your controllers with annotations
softcreatr/jsonpath                  0.7.2     JSONPath implementation for parsing, searching and flattening arrays
swiftmailer/swiftmailer              v6.2.5    Swiftmailer, free feature-rich PHP mailer
symfony/amqp-messenger               v5.2.3    Symfony AMQP extension Messenger Bridge
symfony/asset                        v5.2.3    Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files
symfony/browser-kit                  v5.2.3    Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically
symfony/cache                        v5.2.3    Provides an extended PSR-6, PSR-16 (and tags) implementation
symfony/cache-contracts              v2.2.0    Generic abstractions related to caching
symfony/config                       v5.2.3    Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/console                      v5.2.3    Eases the creation of beautiful and testable command line interfaces
symfony/css-selector                 v5.2.3    Converts CSS selectors to XPath expressions
symfony/dependency-injection         v5.2.3    Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts        v2.2.0    A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge              v5.2.3    Provides integration for Doctrine with various Symfony components
symfony/doctrine-messenger           v5.2.3    Symfony Doctrine Messenger Bridge
symfony/dom-crawler                  v5.2.3    Eases DOM navigation for HTML and XML documents
symfony/dotenv                       v5.2.3    Registers environment variables from a .env file
symfony/error-handler                v5.2.3    Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher             v5.2.3    Provides tools that allow your application components to communicate with each other by dispatching events and listening to them
symfony/event-dispatcher-contracts   v2.2.0    Generic abstractions related to dispatching event
symfony/filesystem                   v5.2.3    Provides basic utilities for the filesystem
symfony/finder                       v5.2.3    Finds files and directories via an intuitive fluent interface
symfony/flex                         v1.12.2   Composer plugin for Symfony
symfony/form                         v5.2.3    Allows to easily create, process and reuse HTML forms
symfony/framework-bundle             v5.2.3    Provides a tight integration between Symfony components and the Symfony full-stack framework
symfony/http-client-contracts        v2.3.1    Generic abstractions related to HTTP clients
symfony/http-foundation              v5.2.3    Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                  v5.2.3    Provides a structured process for converting a Request into a Response
symfony/intl                         v5.2.3    Provides a PHP replacement layer for the C intl extension that includes additional data from the ICU library
symfony/mailer                       v5.2.3    Helps sending emails
symfony/maker-bundle                 v1.29.1   Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.
symfony/messenger                    v5.2.3    Helps applications send and receive messages to/from other applications or via message queues
symfony/mime                         v5.2.3    Allows manipulating MIME messages
symfony/monolog-bridge               v5.2.3    Provides integration for Monolog with various Symfony components
symfony/monolog-bundle               v3.6.0    Symfony MonologBundle
symfony/options-resolver             v5.2.3    Provides an improved replacement for the array_replace PHP function
symfony/orm-pack                     v2.1.0    A pack for the Doctrine ORM
symfony/phpunit-bridge               v5.2.3    Provides utilities for PHPUnit, especially user deprecation notices management
symfony/polyfill-intl-grapheme       v1.22.1   Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu            v1.22.1   Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn            v1.22.1   Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer     v1.22.1   Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring            v1.22.1   Symfony polyfill for the Mbstring extension
symfony/polyfill-php72               v1.22.1   Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php73               v1.22.1   Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/polyfill-php80               v1.22.1   Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/process                      v5.2.3    Executes commands in sub-processes
symfony/profiler-pack                v1.0.5    A pack for the Symfony web profiler
symfony/property-access              v5.2.3    Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info                v5.2.3    Extracts information about PHP class' properties using metadata of popular sources
symfony/proxy-manager-bridge         v5.2.3    Provides integration for ProxyManager with various Symfony components
symfony/redis-messenger              v5.2.3    Symfony Redis extension Messenger Bridge
symfony/routing                      v5.2.3    Maps an HTTP request to a set of configuration variables
symfony/security-bundle              v5.2.3    Provides a tight integration of the Security component into the Symfony full-stack framework
symfony/security-core                v5.2.3    Symfony Security Component - Core Library
symfony/security-csrf                v5.2.3    Symfony Security Component - CSRF Library
symfony/security-guard               v5.2.3    Symfony Security Component - Guard
symfony/security-http                v5.2.3    Symfony Security Component - HTTP Integration
symfony/service-contracts            v2.2.0    Generic abstractions related to writing services
symfony/stopwatch                    v5.2.3    Provides a way to profile code
symfony/string                       v5.2.3    Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
symfony/translation                  v5.2.3    Provides tools to internationalize your application
symfony/translation-contracts        v2.3.0    Generic abstractions related to translation
symfony/twig-bridge                  v5.2.3    Provides integration for Twig with various Symfony components
symfony/twig-bundle                  v5.2.3    Provides a tight integration of Twig into the Symfony full-stack framework
symfony/validator                    v5.2.3    Provides tools to validate values
symfony/var-dumper                   v5.2.3    Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter                 v5.2.3    Allows exporting any serializable PHP data structure to plain PHP code
symfony/web-profiler-bundle          v5.2.3    Provides a development tool that gives detailed information about the execution of any request
symfony/yaml                         v5.2.3    Loads and dumps YAML files
symfonycasts/reset-password-bundle   v1.4.0    Symfony bundle that adds password reset functionality.
theseer/tokenizer                    1.2.0     A small library for converting tokenized PHP source code into XML and potentially other formats
twig/twig                            v3.3.0    Twig, the flexible, fast, and secure template language for PHP
webmozart/assert                     1.9.1     Assertions to validate method input/output with nice error messages.
willdurand/js-translation-bundle     4.0.1     A pretty nice way to expose your translation messages to your JavaScript.
  • Suite configuration:
actor: ApiTester
modules:
    enabled:
        - \App\Tests\Helper\Api
        - Symfony:
            app_path: 'src'
            environment: 'test'
        - Doctrine2:
            depends: Symfony
        - REST:
            url: https://localhost
            depends: Symfony
        - DataFactory:
            depends: Doctrine2
        - \App\Tests\Helper\Factories

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions