I was trying to use the new amOnRoute.
Provide console output if related. Use
-vvvmode 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:
/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
composer show)``` 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
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.
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 withcleanup: true, works inside a transaction, so aROLLBACKcan 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