‪TYPO3CMS  9.5
DatabaseWriterTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use Prophecy\Argument;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪DatabaseWriterTest extends UnitTestCase
27 {
32  {
33  $logTable = $this->getUniqueId('logtable_');
35  $subject = $this->getMockBuilder(\‪TYPO3\CMS\Core\Log\Writer\DatabaseWriter::class)
36  ->setMethods(['dummy'])
37  ->disableOriginalConstructor()
38  ->getMock();
39  $subject->setLogTable($logTable);
40  $this->assertSame($logTable, $subject->getLogTable());
41  }
42 
47  {
48  $logTable = $this->getUniqueId('logtable_');
49 
50  $connectionProphecy = $this->prophesize(Connection::class);
51  $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
52  $connectionPoolProphecy->getConnectionForTable(Argument::cetera())->willReturn($connectionProphecy->reveal());
53 
54  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
55  $logRecordMock = $this->createMock(\‪TYPO3\CMS\Core\Log\LogRecord::class);
56  $subject = $this->getMockBuilder(\‪TYPO3\CMS\Core\Log\Writer\DatabaseWriter::class)
57  ->setMethods(['dummy'])
58  ->disableOriginalConstructor()
59  ->getMock();
60  $subject->setLogTable($logTable);
61 
62  // $logTable should end up as first insert argument
63  $connectionProphecy->insert($logTable, Argument::cetera())->willReturn(1);
64 
65  $subject->writeLog($logRecordMock);
66  }
67 }
‪TYPO3\CMS\Core\Tests\Unit\Log\Writer\DatabaseWriterTest\writeLogInsertsToSpecifiedTable
‪writeLogInsertsToSpecifiedTable()
Definition: DatabaseWriterTest.php:46
‪TYPO3
‪TYPO3\CMS\Core\Tests\Unit\Log\Writer\DatabaseWriterTest
Definition: DatabaseWriterTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Log\Writer\DatabaseWriterTest\getTableReturnsPreviouslySetTable
‪getTableReturnsPreviouslySetTable()
Definition: DatabaseWriterTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Log\Writer
Definition: AbstractWriterTest.php:2
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:31
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45