Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel module + Doctrine ORM cleanup not working #17

Open
99hops opened this issue May 8, 2020 · 4 comments
Open

Laravel module + Doctrine ORM cleanup not working #17

99hops opened this issue May 8, 2020 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@99hops
Copy link

99hops commented May 8, 2020

What are you trying to achieve?

Rollback transactions between each test

What do you get instead?

Database changes not reverted

Provide console output if related. Use -vvv mode for more details.

vendor/bin/codecept -vvv run api
Codeception PHP Testing Framework v4.1.4
Powered by PHPUnit 8.5.4 by Sebastian Bergmann and contributors.
Running with seed: 


Api Tests (2) --------------------------------------------------------------------------------------------------------
Modules: \Helper\Api, Cli, Laravel5, REST
----------------------------------------------------------------------------------------------------------------------
Recreating database...
Dropped all tables successfully.                                                                       
Database seeding completed successfully.                                                                            
done!
UserRegistrationCest: Registration success test
Signature: UserRegistrationCest:registrationSuccessTest
Test: tests/api/UserRegistrationCest.php:registrationSuccessTest
Scenario --
**[Database] Transaction started**
I send post "http://api.project.local/v1/auth/register",{"email":"davert@codeception.com","phone":"+380670000222","pa...}
[Request] POST http://api.project.local/v1/auth/register {"email":"davert@codeception.com","phone":"+380670000222","password":"password","firstName":"firstName","lastName":"firstName","username":"username","inviteHash":"invite","nationality":"nationality","country":"USA","city":"NY","street":"Park Avenue","homeNumber":"256","zip":"23699","birthDate":"1988-01-01"}                                                                                                             
[Request Headers] []
[Page] http://api.project.local/v1/auth/register
[Response] 201
[Request Cookies] []
[Response Headers] {"cache-control":["no-cache, private"],"date":["Fri, 08 May 2020 13:23:10 GMT"],"content-type":["application/json"]}                                                                                                   
[Response] {"result":{},"version":"v0.0.1","memory-c":40.9822,"memory-p":41.1235}
I see response code is 201
I see response is json 
I can see response contains json {"result":[]}
PASSED 

**[Database] Transaction cancelled; all changes reverted.**


UserRegistrationCest: Registration success2 test
Signature: UserRegistrationCest:registrationSuccess2Test
Test: tests/api/UserRegistrationCest.php:registrationSuccess2Test
Scenario --
**[Database] Transaction started**
I send post "http://api.project.local/v1/auth/register",{"email":"davert@codeception.com","phone":"+380670000222","pa...}
[Request] POST http://api.project.local/v1/auth/register {"email":"davert@codeception.com","phone":"+380670000222","password":"password","firstName":"firstName","lastName":"firstName","username":"username","inviteHash":"invite","nationality":"nationality","country":"USA","city":"NY","street":"Park Avenue","homeNumber":"256","zip":"23699","birthDate":"1988-01-01"}                                                                                                             
[Request Headers] []
[Page] http://api.project.local/v1/auth/register
[Response] 422
[Request Cookies] []
[Response Headers] {"cache-control":["no-cache, private"],"date":["Fri, 08 May 2020 13:23:11 GMT"],"content-type":["application/json"],"access-control-allow-origin":[null],"vary":["Origin"]}                                            
[Response] {"version":"v0.0.1","messages":[{"severity":"error","text":"The given data was invalid.","code":422}],"validation":{"phone":["The phone has already been taken."],"username":["The username has already been taken."],"email":["The email has already been taken."]},"memory-c":43.3535,"memory-p":43.3658}                                          
I see response code is 201
FAIL 

**[Database] Transaction cancelled; all changes reverted.**
----------------------------------------------------------------------------------------------------------------------
Tests ran into 'codeception' environtment


Time: 11.5 seconds, Memory: 44.50 MB

There was 1 failure:

---------
1) UserRegistrationCest: Registration success2 test
Test  tests/api/UserRegistrationCest.php:registrationSuccess2Test
Step  See response code is 201
Fail  Expected HTTP Status Code: 201 (Created). Actual Status Code: 422 (Unprocessable Entity)
Failed asserting that 422 matches expected 201.

Scenario Steps:                                                                                                       

2. $I->seeResponseCodeIs(201) at tests/api/UserRegistrationCest.php:56
1. $I->sendPOST("http://api.project.local/v1/auth/register",{"email":"davert@codeception.com","phone":"+380670000222...})at tests/api/UserRegistrationCest.php:41

/www/refactor/vendor/phpunit/phpunit/src/Framework/Constraint/IsEqual.php:96
/www/refactor/vendor/phpunit/phpunit/src/Framework/Assert.php:2887
/www/refactor/vendor/phpunit/phpunit/src/Framework/Assert.php:602
/www/refactor/vendor/codeception/lib-asserts/src/Codeception/Util/Shared/Asserts.php:41
/www/refactor/vendor/codeception/lib-innerbrowser/src/Codeception/Lib/InnerBrowser.php:1671
/www/refactor/vendor/codeception/module-rest/src/Codeception/Module/REST.php:1269
/www/refactor/vendor/codeception/codeception/src/Codeception/Step.php:268
/www/refactor/vendor/codeception/codeception/src/Codeception/Scenario.php:76
/www/refactor/tests/_support/_generated/ApiTesterActions.php:3351
/www/refactor/tests/api/UserRegistrationCest.php:56
/www/refactor/vendor/codeception/codeception/src/Codeception/Lib/Di.php:127
/www/refactor/vendor/codeception/codeception/src/Codeception/Test/Cest.php:138
/www/refactor/vendor/codeception/codeception/src/Codeception/Test/Cest.php:150
/www/refactor/vendor/codeception/codeception/src/Codeception/Test/Cest.php:82
/www/refactor/vendor/codeception/codeception/src/Codeception/Test/Test.php:88
/www/refactor/vendor/phpunit/phpunit/src/Framework/TestSuite.php:597
/www/refactor/vendor/codeception/phpunit-wrapper/src/Runner.php:117
/www/refactor/vendor/codeception/codeception/src/Codeception/SuiteManager.php:161
/www/refactor/vendor/codeception/codeception/src/Codeception/Codecept.php:196
/www/refactor/vendor/codeception/codeception/src/Codeception/Codecept.php:163
/www/refactor/vendor/codeception/codeception/src/Codeception/Command/Run.php:503
/www/refactor/vendor/codeception/codeception/src/Codeception/Command/Run.php:397
/www/refactor/vendor/symfony/console/Command/Command.php:255
/www/refactor/vendor/symfony/console/Application.php:1001
/www/refactor/vendor/symfony/console/Application.php:271
/www/refactor/vendor/symfony/console/Application.php:147
/www/refactor/vendor/codeception/codeception/src/Codeception/Application.php:117
/www/refactor/vendor/codeception/codeception/app.php:46
/www/refactor/vendor/codeception/codeception/app.php:47
/www/refactor/vendor/codeception/codeception/codecept:7

Artifacts:

Html: /www/refactor/tests/_output/UserRegistrationCest.registrationSuccess2Test.fail.json
Response: /www/refactor/tests/_output/UserRegistrationCest.registrationSuccess2Test.fail.json
Body: {"version":"v0.0.1","messages":[{"severity":"error","text":"The given data was invalid.","code":422}],"validation":{"phone":["The phone has already been taken."],"username":["The username has already been taken."],"email":["The email has already been taken."]},"memory-c":43.3535,"memory-p":43.3658}

FAILURES!
Tests: 2, Assertions: 5, Failures: 1.

Provide test source code if related

<?php

/**
 * Class UserRegistrationCest
 */
class UserRegistrationCest
{

    /**
     * @param ApiTester $I
     */
    public function registrationSuccessTest(ApiTester $I)
    {
        $I->sendPOST(route('api.v1.auth.register'), [
            'email'       => 'davert@codeception.com',
            'phone'       => '+380670000222',
            'password'    => 'password',
            'firstName'   => 'firstName',
            'lastName'    => 'firstName',
            'username'    => 'username',
            'inviteHash'  => 'invite',
            'nationality' => 'nationality',
            'country'     => 'USA',
            'city'        => 'NY',
            'street'      => 'Park Avenue',
            'homeNumber'  => '256',
            'zip'         => '23699',
            'birthDate'   => '1988-01-01',
        ]);
        $I->seeResponseCodeIs(\Codeception\Util\HttpCode::CREATED); // 201
        $I->seeResponseIsJson();
        $I->canSeeResponseContainsJson(['result' => []]);
    }

    /**
     * @param ApiTester $I
     */
    public function registrationSuccess2Test(ApiTester $I)
    {
        $I->sendPOST(route('api.v1.auth.register'), [
            'email'       => 'davert@codeception.com',
            'phone'       => '+380670000222',
            'password'    => 'password',
            'firstName'   => 'firstName',
            'lastName'    => 'firstName',
            'username'    => 'username',
            'inviteHash'  => 'invite',
            'nationality' => 'nationality',
            'country'     => 'USA',
            'city'        => 'NY',
            'street'      => 'Park Avenue',
            'homeNumber'  => '256',
            'zip'         => '23699',
            'birthDate'   => '1988-01-01',
        ]);
        $I->seeResponseCodeIs(\Codeception\Util\HttpCode::CREATED); // 201
        $I->seeResponseIsJson();
        $I->canSeeResponseContainsJson(['result' => []]);
    }
}

Details

  • Codeception version:
  • PHP Version: 4.1.4
  • Operating System: Unbuntu 20.04
  • Installation type: Composer
  • List of installed packages (composer show)
asm89/stack-cors                      1.3.0     Cross-origin resource sharing library and stack middleware
barryvdh/laravel-cors                 v0.11.4   Adds CORS (Cross-Origin Resource Sharing) headers support in your...
barryvdh/laravel-ide-helper           v2.7.0    Laravel IDE Helper, generates correct PHPDocs for all Facade clas...
barryvdh/reflection-docblock          v2.0.6   
behat/gherkin                         v4.6.2    Gherkin DSL parser for PHP 5.3
beyondcode/laravel-dump-server        1.3.0     Symfony Var-Dump Server for Laravel
cakephp/chronos                       1.3.0     A simple API extension for DateTime.
codeception/codeception               4.1.4     BDD-style testing framework
codeception/lib-asserts               1.12.0    Assertion methods used by Codeception core and Asserts module
codeception/lib-innerbrowser          1.3.1     Parent library for all Codeception framework modules and PhpBrowser
codeception/module-asserts            1.2.1     Codeception module containing various assertions
codeception/module-cli                1.0.2     Codeception module for testing basic shell commands and shell output
codeception/module-db                 1.0.1     WebDriver module for Codeception
codeception/module-doctrine2          1.0.1     Doctrine2 module for Codeception
codeception/module-laravel5           1.1.0     Codeception module for Laravel 5 framework
codeception/module-phpbrowser         1.0.0     Codeception module for testing web application over HTTP
codeception/module-rest               1.2.0     REST module for Codeception
codeception/module-symfony            1.1.0     Codeception module for Symfony framework
codeception/phpunit-wrapper           8.1.2     PHPUnit classes used by Codeception
codeception/stub                      3.6.1     Flexible Stub wrapper for PHPUnit's Mock Builder
composer/ca-bundle                    1.2.7     Lets you find a path to the system CA bundle, and includes a fall...
composer/composer                     1.10.6    Composer helps you declare, manage and install dependencies of PH...
composer/semver                       1.5.1     Semver library that offers utilities, version constraint parsing ...
composer/spdx-licenses                1.5.3     SPDX licenses list and validation library.
composer/xdebug-handler               1.4.1     Restarts a process without Xdebug.
creof/doctrine2-spatial               1.2.0     Doctrine2 multi-platform support for spatial types and functions
creof/geo-parser                      2.2.1     Parser for geography coordinate strings
creof/wkb-parser                      v2.3.0    Parser for well-known binary (WKB/EWKB) object data
creof/wkt-parser                      2.2.0     Parser for well-known text (WKT) object strings
defuse/php-encryption                 v2.2.1    Secure PHP Encryption Library
dnoegel/php-xdg-base-dir              v0.1.1    implementation of xdg base directory specification for php
doctrine/annotations                  1.10.2    Docblock Annotations Parser
doctrine/cache                        1.10.0    PHP Doctrine Cache library is a popular cache implementation that...
doctrine/collections                  1.6.4     PHP Doctrine Collections library that adds additional functionali...
doctrine/common                       2.12.0    PHP Doctrine Common project is a library that provides additional...
doctrine/dbal                         2.10.2    Powerful PHP database abstraction layer (DBAL) with many features...
doctrine/event-manager                1.1.0     The Doctrine Event Manager is a simple PHP event system that was ...
doctrine/inflector                    1.3.1     Common String Manipulations with regard to casing and singular/pl...
doctrine/instantiator                 1.3.0     A small, lightweight utility to instantiate objects in PHP withou...
doctrine/lexer                        1.2.0     PHP Doctrine Lexer parser library that can be used in Top-Down, R...
doctrine/migrations                   v1.8.1    Database Schema migrations using Doctrine DBAL
doctrine/orm                          v2.7.2    Object-Relational-Mapper for PHP
doctrine/persistence                  1.3.7     The Doctrine Persistence project is a set of shared interfaces an...
doctrine/reflection                   1.2.1     The Doctrine Reflection project is a simple library used by the v...
dragonmantank/cron-expression         v2.3.0    CRON for PHP: Calculate the next or previous run date and determi...
egulias/email-validator               2.1.17    A library for validating emails against several RFCs
facade/flare-client-php               1.3.2     Send PHP errors to Flare
facade/ignition                       1.16.1    A beautiful error page for Laravel applications.
facade/ignition-contracts             1.0.0     Solution contracts for Ignition
fideloper/proxy                       4.3.0     Set trusted proxies for Laravel
filp/whoops                           2.7.2     php error handling for cool kids
firebase/php-jwt                      v5.2.0    A simple library to encode and decode JSON Web Tokens (JWT) in PH...
flow/jsonpath                         0.5.0     JSONPath implementation for parsing, searching and flattening arrays
fzaninotto/faker                      v1.9.1    Faker is a PHP library that generates fake data for you.
giggsey/libphonenumber-for-php        8.12.3    PHP Port of Google's libphonenumber
giggsey/locale                        1.8       Locale functions required by libphonenumber-for-php
guzzlehttp/guzzle                     6.5.3     Guzzle is a PHP HTTP client library
guzzlehttp/promises                   v1.3.1    Guzzle promises library
guzzlehttp/psr7                       1.6.1     PSR-7 message implementation that also provides common utility me...
hamcrest/hamcrest-php                 v2.0.0    This is the PHP port of Hamcrest Matchers
intervention/image                    2.5.1     Image handling and manipulation library with support for Laravel ...
itsgoingd/clockwork                   v4.1.3    php dev tools integrated to your browser
jakub-onderka/php-console-color       v0.2     
jakub-onderka/php-console-highlighter v0.4      Highlight PHP code in terminal
jdorn/sql-formatter                   v1.2.17   a PHP SQL highlighting library
jean85/pretty-package-versions        1.2       A wrapper for ocramius/package-versions to get pretty versions st...
justinrainbow/json-schema             5.2.9     A library to validate a json schema.
laminas/laminas-code                  3.4.1     Extensions to the PHP Reflection API, static code scanning, and c...
laminas/laminas-eventmanager          3.2.1     Trigger and listen to events within a PHP application
laminas/laminas-zendframework-bridge  1.0.3     Alias legacy ZF class names to Laminas Project equivalents.
laravel-doctrine/migrations           1.3.2     Doctrine Migrations for Laravel
laravel-doctrine/orm                  1.5.7     A Doctrine ORM bridge for Laravel 5
laravel/framework                     v6.18.13  The Laravel Framework.
laravel/homestead                     v9.4.1    A virtual machine for web artisans.
laravel/horizon                       v3.7.2    Dashboard and code-driven configuration for Laravel queues.
laravel/passport                      v7.5.1    Laravel Passport provides OAuth2 server support to Laravel.
laravel/telescope                     v2.1.7    An elegant debug assistant for the Laravel framework.
laravel/tinker                        v1.0.10   Powerful REPL for the Laravel framework.
laravel/ui                            v1.2.0    Laravel UI utilities and presets.
lcobucci/jwt                          3.3.1     A simple library to work with JSON Web Token and JSON Web Signature
league/commonmark                     1.4.3     Highly-extensible PHP Markdown parser which fully supports the Co...
league/event                          2.2.0     Event package
league/flysystem                      1.0.67    Filesystem abstraction: Many filesystems, one API.
league/iso3166                        2.1.5     ISO 3166-1 PHP Library
league/oauth2-server                  7.4.0     A lightweight and powerful OAuth 2.0 authorization and resource s...
mockery/mockery                       1.3.1     Mockery is a simple yet flexible PHP mock object framework
monolog/monolog                       2.0.2     Sends your logs to files, sockets, inboxes, databases and various...
moontoast/math                        1.2.1     A mathematics library, providing functionality for large numbers
myclabs/deep-copy                     1.9.5     Create deep copies (clones) of your objects
nesbot/carbon                         2.33.0    An API extension for DateTime that supports 281 different languages.
nette/bootstrap                       v3.0.1    🅱 Nette Bootstrap: the simple way to configure and bootstrap y...
nette/di                              v3.0.3    💎 Nette Dependency Injection Container: Flexible, compiled and...
nette/finder                          v2.5.2    🔍 Nette Finder: find files and directories with an intuitive API.
nette/neon                            v3.1.2    🍸 Nette NEON: encodes and decodes NEON file format.
nette/php-generator                   v3.3.4    🐘 Nette PHP Generator: generates neat PHP code for you. Suppor...
nette/robot-loader                    v3.2.3    🍀 Nette RobotLoader: high performance and comfortable autoload...
nette/schema                          v1.0.2    📐 Nette Schema: validating data structures against a given Sch...
nette/utils                           v3.1.1    🛠 Nette Utils: lightweight utilities for string & array manipu...
nikic/php-parser                      v4.4.0    A PHP parser written in PHP
nunomaduro/collision                  v3.0.1    Cli error handling for console/command-line PHP applications.
nunomaduro/larastan                   v0.4.3    Larastan - Discover bugs in your code without running it. A phpst...
ocramius/package-versions             1.8.0     Composer plugin that provides efficient querying for installed pa...
ocramius/proxy-manager                2.8.0     A library providing utilities to generate, instantiate and genera...
opis/closure                          3.5.1     A library that can be used to serialize closures (anonymous funct...
paragonie/random_compat               v9.99.99  PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
phar-io/manifest                      1.0.3     Component for reading phar.io manifest information from a PHP Arc...
phar-io/version                       2.0.1     Library for handling version information and constraints
phpdocumentor/reflection-common       2.1.0     Common reflection classes used by phpdocumentor to reflect the co...
phpdocumentor/reflection-docblock     5.1.0     With this component, a library can provide support for annotation...
phpdocumentor/type-resolver           1.1.0     A PSR-5 based resolver of Class names, Types and Structural Eleme...
phpoption/phpoption                   1.7.3     Option Type for PHP
phpseclib/bcmath_compat               1.0.5     PHP 5.x/7.x polyfill for bcmath extension
phpseclib/phpseclib                   2.0.27    PHP Secure Communications Library - Pure-PHP implementations of R...
phpspec/prophecy                      v1.10.3   Highly opinionated mocking framework for PHP 5.3+
phpstan/phpdoc-parser                 0.3.5     PHPDoc parser with support for nullable, intersection and generic...
phpstan/phpstan                       0.11.19   PHPStan - PHP Static Analysis Tool
phpunit/php-code-coverage             7.0.10    Library that provides collection, processing, and rendering funct...
phpunit/php-file-iterator             2.0.2     FilterIterator implementation that filters files based on a list ...
phpunit/php-text-template             1.2.1     Simple template engine.
phpunit/php-timer                     2.1.2     Utility class for timing
phpunit/php-token-stream              3.1.1     Wrapper around PHP's tokenizer extension.
phpunit/phpunit                       8.5.4     The PHP Unit Testing framework.
predis/predis                         v1.1.1    Flexible and feature-complete Redis client for PHP and HHVM
psr/container                         1.0.0     Common Container Interface (PHP FIG PSR-11)
psr/http-factory                      1.0.1     Common interfaces for PSR-7 HTTP message factories
psr/http-message                      1.0.1     Common interface for HTTP messages
psr/log                               1.1.3     Common interface for logging libraries
psr/simple-cache                      1.0.1     Common interfaces for simple caching
psy/psysh                             v0.9.12   An interactive shell for modern PHP.
ralouphie/getallheaders               3.0.3     A polyfill for getallheaders.
ramsey/uuid                           3.9.3     Formerly rhumsaa/uuid. A PHP 5.4+ library for generating RFC 4122...
scrivo/highlight.php                  v9.18.1.1 Server side syntax highlighter that supports 185 languages. It's ...
sebastian/code-unit-reverse-lookup    1.0.1     Looks up which function or method a line of code belongs to
sebastian/comparator                  3.0.2     Provides the functionality to compare PHP values for equality
sebastian/diff                        3.0.2     Diff implementation
sebastian/environment                 4.2.3     Provides functionality to handle HHVM/PHP environments
sebastian/exporter                    3.1.2     Provides the functionality to export PHP variables for visualization
sebastian/global-state                3.0.0     Snapshotting of global state
sebastian/object-enumerator           3.0.3     Traverses array structures and object graphs to enumerate all ref...
sebastian/object-reflector            1.1.1     Allows reflection of object attributes, including inherited and n...
sebastian/recursion-context           3.0.0     Provides functionality to recursively process PHP variables
sebastian/resource-operations         2.0.1     Provides a list of PHP built-in functions that operate on resources
sebastian/type                        1.1.3     Collection of value objects that represent the types of the PHP t...
sebastian/version                     2.0.1     Library that helps with managing the version number of Git-hosted...
seld/jsonlint                         1.8.0     JSON Linter
seld/phar-utils                       1.1.0     PHAR file format utilities, for when PHP phars you up
squizlabs/php_codesniffer             3.5.5     PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detec...
swiftmailer/swiftmailer               v6.2.3    Swiftmailer, free feature-rich PHP mailer
symfony/browser-kit                   v5.0.8    Symfony BrowserKit Component
symfony/console                       v4.4.8    Symfony Console Component
symfony/css-selector                  v5.0.8    Symfony CssSelector Component
symfony/debug                         v4.4.8    Symfony Debug Component
symfony/dom-crawler                   v5.0.8    Symfony DomCrawler Component
symfony/error-handler                 v4.4.8    Symfony ErrorHandler Component
symfony/event-dispatcher              v4.4.8    Symfony EventDispatcher Component
symfony/event-dispatcher-contracts    v1.1.7    Generic abstractions related to dispatching event
symfony/filesystem                    v5.0.8    Symfony Filesystem Component
symfony/finder                        v4.4.8    Symfony Finder Component
symfony/http-foundation               v4.4.8    Symfony HttpFoundation Component
symfony/http-kernel                   v4.4.8    Symfony HttpKernel Component
symfony/mime                          v5.0.8    A library to manipulate MIME messages
symfony/polyfill-ctype                v1.15.0   Symfony polyfill for ctype functions
symfony/polyfill-iconv                v1.15.0   Symfony polyfill for the Iconv extension
symfony/polyfill-intl-idn             v1.15.0   Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-mbstring             v1.15.0   Symfony polyfill for the Mbstring extension
symfony/polyfill-php72                v1.15.0   Symfony polyfill backporting some PHP 7.2+ features to lower PHP ...
symfony/polyfill-php73                v1.15.0   Symfony polyfill backporting some PHP 7.3+ features to lower PHP ...
symfony/process                       v4.4.8    Symfony Process Component
symfony/psr-http-message-bridge       v1.3.0    PSR HTTP message bridge
symfony/routing                       v4.4.8    Symfony Routing Component
symfony/serializer                    v5.0.8    Symfony Serializer Component
symfony/service-contracts             v2.0.1    Generic abstractions related to writing services
symfony/translation                   v4.4.8    Symfony Translation Component
symfony/translation-contracts         v2.0.1    Generic abstractions related to translation
symfony/var-dumper                    v4.4.8    Symfony mechanism for exploring and dumping PHP variables
symfony/yaml                          v5.0.8    Symfony Yaml Component
theseer/tokenizer                     1.1.3     A small library for converting tokenized PHP source code into XML...
tijsverkoyen/css-to-inline-styles     2.2.2     CssToInlineStyles is a class that enables you to convert HTML-pag...
vlucas/phpdotenv                      v3.6.4    Loads environment variables from `.env` to `getenv()`, `$_ENV` an...
webimpress/safe-writer                2.0.1     Tool to write files safely, to avoid race conditions
webmozart/assert                      1.8.0     Assertions to validate method input/output with nice error messages.
zendframework/zend-diactoros          2.2.1     PSR HTTP Message implementations
  • Suite configuration:
actor: ApiTester
modules:
    enabled:
        - \Helper\Api
        - Cli
        #- Db
        #- Doctrine2:
            #connection_callback: ['Doctrine\Common\Persistence\ManagerRegistry', 'getManager']
            #connection_callback: ['Doctrine\ORM\EntityManagerInterface', 'getConnection']
            #cleanup: true
        - Laravel5:
            environment_file: .env.codeception
            cleanup: true #wrap each test in ORM transaction
            #depends: Doctrine2
        - REST:
            url: http://api.project.local/v1/
            depends: Laravel5
            part: Json
extensions:
  enabled:
    - \Extension\Api

At the end the first test passed but the second one which is trying to insert the same db record fails and the previous one is not removed.

What's specific in this project is that is uses Laravel (6.18.13) with Doctrine (1.5 provided by laravel-doctrine/orm). I tried everything possible I could find without success.

What's obvious is [Database] Transaction started / [Database] Transaction cancelled; all changes reverted.

Could it be that the Laravel5 module only supports Eloquent?

Refering here https://codeception.com/for/laravel#functional-tests it is stated:
"Codeception will also use Eloquent to cleanup changes to database by wrapping tests into transaction and rolling it back in the end of a test. This makes tests isolated and fast. Laravel5 module allows to access services from DIC container, user authentication methods, fixture generators, check form validations and more."

If so what options do I have to make this work with Doctrine?

@Naktibalda
Copy link
Member

Have you got it working?

Dependencies were messed up in that configuration.
Doctrine2 module must depend on framework module, but Laravel5 module (and Laravel module now) does not implement DoctrineProvider interface, so you have to implement helper module which implements DoctrineProvider interface and retrieves the instance of Doctrine Entity Manager from Laravel module.

@Naktibalda Naktibalda transferred this issue from Codeception/Codeception Jan 2, 2021
@Naktibalda
Copy link
Member

@TavoNiievez Would it be possible to implement DoctrineProvider interface in Laravel module?

Symfony implementation

@TavoNiievez
Copy link
Member

TavoNiievez commented Jan 2, 2021

Would it be possible to implement the DoctrineProvider interface in the Laravel module?

Absolutely yes.

However, by far, that's not the biggest challenge.

The most popular way to integrate the Doctrine ORM into Laravel is with the lavarel-doctrine project. There are complete but somewhat outdated guides with which you can achieve this in the test project, updating some things like the validation.

To implement this method, we should also check that the integration of the Doctrine and Laravel modules works in their entirety.

I can gladly guide the process if anyone is interested in forking the test project and integrating Doctrine for the two Laravel versions that are currently being tested (6.x LTS and the most recent 8.x main).

From there the implementation of _getEntityManager() can be carried out, and tests could be written to verify the integration, as well as update create the corresponding documentation.

@TavoNiievez TavoNiievez changed the title Laravel5 module + Doctrine ORM cleanup not working Laravel module + Doctrine ORM cleanup not working Jan 19, 2021
@TavoNiievez TavoNiievez added enhancement New feature or request help wanted Extra attention is needed labels Jan 19, 2021
@TavoNiievez
Copy link
Member

What's wrong with this issue is that, for some reason, the _before hook of the Doctrine module executes before the one of the Laravel module, while the _after hook of the Doctrine module never executes.

Adding the following makes both the Doctrine integration and the cleanup: true option work:

    public function _getEntityManager()
    {
        if (!$this->client) {
            $this->client = new LaravelConnector($this);
        }
        return $this->app['em'];
    }

and...

    public function _before(TestInterface $test)
    {
        $this->client = new LaravelConnector($this);

        $this->getModule('Doctrine2')->_before($test);
    }

    public function _after(TestInterface $test)
    {
        $this->getModule('Doctrine2')->_after($test);
    }

Of course, this is not the best solution...
It is still necessary to check details such as that the memory is cleaned correctly.

But now that there is where to do tests ( https://github.com/TavoNiievez/laravel-module-tests/tree/doctrine ) it should be easier to solve these problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants