ExtraLazyCollectionTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional;
  3. use Doctrine\ORM\Mapping\ClassMetadataInfo;
  4. require_once __DIR__ . '/../../TestInit.php';
  5. /**
  6. * Description of ExtraLazyCollectionTest
  7. *
  8. * @author beberlei
  9. */
  10. class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
  11. {
  12. private $userId;
  13. private $groupId;
  14. private $articleId;
  15. public function setUp()
  16. {
  17. $this->useModelSet('cms');
  18. parent::setUp();
  19. $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
  20. $class->associationMappings['groups']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY;
  21. $class->associationMappings['articles']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY;
  22. $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup');
  23. $class->associationMappings['users']['fetch'] = ClassMetadataInfo::FETCH_EXTRA_LAZY;
  24. $this->loadFixture();
  25. }
  26. public function tearDown()
  27. {
  28. parent::tearDown();
  29. $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
  30. $class->associationMappings['groups']['fetch'] = ClassMetadataInfo::FETCH_LAZY;
  31. $class->associationMappings['articles']['fetch'] = ClassMetadataInfo::FETCH_LAZY;
  32. $class = $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsGroup');
  33. $class->associationMappings['users']['fetch'] = ClassMetadataInfo::FETCH_LAZY;
  34. }
  35. /**
  36. * @group DDC-546
  37. */
  38. public function testCountNotInitializesCollection()
  39. {
  40. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  41. $queryCount = $this->getCurrentQueryCount();
  42. $this->assertFalse($user->groups->isInitialized());
  43. $this->assertEquals(3, count($user->groups));
  44. $this->assertFalse($user->groups->isInitialized());
  45. foreach ($user->groups AS $group) { }
  46. $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount(), "Expecting two queries to be fired for count, then iteration.");
  47. }
  48. /**
  49. * @group DDC-546
  50. */
  51. public function testCountWhenNewEntityPresent()
  52. {
  53. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  54. $newGroup = new \Doctrine\Tests\Models\CMS\CmsGroup();
  55. $newGroup->name = "Test4";
  56. $user->addGroup($newGroup);
  57. $this->_em->persist($newGroup);
  58. $this->assertFalse($user->groups->isInitialized());
  59. $this->assertEquals(4, count($user->groups));
  60. $this->assertFalse($user->groups->isInitialized());
  61. }
  62. /**
  63. * @group DDC-546
  64. */
  65. public function testCountWhenInitialized()
  66. {
  67. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  68. $queryCount = $this->getCurrentQueryCount();
  69. foreach ($user->groups AS $group) { }
  70. $this->assertTrue($user->groups->isInitialized());
  71. $this->assertEquals(3, count($user->groups));
  72. $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Should only execute one query to initialize colleciton, no extra query for count() more.");
  73. }
  74. /**
  75. * @group DDC-546
  76. */
  77. public function testCountInverseCollection()
  78. {
  79. $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId);
  80. $this->assertFalse($group->users->isInitialized(), "Pre-Condition");
  81. $this->assertEquals(4, count($group->users));
  82. $this->assertFalse($group->users->isInitialized(), "Extra Lazy collection should not be initialized by counting the collection.");
  83. }
  84. /**
  85. * @group DDC-546
  86. */
  87. public function testCountOneToMany()
  88. {
  89. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  90. $this->assertFalse($user->groups->isInitialized(), "Pre-Condition");
  91. $this->assertEquals(2, count($user->articles));
  92. }
  93. /**
  94. * @group DDC-546
  95. */
  96. public function testFullSlice()
  97. {
  98. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  99. $this->assertFalse($user->groups->isInitialized(), "Pre-Condition: Collection is not initialized.");
  100. $someGroups = $user->groups->slice(null);
  101. $this->assertEquals(3, count($someGroups));
  102. }
  103. /**
  104. * @group DDC-546
  105. */
  106. public function testSlice()
  107. {
  108. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  109. $this->assertFalse($user->groups->isInitialized(), "Pre-Condition: Collection is not initialized.");
  110. $queryCount = $this->getCurrentQueryCount();
  111. $someGroups = $user->groups->slice(0, 2);
  112. $this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsGroup', $someGroups);
  113. $this->assertEquals(2, count($someGroups));
  114. $this->assertFalse($user->groups->isInitialized(), "Slice should not initialize the collection if it wasn't before!");
  115. $otherGroup = $user->groups->slice(2, 1);
  116. $this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsGroup', $otherGroup);
  117. $this->assertEquals(1, count($otherGroup));
  118. $this->assertFalse($user->groups->isInitialized());
  119. foreach ($user->groups AS $group) { }
  120. $this->assertTrue($user->groups->isInitialized());
  121. $this->assertEquals(3, count($user->groups));
  122. $this->assertEquals($queryCount + 3, $this->getCurrentQueryCount());
  123. }
  124. /**
  125. * @group DDC-546
  126. */
  127. public function testSliceInitializedCollection()
  128. {
  129. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  130. $queryCount = $this->getCurrentQueryCount();
  131. foreach ($user->groups AS $group) { }
  132. $someGroups = $user->groups->slice(0, 2);
  133. $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
  134. $this->assertEquals(2, count($someGroups));
  135. $this->assertTrue($user->groups->contains($someGroups[0]));
  136. $this->assertTrue($user->groups->contains($someGroups[1]));
  137. }
  138. /**
  139. * @group DDC-546
  140. */
  141. public function testSliceInverseCollection()
  142. {
  143. $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId);
  144. $this->assertFalse($group->users->isInitialized(), "Pre-Condition");
  145. $queryCount = $this->getCurrentQueryCount();
  146. $someUsers = $group->users->slice(0, 2);
  147. $otherUsers = $group->users->slice(2, 2);
  148. $this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsUser', $someUsers);
  149. $this->assertContainsOnly('Doctrine\Tests\Models\CMS\CmsUser', $otherUsers);
  150. $this->assertEquals(2, count($someUsers));
  151. $this->assertEquals(2, count($otherUsers));
  152. // +2 queries executed by slice
  153. $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount(), "Slicing two parts should only execute two additional queries.");
  154. }
  155. /**
  156. * @group DDC-546
  157. */
  158. public function testSliceOneToMany()
  159. {
  160. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  161. $this->assertFalse($user->articles->isInitialized(), "Pre-Condition: Collection is not initialized.");
  162. $queryCount = $this->getCurrentQueryCount();
  163. $someArticle = $user->articles->slice(0, 1);
  164. $otherArticle = $user->articles->slice(1, 1);
  165. $this->assertEquals($queryCount + 2, $this->getCurrentQueryCount());
  166. }
  167. /**
  168. * @group DDC-546
  169. */
  170. public function testContainsOneToMany()
  171. {
  172. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  173. $this->assertFalse($user->articles->isInitialized(), "Pre-Condition: Collection is not initialized.");
  174. // Test One to Many existance retrieved from DB
  175. $article = $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId);
  176. $queryCount = $this->getCurrentQueryCount();
  177. $this->assertTrue($user->articles->contains($article));
  178. $this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
  179. $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
  180. // Test One to Many existance with state new
  181. $article = new \Doctrine\Tests\Models\CMS\CmsArticle();
  182. $article->topic = "Testnew";
  183. $article->text = "blub";
  184. $queryCount = $this->getCurrentQueryCount();
  185. $this->assertFalse($user->articles->contains($article));
  186. $this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Checking for contains of new entity should cause no query to be executed.");
  187. // Test One to Many existance with state clear
  188. $this->_em->persist($article);
  189. $this->_em->flush();
  190. $queryCount = $this->getCurrentQueryCount();
  191. $this->assertFalse($user->articles->contains($article));
  192. $this->assertEquals($queryCount+1, $this->getCurrentQueryCount(), "Checking for contains of persisted entity should cause one query to be executed.");
  193. $this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
  194. // Test One to Many existance with state managed
  195. $article = new \Doctrine\Tests\Models\CMS\CmsArticle();
  196. $article->topic = "How to not fail anymore on tests";
  197. $article->text = "That is simple! Just write more tests!";
  198. $this->_em->persist($article);
  199. $queryCount = $this->getCurrentQueryCount();
  200. $this->assertFalse($user->articles->contains($article));
  201. $this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Checking for contains of managed entity (but not persisted) should cause no query to be executed.");
  202. $this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
  203. }
  204. /**
  205. * @group DDC-546
  206. */
  207. public function testContainsManyToMany()
  208. {
  209. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  210. $this->assertFalse($user->groups->isInitialized(), "Pre-Condition: Collection is not initialized.");
  211. // Test Many to Many existance retrieved from DB
  212. $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId);
  213. $queryCount = $this->getCurrentQueryCount();
  214. $this->assertTrue($user->groups->contains($group));
  215. $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Checking for contains of managed entity should cause one query to be executed.");
  216. $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
  217. // Test Many to Many existance with state new
  218. $group = new \Doctrine\Tests\Models\CMS\CmsGroup();
  219. $group->name = "A New group!";
  220. $queryCount = $this->getCurrentQueryCount();
  221. $this->assertFalse($user->groups->contains($group));
  222. $this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Checking for contains of new entity should cause no query to be executed.");
  223. $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
  224. // Test Many to Many existance with state clear
  225. $this->_em->persist($group);
  226. $this->_em->flush();
  227. $queryCount = $this->getCurrentQueryCount();
  228. $this->assertFalse($user->groups->contains($group));
  229. $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Checking for contains of persisted entity should cause one query to be executed.");
  230. $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
  231. // Test Many to Many existance with state managed
  232. $group = new \Doctrine\Tests\Models\CMS\CmsGroup();
  233. $group->name = "My managed group";
  234. $this->_em->persist($group);
  235. $queryCount = $this->getCurrentQueryCount();
  236. $this->assertFalse($user->groups->contains($group));
  237. $this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Checking for contains of managed entity (but not persisted) should cause no query to be executed.");
  238. $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
  239. }
  240. /**
  241. * @group DDC-546
  242. */
  243. public function testContainsManyToManyInverse()
  244. {
  245. $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId);
  246. $this->assertFalse($group->users->isInitialized(), "Pre-Condition: Collection is not initialized.");
  247. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  248. $queryCount = $this->getCurrentQueryCount();
  249. $this->assertTrue($group->users->contains($user));
  250. $this->assertEquals($queryCount+1, $this->getCurrentQueryCount(), "Checking for contains of managed entity should cause one query to be executed.");
  251. $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
  252. $newUser = new \Doctrine\Tests\Models\CMS\CmsUser();
  253. $newUser->name = "A New group!";
  254. $queryCount = $this->getCurrentQueryCount();
  255. $this->assertFalse($group->users->contains($newUser));
  256. $this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Checking for contains of new entity should cause no query to be executed.");
  257. $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
  258. }
  259. /**
  260. *
  261. */
  262. public function testRemoveElementOneToMany()
  263. {
  264. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  265. $this->assertFalse($user->articles->isInitialized(), "Pre-Condition: Collection is not initialized.");
  266. // Test One to Many removal with Entity retrieved from DB
  267. $article = $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId);
  268. $queryCount = $this->getCurrentQueryCount();
  269. $user->articles->removeElement($article);
  270. $this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
  271. $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
  272. // Test One to Many removal with Entity state as new
  273. $article = new \Doctrine\Tests\Models\CMS\CmsArticle();
  274. $article->topic = "Testnew";
  275. $article->text = "blub";
  276. $queryCount = $this->getCurrentQueryCount();
  277. $user->articles->removeElement($article);
  278. $this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing a new entity should cause no query to be executed.");
  279. // Test One to Many removal with Entity state as clean
  280. $this->_em->persist($article);
  281. $this->_em->flush();
  282. $queryCount = $this->getCurrentQueryCount();
  283. $user->articles->removeElement($article);
  284. $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a persisted entity should cause one query to be executed.");
  285. $this->assertFalse($user->articles->isInitialized(), "Post-Condition: Collection is not initialized.");
  286. // Test One to Many removal with Entity state as managed
  287. $article = new \Doctrine\Tests\Models\CMS\CmsArticle();
  288. $article->topic = "How to not fail anymore on tests";
  289. $article->text = "That is simple! Just write more tests!";
  290. $this->_em->persist($article);
  291. $queryCount = $this->getCurrentQueryCount();
  292. $user->articles->removeElement($article);
  293. $this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing a managed entity should cause no query to be executed.");
  294. }
  295. /**
  296. *
  297. */
  298. public function testRemoveElementManyToMany()
  299. {
  300. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  301. $this->assertFalse($user->groups->isInitialized(), "Pre-Condition: Collection is not initialized.");
  302. // Test Many to Many removal with Entity retrieved from DB
  303. $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId);
  304. $queryCount = $this->getCurrentQueryCount();
  305. $user->groups->removeElement($group);
  306. $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a persisted entity should cause one query to be executed.");
  307. $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
  308. // Test Many to Many removal with Entity state as new
  309. $group = new \Doctrine\Tests\Models\CMS\CmsGroup();
  310. $group->name = "A New group!";
  311. $queryCount = $this->getCurrentQueryCount();
  312. $user->groups->removeElement($group);
  313. $this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing new entity should cause no query to be executed.");
  314. $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
  315. // Test Many to Many removal with Entity state as clean
  316. $this->_em->persist($group);
  317. $this->_em->flush();
  318. $queryCount = $this->getCurrentQueryCount();
  319. $user->groups->removeElement($group);
  320. $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a persisted entity should cause one query to be executed.");
  321. $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
  322. // Test Many to Many removal with Entity state as managed
  323. $group = new \Doctrine\Tests\Models\CMS\CmsGroup();
  324. $group->name = "A New group!";
  325. $this->_em->persist($group);
  326. $queryCount = $this->getCurrentQueryCount();
  327. $user->groups->removeElement($group);
  328. $this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing a managed entity should cause no query to be executed.");
  329. $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
  330. }
  331. /**
  332. *
  333. */
  334. public function testRemoveElementManyToManyInverse()
  335. {
  336. $group = $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId);
  337. $this->assertFalse($group->users->isInitialized(), "Pre-Condition: Collection is not initialized.");
  338. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  339. $queryCount = $this->getCurrentQueryCount();
  340. $group->users->removeElement($user);
  341. $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Removing a managed entity should cause one query to be executed.");
  342. $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
  343. $newUser = new \Doctrine\Tests\Models\CMS\CmsUser();
  344. $newUser->name = "A New group!";
  345. $queryCount = $this->getCurrentQueryCount();
  346. $group->users->removeElement($newUser);
  347. $this->assertEquals($queryCount, $this->getCurrentQueryCount(), "Removing a new entity should cause no query to be executed.");
  348. $this->assertFalse($user->groups->isInitialized(), "Post-Condition: Collection is not initialized.");
  349. }
  350. /**
  351. * @group DDC-1399
  352. */
  353. public function testCountAfterAddThenFlush()
  354. {
  355. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  356. $newGroup = new \Doctrine\Tests\Models\CMS\CmsGroup();
  357. $newGroup->name = "Test4";
  358. $user->addGroup($newGroup);
  359. $this->_em->persist($newGroup);
  360. $this->assertFalse($user->groups->isInitialized());
  361. $this->assertEquals(4, count($user->groups));
  362. $this->assertFalse($user->groups->isInitialized());
  363. $this->_em->flush();
  364. $this->assertEquals(4, count($user->groups));
  365. }
  366. /**
  367. * @group DDC-1462
  368. */
  369. public function testSliceOnDirtyCollection()
  370. {
  371. $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
  372. /* @var $user CmsUser */
  373. $newGroup = new \Doctrine\Tests\Models\CMS\CmsGroup();
  374. $newGroup->name = "Test4";
  375. $user->addGroup($newGroup);
  376. $this->_em->persist($newGroup);
  377. $qc = $this->getCurrentQueryCount();
  378. $groups = $user->groups->slice(0, 10);
  379. $this->assertEquals(4, count($groups));
  380. $this->assertEquals($qc + 1, $this->getCurrentQueryCount());
  381. }
  382. private function loadFixture()
  383. {
  384. $user1 = new \Doctrine\Tests\Models\CMS\CmsUser();
  385. $user1->username = "beberlei";
  386. $user1->name = "Benjamin";
  387. $user1->status = "active";
  388. $user2 = new \Doctrine\Tests\Models\CMS\CmsUser();
  389. $user2->username = "jwage";
  390. $user2->name = "Jonathan";
  391. $user2->status = "active";
  392. $user3 = new \Doctrine\Tests\Models\CMS\CmsUser();
  393. $user3->username = "romanb";
  394. $user3->name = "Roman";
  395. $user3->status = "active";
  396. $user4 = new \Doctrine\Tests\Models\CMS\CmsUser();
  397. $user4->username = "gblanco";
  398. $user4->name = "Guilherme";
  399. $user4->status = "active";
  400. $this->_em->persist($user1);
  401. $this->_em->persist($user2);
  402. $this->_em->persist($user3);
  403. $this->_em->persist($user4);
  404. $group1 = new \Doctrine\Tests\Models\CMS\CmsGroup();
  405. $group1->name = "Test1";
  406. $group2 = new \Doctrine\Tests\Models\CMS\CmsGroup();
  407. $group2->name = "Test2";
  408. $group3 = new \Doctrine\Tests\Models\CMS\CmsGroup();
  409. $group3->name = "Test3";
  410. $user1->addGroup($group1);
  411. $user1->addGroup($group2);
  412. $user1->addGroup($group3);
  413. $user2->addGroup($group1);
  414. $user3->addGroup($group1);
  415. $user4->addGroup($group1);
  416. $this->_em->persist($group1);
  417. $this->_em->persist($group2);
  418. $this->_em->persist($group3);
  419. $article1 = new \Doctrine\Tests\Models\CMS\CmsArticle();
  420. $article1->topic = "Test";
  421. $article1->text = "Test";
  422. $article1->setAuthor($user1);
  423. $article2 = new \Doctrine\Tests\Models\CMS\CmsArticle();
  424. $article2->topic = "Test";
  425. $article2->text = "Test";
  426. $article2->setAuthor($user1);
  427. $this->_em->persist($article1);
  428. $this->_em->persist($article2);
  429. $this->_em->flush();
  430. $this->_em->clear();
  431. $this->articleId = $article1->id;
  432. $this->userId = $user1->getId();
  433. $this->groupId = $group1->id;
  434. }
  435. }