73 $this->mockIdentityMap = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\IdentityMap');
74 $this->mockQueryFactory = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryFactory');
75 $this->mockQuery = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
76 $this->mockQuerySettings = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
77 $this->mockQuery->expects($this->any())->method(
'getQuerySettings')->will($this->returnValue($this->mockQuerySettings));
78 $this->mockQueryFactory->expects($this->any())->method(
'create')->will($this->returnValue($this->mockQuery));
79 $this->mockBackend = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\BackendInterface');
80 $this->mockSession = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Session');
81 $this->mockPersistenceManager = $this->getMock(
'TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
82 $this->mockPersistenceManager->expects($this->any())->method(
'createQueryForType')->will($this->returnValue($this->mockQuery));
83 $this->mockObjectManager = $this->getMock(
'TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
84 $this->repository = $this->
getAccessibleMock(
'TYPO3\\CMS\\Extbase\\Persistence\\Repository', array(
'dummy'), array($this->mockObjectManager));
85 $this->repository->_set(
'persistenceManager', $this->mockPersistenceManager);
92 $this->assertTrue($this->repository instanceof \
TYPO3\CMS\Extbase\Persistence\RepositoryInterface);
102 $this->repository->_set(
'objectType',
'ExpectedType');
105 $this->repository->createQuery();
112 $orderings = array(
'foo' => \
TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING);
113 $mockQuery = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\QueryInterface');
114 $mockQuery->expects($this->once())->method(
'setOrderings')->with($orderings);
118 $this->repository->_set(
'objectType',
'ExpectedType');
120 $this->repository->setDefaultOrderings($orderings);
121 $this->repository->createQuery();
123 $this->repository->setDefaultOrderings(array());
124 $this->repository->createQuery();
131 $expectedResult = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\QueryResultInterface');
133 $mockQuery = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\QueryInterface');
134 $mockQuery->expects($this->once())->method(
'execute')->with()->will($this->returnValue($expectedResult));
136 $repository = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\Repository', array(
'createQuery'), array($this->mockObjectManager));
139 $this->assertSame($expectedResult,
$repository->findAll());
147 $object = new \stdClass();
149 $expectedResult = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\QueryResultInterface');
150 $expectedResult->expects($this->once())->method(
'getFirst')->will($this->returnValue($object));
152 $mockQuery = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\QueryInterface');
153 $mockQuery->expects($this->any())->method(
'getQuerySettings')->will($this->returnValue($this->mockQuerySettings));
155 $mockQuery->expects($this->once())->method(
'execute')->will($this->returnValue($expectedResult));
157 $session = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\Generic\Session');
158 $session->expects($this->once())->method(
'hasIdentifier')->will($this->returnValue(FALSE));
160 $repository = $this->
getAccessibleMock(
'TYPO3\CMS\Extbase\Persistence\Repository', array(
'createQuery'), array($this->mockObjectManager));
163 $this->assertSame($object,
$repository->findByIdentifier($identifier));
170 $object = new \stdClass();
174 $this->repository->_set(
'objectType', get_class($object));
175 $this->repository->add($object);
182 $object = new \stdClass();
186 $this->repository->_set(
'objectType', get_class($object));
187 $this->repository->remove($object);
194 $object = new \stdClass();
198 $this->repository->_set(
'objectType', get_class($object));
199 $this->repository->update($object);
206 $mockQueryResult = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\QueryResultInterface');
207 $mockQuery = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\QueryInterface');
208 $mockQuery->expects($this->once())->method(
'equals')->with(
'foo',
'bar')->will($this->returnValue(
'matchCriteria'));
209 $mockQuery->expects($this->once())->method(
'matching')->with(
'matchCriteria')->will($this->returnValue(
$mockQuery));
210 $mockQuery->expects($this->once())->method(
'execute')->with()->will($this->returnValue($mockQueryResult));
212 $repository = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\Repository', array(
'createQuery'), array($this->mockObjectManager));
215 $this->assertSame($mockQueryResult,
$repository->findByFoo(
'bar'));
222 $object = new \stdClass();
223 $mockQueryResult = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\QueryResultInterface');
224 $mockQueryResult->expects($this->once())->method(
'getFirst')->will($this->returnValue($object));
225 $mockQuery = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\QueryInterface');
226 $mockQuery->expects($this->once())->method(
'equals')->with(
'foo',
'bar')->will($this->returnValue(
'matchCriteria'));
227 $mockQuery->expects($this->once())->method(
'matching')->with(
'matchCriteria')->will($this->returnValue(
$mockQuery));
229 $mockQuery->expects($this->once())->method(
'execute')->will($this->returnValue($mockQueryResult));
231 $repository = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\Repository', array(
'createQuery'), array($this->mockObjectManager));
234 $this->assertSame($object,
$repository->findOneByFoo(
'bar'));
241 $mockQuery = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\QueryInterface');
242 $mockQueryResult = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\QueryResultInterface');
243 $mockQuery->expects($this->once())->method(
'equals')->with(
'foo',
'bar')->will($this->returnValue(
'matchCriteria'));
244 $mockQuery->expects($this->once())->method(
'matching')->with(
'matchCriteria')->will($this->returnValue(
$mockQuery));
245 $mockQuery->expects($this->once())->method(
'execute')->will($this->returnValue($mockQueryResult));
246 $mockQueryResult->expects($this->once())->method(
'count')->will($this->returnValue(2));
248 $repository = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\Repository', array(
'createQuery'), array($this->mockObjectManager));
251 $this->assertSame(2,
$repository->countByFoo(
'bar'));
259 $repository = $this->getMock(
'TYPO3\CMS\Extbase\Persistence\Repository', array(
'createQuery'), array($this->mockObjectManager));
268 $this->repository->_set(
'objectType',
'ExpectedObjectType');
269 $this->repository->add(
new \stdClass());
277 $this->repository->_set(
'objectType',
'ExpectedObjectType');
278 $this->repository->remove(
new \stdClass());
286 $repository->_set(
'objectType',
'ExpectedObjectType');
298 array(
'Tx_BlogExample_Domain_Repository_BlogRepository',
'Tx_BlogExample_Domain_Model_Blog'),
299 array(
'_Domain_Repository_Content_PageRepository',
'_Domain_Model_Content_Page'),
300 array(
'Tx_RepositoryExample_Domain_Repository_SomeModelRepository',
'Tx_RepositoryExample_Domain_Model_SomeModel'),
301 array(
'Tx_RepositoryExample_Domain_Repository_RepositoryRepository',
'Tx_RepositoryExample_Domain_Model_Repository'),
302 array(
'Tx_Repository_Domain_Repository_RepositoryRepository',
'Tx_Repository_Domain_Model_Repository')
313 $repositoryClassNameWithNS = __NAMESPACE__ .
'\\' . $repositoryClassName;
314 eval(
'namespace ' . __NAMESPACE__ .
'; class ' . $repositoryClassName .
' extends \\TYPO3\\CMS\\Extbase\\Persistence\\Repository { 315 protected function getRepositoryClassName() { 316 return \'' . $repositoryClassName .
'\';
318 public function _getObjectType() {
319 return $this->objectType;
322 $this->repository = new $repositoryClassNameWithNS($this->mockObjectManager); 323 $this->assertEquals($modelClassName, $this->repository->_getObjectType()); 329 public function createQueryReturnsQueryWithUnmodifiedDefaultQuerySettings() { 330 $this->mockQuery = new \TYPO3\CMS\Extbase\Persistence\Generic\Query('foo
'); 331 $mockDefaultQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface
'); 332 $this->repository->setDefaultQuerySettings($mockDefaultQuerySettings); 333 $query = $this->repository->createQuery(); 334 $instanceQuerySettings = $query->getQuerySettings(); 335 $this->assertEquals($mockDefaultQuerySettings, $instanceQuerySettings); 336 $this->assertNotSame($mockDefaultQuerySettings, $instanceQuerySettings); 342 public function findByUidReturnsResultOfGetObjectByIdentifierCall() { 344 $object = new \stdClass(); 346 $expectedResult = $object; 347 $repository->expects($this->once())->method('findByIdentifier
')->will($this->returnValue($object)); 348 $actualResult = $repository->findByUid($fakeUid); 349 $this->assertSame($expectedResult, $actualResult); 356 public function updateRejectsObjectsOfWrongType() { 357 $this->repository->_set('objectType
', 'Foo
'); 358 $this->repository->update(new \stdClass()); 364 public function magicCallMethodReturnsFirstArrayKeyInFindOneBySomethingIfQueryReturnsRawResult() { 365 $queryResultArray = array( 370 $this->mockQuery->expects($this->once())->method('equals
')->with('foo
', 'bar
')->will($this->returnValue('matchCriteria
')); 371 $this->mockQuery->expects($this->once())->method('matching
')->with('matchCriteria
')->will($this->returnValue($this->mockQuery)); 372 $this->mockQuery->expects($this->once())->method('setLimit
')->with(1)->will($this->returnValue($this->mockQuery)); 373 $this->mockQuery->expects($this->once())->method('execute
')->will($this->returnValue($queryResultArray)); 374 $this->assertSame(array('foo
' => 'bar
'), $this->repository->findOneByFoo('bar
')); 380 public function magicCallMethodReturnsNullInFindOneBySomethingIfQueryReturnsEmptyRawResult() { 381 $queryResultArray = array(); 382 $this->mockQuery->expects($this->once())->method('equals
')->with('foo
', 'bar
')->will($this->returnValue('matchCriteria
')); 383 $this->mockQuery->expects($this->once())->method('matching
')->with('matchCriteria
')->will($this->returnValue($this->mockQuery)); 384 $this->mockQuery->expects($this->once())->method('setLimit
')->with(1)->will($this->returnValue($this->mockQuery)); 385 $this->mockQuery->expects($this->once())->method('execute
')->will($this->returnValue($queryResultArray)); 386 $this->assertNull($this->repository->findOneByFoo('bar
'));
inject($target, $name, $dependency)
findByidentifierReturnsResultOfGetObjectByIdentifierCall()
abstractRepositoryImplementsRepositoryInterface()
magicCallMethodAcceptsCountBySomethingCallsAndExecutesAQueryWithThatCriteria()
magicCallMethodTriggersAnErrorIfUnknownMethodsAreCalled()
modelAndRepositoryClassNames()
magicCallMethodAcceptsFindOneBySomethingCallsAndExecutesAQueryWithThatCriteria()
createQuerySetsDefaultOrderingIfDefined()
magicCallMethodAcceptsFindBySomethingCallsAndExecutesAQueryWithThatCriteria()
updateDelegatesToPersistenceManager()
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
findAllCreatesQueryAndReturnsResultOfExecuteCall()
createQueryCallsPersistenceManagerWithExpectedClassName()
addDelegatesToPersistenceManager()
constructSetsObjectTypeFromClassName($repositoryClassName, $modelClassName)
removeDelegatesToPersistenceManager()