Closed DiscipleOfShinku closed 4 years ago
Are you sure that it isn't a bug of your application? Does it display expected text if tested manually?
Yes, in a browser all works as expected.
This test worked with Codeception 2.3.9.
Please run this test with --debug
and provide the output!
[Connecting To Db] {"config":{"populate":true,"cleanup":true,"reconnect":false,"waitlock":0,"dump":null,"populator":"mysql -u $user $dbname < tests/_data/dump.sql","dsn":"mysql:host=localhost;dbname=db_test","user":"root","password":null},"options":[]}
[Db] Connected to default db_test
[Db] Executing Populator: `mysql -u root db_test < tests/_data/dump.sql`
[Db] Populator Finished.
Functional Tests (13) ---------------------------------------------------------------------------------------------------------------------------------------------------
Modules: Yii2, Db
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
AdminCest: Edit admin credentials
Signature: AdminCest:editAdminCredentials
Test: tests/functional/AdminCest.php:editAdminCredentials
Scenario --
Destroying application
Starting application
[ConnectionWatcher] watching new connections
[Fixtures] Loading fixtures
[Fixtures] Done
[TransactionForcer] watching new connections
[Db] Executing Populator: `mysql -u root db_test < tests/_data/dump.sql`
[Db] Populator Finished.
I am logged in as 1
[application] 'yii\\web\\Application#1
(
// many lines here
)'
[yii\db\Connection::open] 'Opening DB connection: mysql:host=localhost;dbname=db_test'
[ConnectionWatcher] Connection opened!
[TransactionForcer] Connection opened!
[TransactionForcer] Transaction started for: mysql:host=localhost;dbname=db_test
[yii\web\Session::open] 'Session started'
[yii\web\User::login] 'User \'1\' logged in from with duration 0.'
I am on route "admin/edit?id=1"
[Request Headers] []
[Page] /admin/edit?id=1
[Response] 200
[Request Cookies] []
[Response Headers] {"content-type":["text/html; charset=UTF-8"]}
I submit form "#admin-form",{"User[username]":"test-edited","User[password]":"test-edited"}
[Uri] http://localhost/admin/edit?id=1
[Method] POST
[Parameters] {"User[username]":"test-edited","User[password]":"test-edited"}
[Request Headers] []
[Redirect with headers]Array
(
[location] => Array
(
[0] => http://localhost/admin/view?id=1
)
[content-type] => Array
(
[0] => text/html; charset=UTF-8
)
)
[Page] http://localhost/admin/edit?id=1
[Response] 302
[Request Cookies] []
[Response Headers] {"location":["http://localhost/admin/view?id=1"],"content-type":["text/html; charset=UTF-8"]}
[Redirecting to] http://localhost/admin/view?id=1
[Page] http://localhost/admin/view?id=1
[Response] 200
[Request Cookies] []
[Response Headers] {"content-type":["text/html; charset=UTF-8"]}
I see "Exit (test-edited)"
FAIL
[TransactionForcer] Transaction cancelled; all changes reverted.
[TransactionForcer] no longer watching new connections
Destroying application
[ConnectionWatcher] no longer watching new connections
[ConnectionWatcher] closing all (1) connections
Suite done, restoring $_SERVER to
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DEPRECATION: 'settings: bootstrap: _bootstrap.php' option is deprecated! Replace it with: 'bootstrap: _bootstrap.php' (not under settings section). See https://bit.ly/2YrRzVc
[Connecting To Db] {"config":{"populate":true,"cleanup":true,"reconnect":false,"waitlock":0,"dump":null,"populator":"mysql -u $user $dbname < tests/_data/dump.sql","dsn":"mysql:host=localhost;dbname=db_test","user":"root","password":null},"options":[]}
[Db] Connected to default db_test
[Db] Executing Populator: `mysql -u root db_test < tests/_data/dump.sql`
[Db] Populator Finished.
@SamMousa Debug output was provided, are you going to look at it again?
I'll put it in the list
I've taken a look and nothing stands out to me. If you feel this is a bug in codeception please provide a minimal test case, ideally as a PR for the test repo.
Sorry, I don't know about the test repo. Here is a minimal test case. It requires a DB and includes a migration for it.
@DiscipleOfShinku thanks for that, it explains a lot.
What is happening is a different issue. In Yii's functional test module we do not reset the whole application during a test. This allows you to inspect the application state after / before a request.
In your case, the User
component loads your identity on the first page load. (Since it is used there to render the header).
On the 2nd render, which happens after updating, the information is not reloaded since it is already available.
There is actually configuration that allows you to prevent this: https://codeception.com/docs/modules/Yii2#Config, look for the recreateComponents
option. Add the user
component to it and we'll make sure that it's reinitialized upon every request.
If you cannot get that to work, you could also try this hacky fix for debugging only:
public function _before(FunctionalTester $I)
{
$I->amLoggedInAs(1);
}
public function editAdminCredentials(FunctionalTester $I)
{
$I->amOnRoute('admin/edit?id=1');
$I->submitForm('#admin-form', [
'User[username]' => 'test-edited',
'User[password]' => 'test-edited',
]);
/**
* BEGIN UGLY HACK
* Calling this will force the user component to refresh it's data.
*/
$I->amLoggedInAs(1);
$I->amOnRoute('admin/edit?id=1');
/** END UGLY HACK */
$I->see('Exit (test-edited)');
}
Oh! I probably should have read this option's description several times. And there are two requests in that test.
recreateComponent: ['user']
fixed the test.
Thank you and sorry for the trouble.
What are you trying to achieve?
To test an entry editing.
tests/functional/AdminCest.php
What do you get instead?
I get old
Yii::$app->user->identity->username
and old breadcrumbs.tests/_output/AdminCest.editAdminCredentials.fail.html
controllers/AdminController.php
views/layout/main.php
views/admin/edit.php
views/admin/view.php
Details
composer show
) behat/gherkin v4.6.0 Gherkin DSL parser for PHP 5.3 bower-asset/bootstrap v3.4.1 bower-asset/inputmask 3.3.11 bower-asset/jquery 3.4.1bower-asset/jquery-ui 1.12.1 bower-asset/punycode v1.3.2 bower-asset/yii2-pjax 2.0.7.1 cebe/markdown 1.2.1 A super fast, highly extensible markdown parser for PHP codeception/codeception 4.0.1 BDD-style testing framework codeception/lib-asserts 1.10.1 Assertion methods used by Codeception core and Asserts module codeception/lib-innerbrowser 1.2.3 Parent library for all Codeception framework modules and PhpBrowser codeception/module-asserts 1.1.1 Codeception module containing various assertions codeception/module-db 1.0.1 WebDriver module for Codeception codeception/module-yii2 1.0.1 Codeception module for Yii2 framework codeception/phpunit-wrapper 8.1.1 PHPUnit classes used by Codeception codeception/specify 0.4.6 BDD code blocks for PHPUnit and Codeception codeception/stub 3.6.0 Flexible Stub wrapper for PHPUnit's Mock Builder codeception/verify 0.4.0 BDD assertion library for PHPUnit doctrine/instantiator 1.3.0 A small, lightweight utility to instantiate objects in PHP without invoking their constructors doctrine/lexer 1.2.0 PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers. egulias/email-validator 2.1.12 A library for validating emails against several RFCs ezyang/htmlpurifier v4.12.0 Standards compliant HTML filter written in PHP fortawesome/font-awesome 5.12.0 The iconic font, CSS, and SVG framework froala/wysiwyg-editor v2.9.5 A beautiful jQuery WYSIWYG HTML rich text editor. High performance and modern design make it easy to use for developers a... froala/yii2-froala-editor 2.9.5 A beautiful jQuery WYSIWYG HTML text editor based on HTML5 technology. Cross browser, with mobile support, high performan... fzaninotto/faker v1.9.1 Faker is a PHP library that generates fake data for you. guzzlehttp/psr7 1.6.1 PSR-7 message implementation that also provides common utility methods myclabs/deep-copy 1.9.4 Create deep copies (clones) of your objects opis/closure 3.5.1 A library that can be used to serialize closures (anonymous functions) and arbitrary objects. phar-io/manifest 1.0.3 Component for reading phar.io manifest information from a PHP Archive (PHAR) phar-io/version 2.0.1 Library for handling version information and constraints phpdocumentor/reflection-common 2.0.0 Common reflection classes used by phpdocumentor to reflect the code structure phpdocumentor/reflection-docblock 4.3.3 With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that i... phpdocumentor/type-resolver 1.0.1 A PSR-5 based resolver of Class names, Types and Structural Element Names phpspec/php-diff v1.1.0 A comprehensive library for generating differences between two hashable objects (strings or arrays). phpspec/prophecy 1.10.1 Highly opinionated mocking framework for PHP 5.3+ phpunit/php-code-coverage 7.0.10 Library that provides collection, processing, and rendering functionality for PHP code coverage information. phpunit/php-file-iterator 2.0.2 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.2 Utility class for timing phpunit/php-token-stream 3.1.1 Wrapper around PHP's tokenizer extension. phpunit/phpunit 8.5.1 The PHP Unit Testing framework. 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-message 1.0.1 Common interface for HTTP messages ralouphie/getallheaders 3.0.3 A polyfill for getallheaders. rmrevin/yii2-fontawesome 3.4.0 Asset Bundle for Yii2 with Font Awesome 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 referenced objects sebastian/object-reflector 1.1.1 Allows reflection of object attributes, including inherited and non-public ones 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 type system sebastian/version 2.0.1 Library that helps with managing the version number of Git-hosted PHP projects swiftmailer/swiftmailer v6.2.3 Swiftmailer, free feature-rich PHP mailer symfony/browser-kit v4.2.4 Symfony BrowserKit Component symfony/console v5.0.2 Symfony Console Component symfony/css-selector v5.0.2 Symfony CssSelector Component symfony/dom-crawler v4.4.2 Symfony DomCrawler Component symfony/event-dispatcher v5.0.2 Symfony EventDispatcher Component symfony/event-dispatcher-contracts v2.0.1 Generic abstractions related to dispatching event symfony/finder v5.0.2 Symfony Finder Component symfony/polyfill-ctype v1.13.1 Symfony polyfill for ctype functions symfony/polyfill-iconv v1.13.1 Symfony polyfill for the Iconv extension symfony/polyfill-intl-idn v1.13.1 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions symfony/polyfill-mbstring v1.13.1 Symfony polyfill for the Mbstring extension symfony/polyfill-php72 v1.13.1 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions symfony/polyfill-php73 v1.13.1 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions symfony/service-contracts v2.0.1 Generic abstractions related to writing services symfony/yaml v5.0.2 Symfony Yaml Component theseer/tokenizer 1.1.3 A small library for converting tokenized PHP source code into XML and potentially other formats webmozart/assert 1.6.0 Assertions to validate method input/output with nice error messages. yiisoft/yii2 2.0.31 Yii PHP Framework Version 2 yiisoft/yii2-bootstrap 2.0.10 The Twitter Bootstrap extension for the Yii framework yiisoft/yii2-composer 2.0.8 The composer plugin for Yii extension installer yiisoft/yii2-debug 2.1.12 The debugger extension for the Yii framework yiisoft/yii2-faker 2.0.4 Fixture generator. The Faker integration for the Yii framework. yiisoft/yii2-gii 2.1.3 The Gii extension for the Yii framework yiisoft/yii2-jui 2.0.7 The Jquery UI extension for the Yii framework yiisoft/yii2-swiftmailer 2.1.2 The SwiftMailer integration for the Yii framework