|
|
@@ -495,43 +495,22 @@ class ConnectionTest extends TestCase
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testCloseConnectionWithUncommittedTransaction()
|
|
|
+ public function testDestructorWithUncommittedTransaction()
|
|
|
{
|
|
|
$driver = $this->getMockFormDriver();
|
|
|
- $connection = $this->getMockBuilder('\Cake\Database\Connection')
|
|
|
- ->setMethods(['connect'])
|
|
|
- ->setConstructorArgs([['driver' => $driver]])
|
|
|
- ->getMock();
|
|
|
+ $connection = new Connection(['driver' => $driver]);
|
|
|
+ $connection->begin();
|
|
|
+ $this->assertTrue($connection->inTransaction());
|
|
|
|
|
|
- // The returned value of getMock() is referenced by TestCase,
|
|
|
- // so it's impossible(or difficult) to call __destruct() of it during the test.
|
|
|
- // Instead, use cloned object.
|
|
|
- $clonedConnection = clone $connection;
|
|
|
- $clonedConnection->begin();
|
|
|
- $this->assertTrue($clonedConnection->inTransaction());
|
|
|
-
|
|
|
- Log::setConfig('debug', [
|
|
|
- 'engine' => 'File',
|
|
|
- 'path' => LOGS,
|
|
|
- 'levels' => ['notice', 'info', 'debug'],
|
|
|
- 'file' => 'debug',
|
|
|
- ]);
|
|
|
- Log::setConfig('error', [
|
|
|
- 'engine' => 'File',
|
|
|
- 'path' => LOGS,
|
|
|
- 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'],
|
|
|
- 'file' => 'error',
|
|
|
- ]);
|
|
|
- $errorLogFile = LOGS . 'error.log';
|
|
|
- if (file_exists($errorLogFile)) {
|
|
|
- unlink($errorLogFile);
|
|
|
- }
|
|
|
+ $logger = $this->createMock('Psr\Log\AbstractLogger');
|
|
|
+ $logger->expects($this->once())
|
|
|
+ ->method('log')
|
|
|
+ ->with('warning', $this->stringContains('The connection is going to be closed'));
|
|
|
+
|
|
|
+ Log::setConfig('error', $logger);
|
|
|
|
|
|
- // a warning log will be generated by __destruct of Connection.
|
|
|
- unset($clonedConnection);
|
|
|
- $this->assertFileExists($errorLogFile);
|
|
|
- $logContent = file_get_contents($errorLogFile);
|
|
|
- $this->assertStringMatchesFormat('%AWarning: The connection is going to be closed but the transaction is still active.%A', $logContent);
|
|
|
+ // Destroy the connection
|
|
|
+ unset($connection);
|
|
|
}
|
|
|
|
|
|
/**
|