Codeception: Yii2 Module SQL error on amOnRoute: Syntax error or access violation: 1305 SAVEPOINT LEVEL1 does not exist The SQL being executed was: RELEASE SAVEPOINT LEVEL1

Created on 28 Oct 2016  路  13Comments  路  Source: Codeception/Codeception

What are you trying to achieve?

I was trying to use the new amOnRoute.

What do you get instead?

Provide console output if related. Use -vvv mode for more details.
PostCommentCest: Ensure that the comments are being displayed
Signature: frontendtestsfunctionalPostCommentCest:testIfCommentsAreBeingDisplayed
Test: tests/functional/PostCommentCest.php:testIfCommentsAreBeingDisplayed
Scenario --
[yiidbConnection::open] 'Opening DB connection: mysql:host=db;port=3306;dbname=project_tests'
I have fixtures {"user":{"class":"commonfixturesUserFixture"},"post":...}
I grab fixture "post"
I login
I am on page "/login"
[Request Headers] []
[Page] /login
[Response] 200
[Request Cookies] []
[Response Headers] {"content-type":["text/html; charset=UTF-8"]}
I am going to try to login with correct credentials
I login
I fill field "LoginForm[email]","[email protected]"
I fill field "LoginForm[password]","password_0"
I check option "#loginform-rememberme"
I click "login-button"
[Uri] https://localhost/login
[Method] POST
[Parameters] {"_csrf-frontend":"bTZmOGZMVjAITg0BNDYmQ11/FmpTJDMIKEY5UyMtJ3odA19RARg9XQ==","LoginForm[referer]":"","LoginForm[email]":"[email protected]","LoginForm[password]":"password_0","LoginForm[rememberMe]":"1","login-button":""}
[Request Headers] []
[yiiwebUser::login] 'User '3' logged in from . Session not enabled.'
[Headers] {"location":["https://localhost/"],"content-type":["text/html; charset=UTF-8"]}
[Page] https://localhost/login
[Response] 302
[Request Cookies] {"_csrf-frontend":"5bcc147ba8dc17ddfb54a389b6d66406a8a909636abe78a50bbf406f69adf0d9a:2:{i:0;s:14:"_csrf-frontend";i:1;s:32:"exk9Rzps0IpR5he8Ep_kEaqJp59igTkm";}"}
[Response Headers] {"location":["https://localhost/"],"content-type":["text/html; charset=UTF-8"]}
[Redirecting to] https://localhost/
[yiiwebUser::login] 'User '3' logged in from . Session not enabled.'
[Headers] {"location":["https://localhost/ofertas"],"content-type":["text/html; charset=UTF-8"]}
[Page] https://localhost/
[Response] 302
[Request Cookies] {"_csrf-frontend":"5bcc147ba8dc17ddfb54a389b6d66406a8a909636abe78a50bbf406f69adf0d9a:2:{i:0;s:14:"_csrf-frontend";i:1;s:32:"exk9Rzps0IpR5he8Ep_kEaqJp59igTkm";}","frontendCookieAuth_authToken":"76dec6c61c9bba0510aeb0a3b5735afae618dd1981fb6d6b46d15a800dc79995a:2:{i:0;s:28:"frontendCookieAuth_authToken";i:1;s:32:"HP187Mvq7Mmm3CTU80dLkGmni_FUH_lR";}"}
[Response Headers] {"location":["https://localhost/ofertas"],"content-type":["text/html; charset=UTF-8"]}
[Redirecting to] https://localhost/ofertas
[yiiwebUser::login] 'User '3' logged in from . Session not enabled.'
[Page] https://localhost/ofertas
[Response] 200
[Request Cookies] {"_csrf-frontend":"5bcc147ba8dc17ddfb54a389b6d66406a8a909636abe78a50bbf406f69adf0d9a:2:{i:0;s:14:"_csrf-frontend";i:1;s:32:"exk9Rzps0IpR5he8Ep_kEaqJp59igTkm";}","frontendCookieAuth_authToken":"76dec6c61c9bba0510aeb0a3b5735afae618dd1981fb6d6b46d15a800dc79995a:2:{i:0;s:28:"frontendCookieAuth_authToken";i:1;s:32:"HP187Mvq7Mmm3CTU80dLkGmni_FUH_lR";}"}
[Response Headers] {"content-type":["text/html; charset=UTF-8"]}
I see link "Logout","user/logout"
I don't see link "Login"
I don't see link "Signup"
I am on page "oferta/1/post-1-title"
[Request Headers] []
[yiiwebUser::login] 'User '3' logged in from . Session not enabled.'
[Page] oferta/1/post-1-title
[Response] 200
[Request Cookies] {"_csrf-frontend":"5bcc147ba8dc17ddfb54a389b6d66406a8a909636abe78a50bbf406f69adf0d9a:2:{i:0;s:14:"_csrf-frontend";i:1;s:32:"exk9Rzps0IpR5he8Ep_kEaqJp59igTkm";}","frontendCookieAuth_authToken":"76dec6c61c9bba0510aeb0a3b5735afae618dd1981fb6d6b46d15a800dc79995a:2:{i:0;s:28:"frontendCookieAuth_authToken";i:1;s:32:"HP187Mvq7Mmm3CTU80dLkGmni_FUH_lR";}"}
[Response Headers] {"content-type":["text/html; charset=UTF-8"]}
I see "Post 1 title","h1"
I expect to see that the post has comments
I see "1","dd.comments"
I don't see "Seja o primeiro a comentar."
I see element "#post-comments ol.comments"
I am going to check if a comment is being properly nestled
I grab fixture "post"
I am on route "post/view",{"id":"3","slug":"post-3-title"}
[Request Headers] []
[yiiwebUser::login] 'User '3' logged in from . Session not enabled.'
ERROR


1) PostCommentCest: Ensure that the comments are being displayed
Test tests/functional/PostCommentCest.php:testIfCommentsAreBeingDisplayed

The SQL being executed was: RELEASE SAVEPOINT LEVEL1

Scenario Steps:

  1. $I->amOnRoute("post/view",{"id":"3","slug":"post-3-title"}) at tests/functional/PostCommentCest.php:43
  2. $I->grabFixture("post") at tests/functional/PostCommentCest.php:42
  3. // I am going to check if a comment is being properly nestled
  4. $I->seeElement("#post-comments ol.comments") at tests/functional/PostCommentCest.php:38
  5. $I->dontSee("Seja o primeiro a comentar.") at tests/functional/PostCommentCest.php:37
  6. $I->see("1","dd.comments") at tests/functional/PostCommentCest.php:36

/var/www/html/project/vendor/yiisoft/yii2/db/Command.php:854
/var/www/html/project/vendor/yiisoft/yii2/db/Schema.php:414
/var/www/html/project/vendor/yiisoft/yii2/db/Transaction.php:158
/var/www/html/project/common/models/PostVisit.php:111
/var/www/html/project/frontend/controllers/PostController.php:126
/var/www/html/project/vendor/yiisoft/yii2/base/InlineAction.php:55
/var/www/html/project/vendor/yiisoft/yii2/base/Controller.php:154
/var/www/html/project/vendor/yiisoft/yii2/base/Module.php:454
/var/www/html/project/vendor/yiisoft/yii2/web/Application.php:100
/var/www/html/project/vendor/codeception/base/src/Codeception/Lib/Connector/Yii2.php:143
/var/www/html/project/vendor/symfony/browser-kit/Client.php:315
/var/www/html/project/vendor/codeception/base/src/Codeception/Lib/InnerBrowser.php:191
/var/www/html/project/vendor/codeception/base/src/Codeception/Lib/InnerBrowser.php:239
/var/www/html/project/vendor/codeception/base/src/Codeception/Lib/InnerBrowser.php:331
/var/www/html/project/vendor/codeception/base/src/Codeception/Module/Yii2.php:453
/var/www/html/project/vendor/codeception/base/src/Codeception/Module/Yii2.php:467
/var/www/html/project/vendor/codeception/base/src/Codeception/Step.php:256
/var/www/html/project/vendor/codeception/base/src/Codeception/Scenario.php:69
/var/www/html/project/frontend/tests/_support/_generated/FunctionalTesterActions.php:1109
/var/www/html/project/frontend/tests/functional/PostCommentCest.php:43
/var/www/html/project/vendor/codeception/base/src/Codeception/Lib/Di.php:123
/var/www/html/project/vendor/codeception/base/src/Codeception/Test/Cest.php:135
/var/www/html/project/vendor/codeception/base/src/Codeception/Test/Cest.php:147
/var/www/html/project/vendor/codeception/base/src/Codeception/Test/Cest.php:81
/var/www/html/project/vendor/codeception/base/src/Codeception/Test/Test.php:90
/var/www/html/project/vendor/phpunit/phpunit/src/Framework/TestSuite.php:753
/var/www/html/project/vendor/codeception/base/src/Codeception/PHPUnit/Runner.php:98
/var/www/html/project/vendor/codeception/base/src/Codeception/SuiteManager.php:162
/var/www/html/project/vendor/codeception/base/src/Codeception/Codecept.php:209
/var/www/html/project/vendor/codeception/base/src/Codeception/Codecept.php:178
/var/www/html/project/vendor/codeception/base/src/Codeception/Command/Run.php:281
/var/www/html/project/vendor/symfony/console/Command/Command.php:256
/var/www/html/project/vendor/symfony/console/Application.php:820
/var/www/html/project/vendor/symfony/console/Application.php:187
/var/www/html/project/vendor/symfony/console/Application.php:118
/var/www/html/project/vendor/codeception/base/src/Codeception/Application.php:103
/var/www/html/project/vendor/codeception/base/codecept:33

Provide test source code if related

       I->wantTo('ensure that the comments are being displayed');
        $post = $I->grabFixture('post')['published-user3-store1'];
        $I->login();

        /*-----------------------------------------------------------------------*/
        $I->amOnPage('oferta/'. $post['id'] .'/'. $post['slug']);
        $I->see($post['title'], 'h1');

        $I->expectTo('see that the post has comments');
        $I->see('1', 'dd.comments');
        $I->dontSee('Seja o primeiro a comentar.');
        $I->seeElement('#post-comments ol.comments');

        /*-----------------------------------------------------------------------*/
        $I->amGoingTo('check if a comment is being properly nestled');
        $post = $I->grabFixture('post')['published-user5-store1'];
        $I->amOnRoute('post/view', ['id'=>$post['id'], 'slug'=>$post['slug']]);
        $I->see($post['title'], 'h1');

If I change the first $I->amOnPage to $I->amOnRoute it gives me the error there. It was not happening on codeception 2.2.5

Details

  • Codeception version: 2.2.6
  • PHP Version: 7.0
  • Operating System: Ubuntu
  • Installation type: Composer
  • List of installed packages (composer show)
    behat/gherkin v4.4.4 Gherkin DSL parser for PHP 5.3
    bower-asset/bootstrap v3.3.7 The most popular front-end framework for ...
    bower-asset/devbridge-autocomplete v1.2.26 Autocomplete provides suggestions while y...
    bower-asset/jquery 2.2.4
    bower-asset/jquery-maskmoney 3.0.2
    bower-asset/jquery-timeago v1.5.3
    bower-asset/jquery.inputmask 3.2.7 jquery.inputmask is a jquery plugin which...
    bower-asset/js-cookie v2.1.3
    bower-asset/punycode v1.3.2
    bower-asset/pure v0.6.0 Use Pure's ridiculously tiny CSS to start...
    bower-asset/purecss-sass v0.6.0-patch1 Pure CSS framework by Yahoo, converted to...
    bower-asset/summernote v0.8.2
    bower-asset/typeahead.js v0.11.1
    bower-asset/yii2-pjax v2.0.6
    brummm/yii2summernote dev-master 8d2fc0e A easily installable summernote bundle wi...
    cebe/markdown 1.1.1 A super fast, highly extensible markdown ...
    codeception/base 2.2.6 BDD-style testing framework
    codeception/specify 0.4.5 BDD code blocks for PHPUnit and Codeception
    codeception/verify 0.3.2 BDD assertion library for PHPUnit
    doctrine/inflector v1.1.0 Common String Manipulations with regard t...
    doctrine/instantiator 1.0.5 A small, lightweight utility to instantia...
    ezyang/htmlpurifier v4.8.0 Standards compliant HTML filter written i...
    facebook/webdriver 1.2.0 A PHP client for WebDriver
    fortawesome/font-awesome v4.7.0 The iconic font and CSS framework
    fzaninotto/faker v1.6.0 Faker is a PHP library that generates fak...
    guzzlehttp/guzzle 6.2.2 Guzzle is a PHP HTTP client library
    guzzlehttp/promises 1.2.0 Guzzle promises library
    guzzlehttp/psr7 1.3.1 PSR-7 message implementation
    illuminate/cache v5.3.16 The Illuminate Cache package.
    illuminate/contracts v5.3.16 The Illuminate Contracts package.
    illuminate/filesystem v5.3.16 The Illuminate Filesystem package.
    illuminate/support v5.3.16 The Illuminate Support package.
    imagine/imagine v0.5.0 Image processing for PHP 5.3
    intervention/image 2.3.8 Image handling and manipulation library w...
    intervention/imagecache 2.3.3 Caching extension for the Intervention Im...
    jeremeamia/SuperClosure 2.2.0 Serialize Closure objects, including thei...
    kartik-v/php-date-formatter v1.3.3 A Javascript datetime formatting and mani...
    kartik-v/yii2-datecontrol dev-master c849e53 Date control module allowing separation o...
    kartik-v/yii2-krajee-base v1.8.7 Base library and foundation components fo...
    kartik-v/yii2-widget-datetimepicker v1.4.2 Enhanced Yii2 wrapper for the bootstrap d...
    myclabs/deep-copy 1.5.4 Create deep copies (clones) of your objects
    nesbot/carbon 1.21.0 A simple API extension for DateTime.
    nikic/php-parser v2.1.1 A PHP parser written in PHP
    paragonie/random_compat v2.0.3 PHP 5.x polyfill for random_bytes() and r...
    phpdocumentor/reflection-common 1.0 Common reflection classes used by phpdocu...
    phpdocumentor/reflection-docblock 3.1.1 With this component, a library can provid...
    phpdocumentor/type-resolver 0.2
    phpspec/php-diff v1.1.0 A comprehensive library for generating di...
    phpspec/prophecy v1.6.1 Highly opinionated mocking framework for ...
    phpunit/php-code-coverage 4.0.1 Library that provides collection, process...
    phpunit/php-file-iterator 1.4.1 FilterIterator implementation that filter...
    phpunit/php-text-template 1.2.1 Simple template engine.
    phpunit/php-timer 1.0.8 Utility class for timing
    phpunit/php-token-stream 1.4.8 Wrapper around PHP's tokenizer extension.
    phpunit/phpunit 5.6.2 The PHP Unit Testing framework.
    phpunit/phpunit-mock-objects 3.4.0 Mock Object library for PHPUnit
    psr/http-message 1.0.1 Common interface for HTTP messages
    psr/log 1.0.2 Common interface for logging libraries
    sebastian/code-unit-reverse-lookup 1.0.0 Looks up which function or method a line ...
    sebastian/comparator 1.2.0 Provides the functionality to compare PHP...
    sebastian/diff 1.4.1 Diff implementation
    sebastian/environment 1.3.8 Provides functionality to handle HHVM/PHP...
    sebastian/exporter 1.2.2 Provides the functionality to export PHP ...
    sebastian/global-state 1.1.1 Snapshotting of global state
    sebastian/object-enumerator 1.0.0 Traverses array structures and object gra...
    sebastian/recursion-context 1.0.2 Provides functionality to recursively pro...
    sebastian/resource-operations 1.0.0 Provides a list of PHP built-in functions...
    sebastian/version 2.0.0 Library that helps with managing the vers...
    swiftmailer/swiftmailer v5.4.3 Swiftmailer, free feature-rich PHP mailer
    symfony/browser-kit v3.1.6 Symfony BrowserKit Component
    symfony/console v3.1.6 Symfony Console Component
    symfony/css-selector v3.1.6 Symfony CssSelector Component
    symfony/debug v3.1.6 Symfony Debug Component
    symfony/dom-crawler v3.1.6 Symfony DomCrawler Component
    symfony/event-dispatcher v3.1.6 Symfony EventDispatcher Component
    symfony/finder v3.1.6 Symfony Finder Component
    symfony/polyfill-mbstring v1.2.0 Symfony polyfill for the Mbstring extension
    symfony/polyfill-php56 v1.2.0 Symfony polyfill backporting some PHP 5.6...
    symfony/polyfill-util v1.2.0 Symfony utilities for portability of PHP ...
    symfony/translation v3.1.6 Symfony Translation Component
    symfony/yaml v3.1.6 Symfony Yaml Component
    webmozart/assert 1.1.0 Assertions to validate method input/outpu...
    yiisoft/yii2 2.0.10 Yii PHP Framework Version 2
    yiisoft/yii2-authclient 2.1.1 External authentication via OAuth and Ope...
    yiisoft/yii2-bootstrap 2.0.6 The Twitter Bootstrap extension for the Y...
    yiisoft/yii2-composer 2.0.4 The composer plugin for Yii extension ins...
    yiisoft/yii2-debug 2.0.6 The debugger extension for the Yii framework
    yiisoft/yii2-faker 2.0.3 Fixture generator. The Faker integration ...
    yiisoft/yii2-gii 2.0.5 The Gii extension for the Yii framework
    yiisoft/yii2-httpclient 2.0.1 HTTP client extension for the Yii framework
    yiisoft/yii2-imagine 2.0.4 The Imagine integration for the Yii frame...
    yiisoft/yii2-swiftmailer 2.0.6 The SwiftMailer integration for the Yii f...
  • Suite configuration:

``` codeception.yml
namespace: frontendtests
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
modules:
config:
Db:
cleanup: true
Yii2:
configFile: 'config/test-local.php'
entryUrl: 'https://frontend.dev/index-test.php'
cleanup: true

``` functional.suite.yml
class_name: FunctionalTester
modules:
    enabled:
        - Asserts
        - Filesystem
        - Yii2:
            url: https://frontend.dev/index-test.php
            cleanup: true
    config:
        Db:
          cleanup: true
Yii

Most helpful comment

If anyone get here with the same problem:
It was caused by a double BEGIN TRANSACTION (one from Yii Module and another from my application). Yii Module configured with cleanup: true, works inside a transaction, so a ROLLBACK can be executed in the end and all de changes to the database are undone.
If your application uses transactions, use cleanup: false.

P.s.: edited because on the previous version of my comment it looked like it was a problem with codeception, but it is with Yii Module (It not happens with PhpBrowser, wich I ended getting back into)

P.s.2: My english is a little too bad, but I hope you get everything above

All 13 comments

Are you sure that the Yii2 application is configured correctly?
Looks like you are not.

Savepoint error comes from the app, not from codeception and doesn't depend on how the page is accessed. Yii isn't using savepoints (transactions) unless you do.

If anyone get here with the same problem:
It was caused by a double BEGIN TRANSACTION (one from Yii Module and another from my application). Yii Module configured with cleanup: true, works inside a transaction, so a ROLLBACK can be executed in the end and all de changes to the database are undone.
If your application uses transactions, use cleanup: false.

P.s.: edited because on the previous version of my comment it looked like it was a problem with codeception, but it is with Yii Module (It not happens with PhpBrowser, wich I ended getting back into)

P.s.2: My english is a little too bad, but I hope you get everything above

If your application uses transactions, use cleanup: false.

Where?

codeception.yml
functional.suite.yml
Wherever else you use Yii2 Module.
use:

modules: enabled: - Yii2: cleanup: false
(github markdown parser is eating the line breaks on the code)

It's default for Yii2, and I tried but doesn't help. https://github.com/Codeception/Codeception/pull/3522#issuecomment-259350659

The default is cleanup: true (http://codeception.com/docs/modules/Yii2#config).
Isn't your application using double transactions? Did you make the test without codeception (sorry if its a dumb question, but sometimes those dumb things are the worse to catch)

The default is cleanup: true

馃槙 I use master version and here
https://github.com/Codeception/Codeception/blob/master/src/Codeception/Module/Yii2.php#L97

Isn't your application using double transactions? Did you make the test without codeception

No. My code & tests worked "yesterday", but now I update my old structure of tests to the structure from https://github.com/yiisoft/yii2-app-advanced/pull/190 only.

my issue: https://github.com/Codeception/Codeception/issues/3715

Thanks @brummm for that:

github markdown parser is eating the line breaks on the code

https://github.com/Codeception/Codeception/issues/3715#issuecomment-259891570

Thanks @brummm for cleanup: false. I had to use that 'workaround' to make transactions usable when testing.

@githubjeka Please don't use master branch, it is always behind default branch (2.2) and it hasn't been updated for 4 months now.

There is also an alternate solution. If your tests uses methods with transactions, you can disable cleanup inside the test method at the beginning (or right before method with transaction) and enable it after test completion:

$this->getModule('Yii2')->_reconfigure(['cleanup' => false]);

I tested this in unit tests only, maybe access to the Yii module differs in acceptance.

I stumbled upon this after Codeception 3->4 and Yii2 module upgrade. cleanup was already set to false.
In order to make it work I had to add also transaction: false under the Yii2 module configurations.

Was this page helpful?
0 / 5 - 0 ratings