-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Unbind specific event handler instead of all class level events when … #5045
Conversation
|
||
public function __construct() | ||
{ | ||
$this->handler = function(Event $event) { |
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.
Expected 1 space after FUNCTION keyword; 0 found
{ | ||
$count = count($this->connections); | ||
$this->debug("closing all ($count) connections"); | ||
foreach($this->connections as $connection) { |
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.
Expected 1 space after FOREACH keyword; 0 found
} | ||
codecept_debug("[$title] $message"); | ||
} | ||
} |
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.
Expected 1 newline at end of file; 0 found
<?php | ||
|
||
|
||
namespace Codeception\Lib\Connector\Yii2; |
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.
There must be one blank line after the namespace declaration
$this->pdoCache = []; | ||
$this->dsnCache = []; | ||
} | ||
} |
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.
Expected 1 newline at end of file; 0 found
@samdark This is ready for merge. After it has been merged I will also merge this one: Codeception/yii2-tests#2 which tests the proper closing of database connection in most (if not all) scenarios. |
Merged. Thanks! |
I can't explain this, there's a testcase for it that succeeds.. https://travis-ci.org/Codeception/yii2-tests/builds/397866937 |
Probably that test does not cover all cases. I do not know why, but on 2.4.0 and previous versions everything works fine. |
It worked fine in your specific case (single database component named
@roslov could you make a PR with a minimal test case where you can reproduce it? |
After this fix I can't run tests: Modules: Yii2, Asserts, \businessTest\Helper\Unit
--------------------------------------------------------------------------------------------------------------------------------------------------------
E AuthEmployeeTest: True handle
E AuthEmployeeTest: True handle (0.02s)
PHP Fatal error: Unc
Fatal error: Uncaught Error: Call to a member function stop() on null in \vendor\codeception\codeception\src\Codeception\Module\Yii2.php:346
Stack trace:
#0 vendor\codeception\codeception\src\Codeception\Subscriber\Module.php(66): Codeception\Module\Yii2->_after(Object(businessTest\unit\AuthEmployeeTest))
#1 vendor\symfony\event-dispatcher\EventDispatcher.php(212): Codeception\Subscriber\Module->after(Object(Codeception\Event\TestEvent), 'test.after', Object(Symfony\Component\EventDispatcher\EventDispatcher))
#2 vendor\symfony\event-dispatcher\EventDispatcher.php(44): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(Array, 'test.after', Object(Codeception\Event\TestEvent))
#3vendor\codeception\phpunit-wrapper\src\Listener.php(133): Symfony\Component\EventDispatcher\EventDispatcher->dispatch('test.after' in vendor\codeception\codeception\src\Codeception\Module\Yii2.php:346 |
That's weird; it is created on |
This PR refactors database connection handling for the Yii2 module.
It is fully backwards compatible with the exception of broken stuff that is now fixed.
Database connections should now always be closed after tests no matter how you have opened them or who is holding references to them.