TYPO3 CMS  TYPO3_8-7
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  */
24 
28 class AbstractRepositoryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
29 {
33  protected $subject;
34 
35  protected function createDatabaseMock()
36  {
37  $connectionProphet = $this->prophesize(Connection::class);
38  $connectionProphet->quoteIdentifier(Argument::cetera())->willReturnArgument(0);
39 
40  $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
41  $queryBuilderProphet->expr()->willReturn(
42  GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
43  );
44 
45  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
46  $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
47  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
48 
49  return $queryBuilderProphet;
50  }
51 
52  protected function setUp()
53  {
54  $this->subject = $this->getMockForAbstractClass(AbstractRepository::class, [], '', false);
55  }
56 
60  public function findByUidFailsIfUidIsString()
61  {
62  $this->expectException(\InvalidArgumentException::class);
63  $this->expectExceptionCode(1316779798);
64  $this->subject->findByUid('asdf');
65  }
66 
71  {
72  $statementProphet = $this->prophesize(Statement::class);
73  $statementProphet->fetch()->shouldBeCalled()->willReturn(['uid' => 123]);
74 
75  $queryBuilderProphet = $this->createDatabaseMock();
76  $queryBuilderProphet->select('*')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
77  $queryBuilderProphet->from('')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
78  $queryBuilderProphet->where(Argument::cetera())->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
79  $queryBuilderProphet->createNamedParameter(Argument::cetera())->willReturnArgument(0);
80  $queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
81 
82  $this->subject->findByUid('123');
83  }
84 }
static addInstance($className, $instance)
static makeInstance($className,... $constructorArguments)