-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Yii2 rework, new PR same changes. #4894
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
Conversation
Docblock of a I want to ask you few things:
|
https://codeception.com/for/yii should be checked i.e. if everything there is still valid with these changes. |
The changes are mainly in the configuration:
In Yii2 the application is globally available via |
I still have to look into the different parts of a module (like |
@SamMousa could you put the changes into |
Will do tomorrow. |
@DavertMik I have added docs! |
CHANGELOG-2.4.md
Outdated
@@ -15,6 +15,7 @@ | |||
* More reliable application state before and during test execution | |||
* Fixtures method is now configurable | |||
* Subset of misconfigurations are now detected and create informative messages | |||
* Application no longer available via the `$module->app`, now you must use `\Yii::$app` everywhere |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Application is no longer available
* More reliable application state before and during test execution | ||
* Fixtures method is now configurable | ||
* Subset of misconfigurations are now detected and create informative messages | ||
* Application is no longer available via the `$module->app`, now you must use `\Yii::$app` everywhere |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a breaking change :(
Ok, got it. Thanks! |
@SamMousa please note that your changes break the app lifecycle. Currently I'm bootstraping the following code in my api modules:
The following tests does not work anymore:
|
Issue is here: #4910 |
The response object gets recreated but your bootstrap code is not run again; thus the event is not attached to the second response object... The problem here is what to do for any request that's not the first in a test. In your example not recreating the response object would make all requests in the test case return json. I can fix it for the first request, but not sure about the n-th request; any idea? |
It's a common case to add a custom event handlers to the request/response components via configuration or via module bootstrapping. You need to persist them. As for me - keeping the app state between different tests is a bad idea. Different modules could attach different behaviors, event listeners, configurations to the app components. Keeping them persistent could break everything in a large apps. |
I agree, but I'm not talking about different tests but different requests inside test cases:
The cause here is that there are multiple response objects and the second one won't have your bootstrapping code. How is your bootstrap code bootstrapped? It would work if you bound the event to the class or to the application. What would happen if any code creates a new response object? Whether bootstrapped or not, the assumption you make is that there's only one response object. |
We could of course store event handlers and reattach them when these 2 objects get recreated *-) |
We bootstrap the code is usual: in the
|
Okay I'll make a proposed fix in your bug report and add a test case
…On Tue, Apr 3, 2018, 08:19 Alexey Samoylov ***@***.***> wrote:
We bootstrap the code is usual: in the bootstrap section of the config.
Like
'bootstrap' => [ 'api_module1', 'api_module2' ]
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4894 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAhYzbXp4ByCpMaUoWWfs6403ic0Vky4ks5tkxQzgaJpZM4S_2lu>
.
|
Checked the code once again. We attach the event listeners |
Okay, both should work though. Of course the problem is that module only gets initialized once. Workaround would be to use application after request event. I'll post a fix later today |
@SamMousa how to configure mailer in single test now? old helper public function configureMailer()
{
/** @var \Codeception\Module\Yii2 $module */
$module = $this->getModule('Yii2');
/** @var \yii\base\Application $app */
$app = $module->app;
/** @var \Codeception\Lib\Connector\Yii2 $connector */
$connector = $module->client;
$connector::$mailer = $app->get('mailer');
} \Yii::$app->set('mailer', 'frontend\stub\MockMailer');
$I->configureMailer(); mock mailer: return fail on sending mail class MockMailer extends \Codeception\Lib\Connector\Yii2\TestMailer
{
protected function sendMessage($message)
{
return false;
}
} |
@bscheshirwork i'll get back to you |
@samdark @DavertMik please stop releasing BC breaks as bugfix. This PR completely changes the API of the involved classes and should have been tagged in 3.0.0. Semver is not a joke, I had to drop each and every multiple range version constraint described in composer doc because the projects you maintain just ignore completely https://semver.org/ |
@Slamdunk the issue here is that the public API was never clearly defined. If you would like to contribute something useful instead of complaints feel free to create tests at https://github.com/codeception/yii2-tests This way we can test changes to identify if they break BC before actually releasing something. |
API is always clearly defined: everything public and not signed as
Yeah, and the issue for that is?
That's the exact behaviour I expect from Semver. If you have not the resources to maintain multiple versions (as I don't have in the FOSS I maintain) it would be perfectly ok to bump frequently the major number.
Tests has no correlation to API (although are a fundamental step to decide where an API should be driven to); if you want to identify BC breaks there are simple tool like https://github.com/Roave/BackwardCompatibilityCheck to help you |
Does codeception even use semver at the moment? |
The tag names suggest so. |
Lol, I think the |
Of course is not, but Codeception uses composer to spread itself, and it is statistically near 100 the percentage of the users that, in a composer ecosystem, would consider |
Yet luckily there's very few that are so entitled as you are :) |
Usually we try to avoid introducing breaking changes in patch releases. |
@SamMousa I just want to pay your attention on changed behavior which I faced few days ago. So: Thanks for attention. |
Is this being worked on or is there a way for us to force close database connections? |
This needs more testing; I've tested it in a few of my production apps.
Also somewhere in the docs we should update the "contract" about application state:
Request
andResponse
component are reloaded.Request
orResponse
component.yii\db\Connection
and fire theAFTER_OPEN
event.Database handling (for transactions)
AFTER_OPEN
.Connection
object uses the same PDO object and thus has the same world view.