‪TYPO3CMS  9.5
AbstractRepositoryTest.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 use Doctrine\DBAL\Driver\Statement;
17 use Prophecy\Argument;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪AbstractRepositoryTest extends UnitTestCase
30 {
34  protected ‪$subject;
35 
36  protected function ‪createDatabaseMock()
37  {
38  $connectionProphet = $this->prophesize(Connection::class);
39  $connectionProphet->quoteIdentifier(Argument::cetera())->willReturnArgument(0);
40 
41  $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
42  $queryBuilderProphet->expr()->willReturn(
43  GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
44  );
45 
46  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
47  $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
48  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
49 
50  return $queryBuilderProphet;
51  }
52 
53  protected function ‪setUp()
54  {
55  $this->subject = $this->getMockForAbstractClass(AbstractRepository::class, [], '', false);
56  }
57 
61  public function ‪findByUidFailsIfUidIsString()
62  {
63  $this->expectException(\InvalidArgumentException::class);
64  $this->expectExceptionCode(1316779798);
65  $this->subject->findByUid('asdf');
66  }
67 
72  {
73  $statementProphet = $this->prophesize(Statement::class);
74  $statementProphet->fetch()->shouldBeCalled()->willReturn(['uid' => 123]);
75 
76  $queryBuilderProphet = $this->‪createDatabaseMock();
77  $queryBuilderProphet->select('*')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
78  $queryBuilderProphet->from('')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
79  $queryBuilderProphet->where(Argument::cetera())->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
80  $queryBuilderProphet->createNamedParameter(Argument::cetera())->willReturnArgument(0);
81  $queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
82 
83  $this->subject->findByUid('123');
84  }
85 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:33
‪TYPO3\CMS\Core\Resource\AbstractRepository
Definition: AbstractRepository.php:27
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository
Definition: AbstractRepositoryTest.php:2
‪TYPO3\CMS\Core\Database\Query\QueryBuilder
Definition: QueryBuilder.php:47
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository\AbstractRepositoryTest\findByUidAcceptsNumericUidInString
‪findByUidAcceptsNumericUidInString()
Definition: AbstractRepositoryTest.php:70
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository\AbstractRepositoryTest\$subject
‪AbstractRepository $subject
Definition: AbstractRepositoryTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository\AbstractRepositoryTest
Definition: AbstractRepositoryTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository\AbstractRepositoryTest\findByUidFailsIfUidIsString
‪findByUidFailsIfUidIsString()
Definition: AbstractRepositoryTest.php:60
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository\AbstractRepositoryTest\setUp
‪setUp()
Definition: AbstractRepositoryTest.php:52
‪TYPO3\CMS\Core\Tests\Unit\Resource\Repository\AbstractRepositoryTest\createDatabaseMock
‪createDatabaseMock()
Definition: AbstractRepositoryTest.php:35