‪TYPO3CMS  10.4
AbstractRepositoryTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Doctrine\DBAL\Driver\Statement;
19 use Prophecy\Argument;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪AbstractRepositoryTest extends UnitTestCase
32 {
36  protected ‪$subject;
37 
38  protected function ‪createDatabaseMock()
39  {
40  $connectionProphet = $this->prophesize(Connection::class);
41  $connectionProphet->quoteIdentifier(Argument::cetera())->willReturnArgument(0);
42 
43  $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
44  $queryBuilderProphet->expr()->willReturn(
45  GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
46  );
47 
48  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
49  $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
50  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
51 
52  return $queryBuilderProphet;
53  }
54 
55  protected function ‪setUp(): void
56  {
57  parent::setUp();
58  $this->subject = $this->getMockForAbstractClass(AbstractRepository::class, [], '', false);
59  }
60 
64  public function ‪findByUidFailsIfUidIsString()
65  {
66  $this->expectException(\InvalidArgumentException::class);
67  $this->expectExceptionCode(1316779798);
68  $this->subject->findByUid('asdf');
69  }
70 
75  {
76  $statementProphet = $this->prophesize(Statement::class);
77  $statementProphet->fetch()->shouldBeCalled()->willReturn(['uid' => 123]);
78 
79  $queryBuilderProphet = $this->‪createDatabaseMock();
80  $queryBuilderProphet->select('*')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
81  $queryBuilderProphet->from('')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
82  $queryBuilderProphet->where(Argument::cetera())->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
83  $queryBuilderProphet->createNamedParameter(Argument::cetera())->willReturnArgument(0);
84  $queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
85 
86  $this->subject->findByUid('123');
87  }
88 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:35
‪TYPO3\CMS\Core\Resource\AbstractRepository
Definition: AbstractRepository.php:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository
Definition: AbstractRepositoryTest.php:16
‪TYPO3\CMS\Core\Database\Query\QueryBuilder
Definition: QueryBuilder.php:52
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository\AbstractRepositoryTest\findByUidAcceptsNumericUidInString
‪findByUidAcceptsNumericUidInString()
Definition: AbstractRepositoryTest.php:73
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:36
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository\AbstractRepositoryTest\$subject
‪AbstractRepository $subject
Definition: AbstractRepositoryTest.php:35
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository\AbstractRepositoryTest
Definition: AbstractRepositoryTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository\AbstractRepositoryTest\findByUidFailsIfUidIsString
‪findByUidFailsIfUidIsString()
Definition: AbstractRepositoryTest.php:63
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository\AbstractRepositoryTest\setUp
‪setUp()
Definition: AbstractRepositoryTest.php:54
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository\AbstractRepositoryTest\createDatabaseMock
‪createDatabaseMock()
Definition: AbstractRepositoryTest.php:37