PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/Unit/Persistence/Generic/SessionTest.php

https://github.com/christianjul/FLOW3-Composer
PHP | 611 lines | 415 code | 83 blank | 113 comment | 0 complexity | 8d684f0a512dec9809a2677d90d2932c MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. namespace TYPO3\FLOW3\Tests\Unit\Persistence\Generic;
  3. /* *
  4. * This script belongs to the FLOW3 framework. *
  5. * *
  6. * It is free software; you can redistribute it and/or modify it under *
  7. * the terms of the GNU Lesser General Public License, either version 3 *
  8. * of the License, or (at your option) any later version. *
  9. * *
  10. * The TYPO3 project - inspiring people to share! *
  11. * */
  12. /**
  13. * Testcase for the Persistence Session
  14. *
  15. */
  16. class SessionTest extends \TYPO3\FLOW3\Tests\UnitTestCase {
  17. /**
  18. * @test
  19. */
  20. public function objectRegisteredWithRegisterReconstitutedEntityCanBeRetrievedWithGetReconstitutedEntities() {
  21. $someObject = new \ArrayObject(array());
  22. $session = new \TYPO3\FLOW3\Persistence\Generic\Session();
  23. $session->registerReconstitutedEntity($someObject, array('identifier' => 'fakeUuid'));
  24. $ReconstitutedEntities = $session->getReconstitutedEntities();
  25. $this->assertTrue($ReconstitutedEntities->contains($someObject));
  26. }
  27. /**
  28. * @test
  29. */
  30. public function unregisterReconstitutedEntityRemovesObjectFromSession() {
  31. $someObject = new \ArrayObject(array());
  32. $session = new \TYPO3\FLOW3\Persistence\Generic\Session();
  33. $session->registerObject($someObject, 'fakeUuid');
  34. $session->registerReconstitutedEntity($someObject, array('identifier' => 'fakeUuid'));
  35. $session->unregisterReconstitutedEntity($someObject);
  36. $ReconstitutedEntities = $session->getReconstitutedEntities();
  37. $this->assertFalse($ReconstitutedEntities->contains($someObject));
  38. }
  39. /**
  40. * @test
  41. */
  42. public function hasObjectReturnsTrueForRegisteredObject() {
  43. $object1 = new \stdClass();
  44. $object2 = new \stdClass();
  45. $session = new \TYPO3\FLOW3\Persistence\Generic\Session();
  46. $session->registerObject($object1, 12345);
  47. $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
  48. $this->assertFalse($session->hasObject($object2), 'Session claims it does have unregistered object.');
  49. }
  50. /**
  51. * @test
  52. */
  53. public function hasIdentifierReturnsTrueForRegisteredObject() {
  54. $session = new \TYPO3\FLOW3\Persistence\Generic\Session();
  55. $session->registerObject(new \stdClass(), 12345);
  56. $this->assertTrue($session->hasIdentifier('12345'), 'Session claims it does not have registered object.');
  57. $this->assertFalse($session->hasIdentifier('67890'), 'Session claims it does have unregistered object.');
  58. }
  59. /**
  60. * @test
  61. */
  62. public function getIdentifierByObjectReturnsRegisteredUUIDForObject() {
  63. $object = new \stdClass();
  64. $session = new \TYPO3\FLOW3\Persistence\Generic\Session();
  65. $session->registerObject($object, 12345);
  66. $this->assertEquals($session->getIdentifierByObject($object), 12345, 'Did not get UUID registered for object.');
  67. }
  68. /**
  69. * @test
  70. */
  71. public function getObjectByIdentifierReturnsRegisteredObjectForUUID() {
  72. $object = new \stdClass();
  73. $session = new \TYPO3\FLOW3\Persistence\Generic\Session();
  74. $session->registerObject($object, 12345);
  75. $this->assertSame($session->getObjectByIdentifier('12345'), $object, 'Did not get object registered for UUID.');
  76. }
  77. /**
  78. * @test
  79. */
  80. public function unregisterObjectRemovesRegisteredObject() {
  81. $object1 = new \stdClass();
  82. $object2 = new \stdClass();
  83. $session = new \TYPO3\FLOW3\Persistence\Generic\Session();
  84. $session->registerObject($object1, 12345);
  85. $session->registerObject($object2, 67890);
  86. $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
  87. $this->assertTrue($session->hasIdentifier('12345'), 'Session claims it does not have registered object.');
  88. $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
  89. $this->assertTrue($session->hasIdentifier('67890'), 'Session claims it does not have registered object.');
  90. $session->unregisterObject($object1);
  91. $this->assertFalse($session->hasObject($object1), 'Session claims it does have unregistered object.');
  92. $this->assertFalse($session->hasIdentifier('12345'), 'Session claims it does not have registered object.');
  93. $this->assertTrue($session->hasObject($object2), 'Session claims it does not have registered object.');
  94. $this->assertTrue($session->hasIdentifier('67890'), 'Session claims it does not have registered object.');
  95. }
  96. /**
  97. * @test
  98. */
  99. public function newObjectsAreConsideredDirty() {
  100. $session = new \TYPO3\FLOW3\Persistence\Generic\Session();
  101. $this->assertTrue($session->isDirty(new \stdClass(), 'foo'));
  102. }
  103. /**
  104. * @test
  105. */
  106. public function isDirtyReturnsTrueForUnregisteredReconstitutedEntities() {
  107. $session = $this->getMock('TYPO3\FLOW3\Persistence\Generic\Session', array('isReconstitutedEntity'));
  108. $session->expects($this->once())->method('isReconstitutedEntity')->will($this->returnValue(FALSE));
  109. $this->assertTrue($session->isDirty(new \stdClass(), 'foo'));
  110. }
  111. /**
  112. * @test
  113. */
  114. public function isDirtyReturnsFalseForNullInBothCurrentAndCleanValue() {
  115. $className = 'Class' . md5(uniqid(mt_rand(), TRUE));
  116. eval('class ' . $className . ' { public $foo; }');
  117. $object = new $className();
  118. $session = $this->getMock('TYPO3\FLOW3\Persistence\Generic\Session', array('getIdentifierByObject'));
  119. $session->registerReconstitutedEntity($object, array('identifier' => 'fakeUuid'));
  120. $session->expects($this->once())->method('getIdentifierByObject')->will($this->returnValue('fakeUuid'));
  121. $this->assertFalse($session->isDirty($object, 'foo'));
  122. }
  123. /**
  124. * @test
  125. */
  126. public function isDirtyAsksIsPropertyDirtyForChangedLiterals() {
  127. $className = 'Class' . md5(uniqid(mt_rand(), TRUE));
  128. eval('class ' . $className . ' { public $foo; }');
  129. $object = new $className();
  130. $object->foo = 'different';
  131. $cleanData = array(
  132. 'identifier' => 'fakeUuid',
  133. 'properties' => array(
  134. 'foo' => array(
  135. 'type' => 'string',
  136. 'multivalue' => FALSE,
  137. 'value' => 'bar'
  138. )
  139. )
  140. );
  141. $session = $this->getMock('TYPO3\FLOW3\Persistence\Generic\Session', array('getIdentifierByObject', 'isSingleValuedPropertyDirty'));
  142. $session->registerReconstitutedEntity($object, $cleanData);
  143. $session->expects($this->once())->method('getIdentifierByObject')->will($this->returnValue('fakeUuid'));
  144. $session->expects($this->once())->method('isSingleValuedPropertyDirty')->with('string', 'bar', 'different')->will($this->returnValue(TRUE));
  145. $this->assertTrue($session->isDirty($object, 'foo'));
  146. }
  147. /**
  148. * @test
  149. */
  150. public function isDirtyReturnsFalseForUnactivatedLazyObjects() {
  151. $className = 'Class' . md5(uniqid(mt_rand(), TRUE));
  152. eval('class ' . $className . ' { public $foo; }');
  153. $object = new $className();
  154. $object->FLOW3_Persistence_LazyLoadingObject_thawProperties = 'dummy';
  155. $session = $this->getMock('TYPO3\FLOW3\Persistence\Generic\Session', array('dummy'));
  156. $session->registerReconstitutedEntity($object, array('identifier' => 'fakeUuid'));
  157. $this->assertFalse($session->isDirty($object, 'foo'));
  158. }
  159. /**
  160. * @test
  161. */
  162. public function isDirtyReturnsTrueForTraversablesWhoseCountDiffers() {
  163. $className = 'Class' . md5(uniqid(mt_rand(), TRUE));
  164. eval('class ' . $className . ' { public $foo; }');
  165. $object = new $className();
  166. $object->foo = array('foo', 'bar', 'baz');
  167. $cleanData = array(
  168. 'identifier' => 'fakeUuid',
  169. 'properties' => array(
  170. 'foo' => array(
  171. 'type' => 'string',
  172. 'multivalue' => TRUE,
  173. 'value' => array(array(), array())
  174. )
  175. )
  176. );
  177. $session = $this->getMock('TYPO3\FLOW3\Persistence\Generic\Session', array('getIdentifierByObject'));
  178. $session->registerReconstitutedEntity($object, $cleanData);
  179. $session->expects($this->once())->method('getIdentifierByObject')->will($this->returnValue('fakeUuid'));
  180. $this->assertTrue($session->isDirty($object, 'foo'));
  181. }
  182. /**
  183. * @test
  184. */
  185. public function isDirtyReturnsTrueForNestedArrayWhoseCountDiffers() {
  186. $className = 'Class' . md5(uniqid(mt_rand(), TRUE));
  187. eval('class ' . $className . ' { public $foo; }');
  188. $object = new $className();
  189. $object->foo = array('foo', array('bar', 'baz'));
  190. $cleanData = array(
  191. 'identifier' => 'fakeUuid',
  192. 'properties' => array(
  193. 'foo' => array(
  194. 'type' => 'string',
  195. 'multivalue' => TRUE,
  196. 'value' => array(
  197. array('type' => 'string', 'index' => 0, 'value' => 'foo'),
  198. array(
  199. 'type' => 'array',
  200. 'index' => 1,
  201. 'value' => array('type' => 'string', 'index' => 0, 'value' => 'bar'),
  202. )
  203. )
  204. )
  205. )
  206. );
  207. $session = $this->getMock('TYPO3\FLOW3\Persistence\Generic\Session', array('getIdentifierByObject'));
  208. $session->registerReconstitutedEntity($object, $cleanData);
  209. $session->expects($this->once())->method('getIdentifierByObject')->will($this->returnValue('fakeUuid'));
  210. $this->assertTrue($session->isDirty($object, 'foo'));
  211. }
  212. /**
  213. * @test
  214. */
  215. public function isDirtyReturnsTrueForSplObjectStorageWhoseContainedObjectsDiffer() {
  216. $object = new \stdClass();
  217. $object->FLOW3_Persistence_Identifier = 'dirtyUuid';
  218. $splObjectStorage = new \SplObjectStorage();
  219. $splObjectStorage->attach($object);
  220. $className = 'Class' . md5(uniqid(mt_rand(), TRUE));
  221. eval('class ' . $className . ' { public $splObjectStorage; }');
  222. $parent = new $className();
  223. $parent->splObjectStorage = $splObjectStorage;
  224. $cleanData = array(
  225. 'identifier' => 'fakeUuid',
  226. 'properties' => array(
  227. 'splObjectStorage' => array(
  228. 'type' => 'SplObjectStorage',
  229. 'multivalue' => TRUE,
  230. 'value' => array(
  231. array(
  232. 'value' => array('identifier' => 'cleanUuid')
  233. )
  234. )
  235. )
  236. )
  237. );
  238. $session = $this->getMock('TYPO3\FLOW3\Persistence\Generic\Session', array('getIdentifierByObject'));
  239. $session->registerReconstitutedEntity($parent, $cleanData);
  240. $session->expects($this->atLeastOnce())->method('getIdentifierByObject')->will($this->returnValue('fakeUuid'));
  241. $this->assertTrue($session->isDirty($parent, 'splObjectStorage'));
  242. }
  243. /**
  244. * @test
  245. */
  246. public function isDirtyReturnsTrueForArraysWhoseContainedObjectsDiffer() {
  247. $object = new \stdClass();
  248. $object->FLOW3_Persistence_Identifier = 'dirtyUuid';
  249. $array = array();
  250. $array[] = $object;
  251. $className = 'Class' . md5(uniqid(mt_rand(), TRUE));
  252. eval('class ' . $className . ' { public $array; }');
  253. $parent = new $className();
  254. $parent->array = $array;
  255. $cleanData = array(
  256. 'identifier' => 'fakeUuid',
  257. 'properties' => array(
  258. 'array' => array(
  259. 'type' => 'array',
  260. 'multivalue' => TRUE,
  261. 'value' => array(
  262. array(
  263. 'type' => 'Some\Object',
  264. 'index' => 0,
  265. 'value' => array('identifier' => 'cleanUuid')
  266. )
  267. )
  268. )
  269. )
  270. );
  271. $session = $this->getMock('TYPO3\FLOW3\Persistence\Generic\Session', array('getIdentifierByObject', 'isSingleValuedPropertyDirty'));
  272. $session->registerReconstitutedEntity($parent, $cleanData);
  273. $session->expects($this->once())->method('getIdentifierByObject')->will($this->returnValue('fakeUuid'));
  274. $session->expects($this->once())->method('isSingleValuedPropertyDirty')->will($this->returnValue(TRUE));
  275. $this->assertTrue($session->isDirty($parent, 'array'));
  276. }
  277. /**
  278. * @test
  279. */
  280. public function isDirtyReturnsFalseForCleanArrays() {
  281. $object = new \stdClass();
  282. $object->FLOW3_Persistence_Identifier = 'cleanHash';
  283. $array = array();
  284. $array[] = $object;
  285. $className = 'Class' . md5(uniqid(mt_rand(), TRUE));
  286. eval('class ' . $className . ' { public $array; }');
  287. $parent = new $className();
  288. $parent->array = $array;
  289. $cleanData = array(
  290. 'identifier' => 'fakeUuid',
  291. 'properties' => array(
  292. 'array' => array(
  293. 'type' => 'array',
  294. 'multivalue' => TRUE,
  295. 'value' => array(
  296. array(
  297. 'type' => 'Some\Object',
  298. 'index' => 0,
  299. 'value' => array('identifier' => 'cleanHash')
  300. )
  301. )
  302. )
  303. )
  304. );
  305. $session = $this->getMock('TYPO3\FLOW3\Persistence\Generic\Session', array('getIdentifierByObject', 'isSingleValuedPropertyDirty'));
  306. $session->registerReconstitutedEntity($parent, $cleanData);
  307. $session->expects($this->once())->method('getIdentifierByObject')->will($this->returnValue('fakeUuid'));
  308. $session->expects($this->once())->method('isSingleValuedPropertyDirty')->with('Some\Object', array('identifier' => 'cleanHash'), $object)->will($this->returnValue(FALSE));
  309. $this->assertFalse($session->isDirty($parent, 'array'));
  310. }
  311. /**
  312. * @test
  313. */
  314. public function isDirtyReturnsFalseForCleanNestedArrays() {
  315. $object = new \stdClass();
  316. $object->FLOW3_Persistence_Identifier = 'cleanHash';
  317. $array = array(array($object));
  318. $className = 'Class' . md5(uniqid(mt_rand(), TRUE));
  319. eval('class ' . $className . ' { public $array; }');
  320. $parent = new $className();
  321. $parent->array = $array;
  322. $cleanData = array(
  323. 'identifier' => 'fakeUuid',
  324. 'properties' => array(
  325. 'array' => array(
  326. 'type' => 'array',
  327. 'multivalue' => TRUE,
  328. 'value' => array(
  329. array(
  330. 'type' => 'array',
  331. 'index' => 0,
  332. 'value' => array(
  333. array(
  334. 'type' => 'Some\Object',
  335. 'index' => 0,
  336. 'value' => array('identifier' => 'cleanHash')
  337. ),
  338. )
  339. )
  340. )
  341. )
  342. )
  343. );
  344. $session = $this->getMock('TYPO3\FLOW3\Persistence\Generic\Session', array('getIdentifierByObject', 'isSingleValuedPropertyDirty'));
  345. $session->registerReconstitutedEntity($parent, $cleanData);
  346. $session->expects($this->once())->method('getIdentifierByObject')->will($this->returnValue('fakeUuid'));
  347. $session->expects($this->once())->method('isSingleValuedPropertyDirty')->will($this->returnValue(FALSE));
  348. $this->assertFalse($session->isDirty($parent, 'array'));
  349. }
  350. /**
  351. * @test
  352. */
  353. public function isDirtyReturnsTrueForArraysWithNewMembers() {
  354. $object = new \stdClass();
  355. $object->FLOW3_Persistence_Identifier = 'dirtyUuid';
  356. $array = array();
  357. $array[] = $object;
  358. $className = 'Class' . md5(uniqid(mt_rand(), TRUE));
  359. eval('class ' . $className . ' { public $array; }');
  360. $parent = new $className();
  361. $parent->array = $array;
  362. $cleanData = array(
  363. 'identifier' => 'fakeUuid',
  364. 'properties' => array(
  365. 'array' => array(
  366. 'type' => 'array',
  367. 'multivalue' => TRUE,
  368. 'value' => array(
  369. array(
  370. 'type' => 'Some\Object',
  371. 'index' => 'new',
  372. 'value' => array('identifier' => 'cleanUuid')
  373. )
  374. )
  375. )
  376. )
  377. );
  378. $session = $this->getMock('TYPO3\FLOW3\Persistence\Generic\Session', array('getIdentifierByObject'));
  379. $session->registerReconstitutedEntity($parent, $cleanData);
  380. $session->expects($this->once())->method('getIdentifierByObject')->will($this->returnValue('fakeUuid'));
  381. $this->assertTrue($session->isDirty($parent, 'array'));
  382. }
  383. /**
  384. * Returns tuples of the form <type, current, clean, expected> for
  385. * isSingleValuedPropertyDirty()
  386. */
  387. public function propertyData() {
  388. $dateTime = new \DateTime();
  389. $entity = new \stdClass();
  390. $valueObject = new \stdClass();
  391. return array(
  392. array('string', 'foo', 'foo', FALSE),
  393. array('string', 'foo', 'bar', TRUE),
  394. array('boolean', TRUE, TRUE, FALSE),
  395. array('boolean', TRUE, FALSE, TRUE),
  396. array('float', 1.2, 1.2, FALSE),
  397. array('float', 1.2, 1.3, TRUE),
  398. array('integer', 10, 10, FALSE),
  399. array('integer', 10, 12, TRUE),
  400. array('Some\Entity', $entity, array('identifier' => NULL), FALSE),
  401. array('Some\Entity', $entity, array('identifier' => 'dirtyUuid'), TRUE),
  402. array('Some\ValueObject', $valueObject, array('identifier' => NULL), FALSE),
  403. array('Some\ValueObject', $valueObject, array('identifier' => 'dirtyHash'), TRUE),
  404. array('DateTime', $dateTime, $dateTime->getTimestamp(), FALSE),
  405. array('DateTime', $dateTime, $dateTime->getTimestamp()+1, TRUE),
  406. );
  407. }
  408. /**
  409. * @test
  410. * @dataProvider propertyData
  411. */
  412. public function isSingleValuedPropertyDirtyWorksAsExpected($type, $current, $clean, $expected) {
  413. $session = $this->getMock($this->buildAccessibleProxy('TYPO3\FLOW3\Persistence\Generic\Session'), array('getIdentifierByObject'));
  414. $this->assertEquals($session->_call('isSingleValuedPropertyDirty', $type, $clean, $current), $expected);
  415. }
  416. /**
  417. * @test
  418. */
  419. public function getCleanStateOfPropertyReturnsNullIfPropertyWasNotInObjectData() {
  420. $entity = new \stdClass();
  421. $reconstitutedEntitiesData = array(
  422. 'abc' => array(
  423. 'properties' => array(
  424. 'foo' => array('type' => 'string')
  425. )
  426. )
  427. );
  428. $session = $this->getAccessibleMock('TYPO3\FLOW3\Persistence\Generic\Session', array('isReconstitutedEntity', 'getIdentifierByObject'));
  429. $session->_set('reconstitutedEntitiesData', $reconstitutedEntitiesData);
  430. $session->expects($this->any())->method('isReconstitutedEntity')->with($entity)->will($this->returnValue(TRUE));
  431. $session->expects($this->any())->method('getIdentifierByObject')->with($entity)->will($this->returnValue('abc'));
  432. $state = $session->getCleanStateOfProperty($entity, 'bar');
  433. $this->assertNull($state);
  434. }
  435. /**
  436. * @test
  437. */
  438. public function getCleanStateOfPropertyReturnsNullIfObjectWasNotReconstituted() {
  439. $entity = new \stdClass();
  440. $session = $this->getAccessibleMock('TYPO3\FLOW3\Persistence\Generic\Session', array('isReconstitutedEntity'));
  441. $session->expects($this->any())->method('isReconstitutedEntity')->with($entity)->will($this->returnValue(FALSE));
  442. $state = $session->getCleanStateOfProperty($entity, 'bar');
  443. $this->assertNull($state);
  444. }
  445. /**
  446. * @test
  447. */
  448. public function getCleanStateOfPropertyReturnsPropertyData() {
  449. $entity = new \stdClass();
  450. $reconstitutedEntitiesData = array(
  451. 'abc' => array(
  452. 'properties' => array(
  453. 'foo' => array('type' => 'string')
  454. )
  455. )
  456. );
  457. $session = $this->getAccessibleMock('TYPO3\FLOW3\Persistence\Generic\Session', array('isReconstitutedEntity', 'getIdentifierByObject'));
  458. $session->_set('reconstitutedEntitiesData', $reconstitutedEntitiesData);
  459. $session->expects($this->any())->method('isReconstitutedEntity')->with($entity)->will($this->returnValue(TRUE));
  460. $session->expects($this->any())->method('getIdentifierByObject')->with($entity)->will($this->returnValue('abc'));
  461. $state = $session->getCleanStateOfProperty($entity, 'foo');
  462. $this->assertEquals(array('type' => 'string'), $state);
  463. }
  464. /**
  465. * Does it return the UUID for an object know to the identity map?
  466. *
  467. * @test
  468. */
  469. public function getIdentifierByObjectReturnsUUIDForKnownObject() {
  470. $knownObject = $this->getMock('TYPO3\FLOW3\Aop\ProxyInterface');
  471. $fakeUUID = '123-456';
  472. $session = new \TYPO3\FLOW3\Persistence\Generic\Session();
  473. $session->registerObject($knownObject, $fakeUUID);
  474. $this->assertEquals($fakeUUID, $session->getIdentifierByObject($knownObject));
  475. }
  476. /**
  477. * Does it return the UUID for an AOP proxy not being in the identity map
  478. * but having FLOW3_Persistence_Identifier?
  479. *
  480. * @test
  481. */
  482. public function getIdentifierByObjectReturnsUuidForObjectBeingAOPProxy() {
  483. $knownObject = $this->getMock('TYPO3\FLOW3\Aop\ProxyInterface');
  484. $knownObject->FLOW3_Persistence_Identifier = 'fakeUuid';
  485. $session = new \TYPO3\FLOW3\Persistence\Generic\Session();
  486. $session->injectReflectionService($this->getMock('TYPO3\FLOW3\Reflection\ReflectionService'));
  487. $this->assertEquals('fakeUuid', $session->getIdentifierByObject($knownObject));
  488. }
  489. /**
  490. * Does it return the value object hash for an AOP proxy not being in the
  491. * identity map but having FLOW3_Persistence_Identifier?
  492. *
  493. * @test
  494. */
  495. public function getIdentifierByObjectReturnsHashForObjectBeingAOPProxy() {
  496. $knownObject = $this->getMock('TYPO3\FLOW3\Aop\ProxyInterface');
  497. $knownObject->FLOW3_Persistence_Identifier = 'fakeHash';
  498. $session = new \TYPO3\FLOW3\Persistence\Generic\Session();
  499. $session->injectReflectionService($this->getMock('TYPO3\FLOW3\Reflection\ReflectionService'));
  500. $this->assertEquals('fakeHash', $session->getIdentifierByObject($knownObject));
  501. }
  502. /**
  503. * Does it return NULL for an AOP proxy not being in the identity map and
  504. * not having FLOW3_Persistence_Identifier?
  505. *
  506. * @test
  507. */
  508. public function getIdentifierByObjectReturnsNullForUnknownObjectBeingAOPProxy() {
  509. $unknownObject = $this->getMock('TYPO3\FLOW3\Aop\ProxyInterface');
  510. $session = new \TYPO3\FLOW3\Persistence\Generic\Session();
  511. $session->injectReflectionService($this->getMock('TYPO3\FLOW3\Reflection\ReflectionService'));
  512. $this->assertNull($session->getIdentifierByObject($unknownObject));
  513. }
  514. /**
  515. * @test
  516. */
  517. public function getIdentifierByObjectReturnsValueOfPropertyTaggedWithId() {
  518. $object = $this->getMock('TYPO3\FLOW3\Aop\ProxyInterface');
  519. $object->FLOW3_Persistence_Identifier = 'randomlyGeneratedUuid';
  520. $object->customId = 'customId';
  521. $mockReflectionService = $this->getMock('TYPO3\FLOW3\Reflection\ReflectionService');
  522. $mockReflectionService->expects($this->any())->method('getPropertyNamesByTag')->will($this->returnValue(array('customId')));
  523. $session = new \TYPO3\FLOW3\Persistence\Generic\Session();
  524. $session->injectReflectionService($mockReflectionService);
  525. $this->assertEquals('customId', $session->getIdentifierByObject($object));
  526. }
  527. }
  528. ?>