Skip to content

Commit 2f8d801

Browse files
SamMousasamdark
authored andcommitted
Manual app reset (#4928)
* Due to modules keeping references to the client, destructor is not a good place for clean up. Instead manually reset application in _after * Fix pdoCache never being filled * Improved garbage collection, fixes #4926
1 parent a10f2a0 commit 2f8d801

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/Codeception/Lib/Connector/Yii2.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public function resetApplication()
9696
\yii\base\Event::offAll();
9797
}
9898
Yii::setLogger(null);
99+
// This resolves an issue with database connections not closing properly.
100+
gc_collect_cycles();
99101
}
100102

101103
public function startApp()
@@ -284,16 +286,6 @@ protected function mockMailer(array $config)
284286
return $config;
285287
}
286288

287-
/**
288-
* A new client is created for every test, it is destroyed after every test.
289-
* @see InnerBrowser::_after()
290-
*
291-
*/
292-
public function __destruct()
293-
{
294-
$this->resetApplication();
295-
}
296-
297289
public function restart()
298290
{
299291
parent::restart();

src/Codeception/Module/Yii2.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@ public function _after(TestInterface $test)
358358
if ($this->client !== null && $this->client->getApplication()->has('session', true)) {
359359
$this->client->getApplication()->session->close();
360360
}
361+
362+
$this->client->resetApplication();
361363
parent::_after($test);
362364
}
363365

@@ -385,6 +387,8 @@ public function connectionOpenHandler(Event $event)
385387
*/
386388
if (isset($this->pdoCache[$key])) {
387389
$connection->pdo = $this->pdoCache[$key];
390+
} else {
391+
$this->pdoCache[$key] = $connection->pdo;
388392
}
389393

390394
if (isset($this->dsnCache[$connection->dsn])

0 commit comments

Comments
 (0)