예제 #1
0
 /**
  * @dataProvider entityManagerDataProvider
  * @param EntityManager $em
  */
 public function testCacheIndex(EntityManager $em)
 {
     $product = new IndexedEntity();
     $product->setId1(212)->setId2('test')->setAlpha('index-test')->setBravo(888);
     $em->persist($product)->flush();
     $r = $em->retrieve(IndexedEntity::class, '212.test');
     $r->setBravo(999);
     $r1 = $em->retrieveByIndex(IndexedEntity::class, 'ab', 'index-test.888');
     $this->assertEquals(999, $r1->getBravo());
     $r2 = $em->retrieveByIndex(IndexedEntity::class, 'ab', 'index-test.888', false);
     $this->assertEquals(888, $r2->getBravo());
     $em->getCache()->purge(IndexedEntity::class, '212.test');
     $r3 = $em->retrieveByIndex(IndexedEntity::class, 'ab', 'index-test.888');
     $this->assertEquals(888, $r3->getBravo());
 }
예제 #2
0
 /**
  * @dataProvider entityManagerDataProvider
  * @param EntityManager $em
  */
 public function testIdQuery(EntityManager $em)
 {
     $a = new IndexedEntity();
     $a->setId1('1');
     $a->setId2('first');
     $a->setAlpha('alpha1');
     $a->setBravo(1);
     $a->setCharlie(true);
     $b = new IndexedEntity();
     $b->setId1('2');
     $b->setId2('second');
     $b->setAlpha('alpha2');
     $b->setBravo(2);
     $b->setCharlie(false);
     $em->persist($a)->persist($b)->flush();
     $result = $em->indexedQuery(new IndexedQuery(IndexedEntity::class, ['@id' => '1.fir*']));
     $this->assertCount(1, $result);
     /** @var IndexedEntity $entity */
     $entity = $result->current();
     $this->assertEquals('1', $entity->getId1());
     $this->assertEquals('first', $entity->getId2());
     $this->assertEquals('alpha1', $entity->getAlpha());
     $result = $em->indexedQuery(new IndexedQuery(IndexedEntity::class, ['@id' => '*']));
     $this->assertGreaterThanOrEqual(2, count($result));
     $result = $em->indexedQuery(new IndexedQuery(IndexedEntity::class, ['@id' => '*', 'ab' => 'alpha1*']));
     $this->assertCount(1, $result);
     /** @var IndexedEntity $entity */
     $entity = $result->current();
     $this->assertEquals('1', $entity->getId1());
     $this->assertEquals('first', $entity->getId2());
     $this->assertEquals('alpha1', $entity->getAlpha());
 }
예제 #3
0
파일: IndexTest.php 프로젝트: bravo3/orm
 /**
  * @dataProvider entityManagerDataProvider
  * @param EntityManager $em
  */
 public function testIndex(EntityManager $em)
 {
     $entity = new IndexedEntity();
     $entity->setId1(100)->setId2('id2');
     $entity->setAlpha('alpha')->setBravo('200')->setCharlie(true);
     $metadata = $em->getMapper()->getEntityMetadata($entity);
     $reader = new Reader($metadata, $entity);
     $this->assertEquals('100.id2', $reader->getId());
     $indices = $metadata->getIndices();
     $this->assertCount(3, $indices);
     $ab = $metadata->getIndexByName('ab');
     $this->assertContains('alpha', $ab->getColumns());
     $this->assertContains('bravo', $ab->getColumns());
     $this->assertCount(2, $ab->getColumns());
     $this->assertEquals('alpha.200', $reader->getIndexValue($ab));
     $bc = $metadata->getIndexByName('bc');
     $this->assertContains('bravo', $bc->getColumns());
     $this->assertContains('getCharlie', $bc->getMethods());
     $this->assertCount(1, $bc->getColumns());
     $this->assertCount(1, $bc->getMethods());
     $this->assertEquals('200.1', $reader->getIndexValue($bc));
     $b = $metadata->getIndexByName('b');
     $this->assertContains('bravo', $b->getColumns());
     $this->assertCount(1, $b->getColumns());
     $this->assertEquals('200', $reader->getIndexValue($b));
     $em->persist($entity)->flush();
     /** @var IndexedEntity $retrieved */
     $retrieved = $em->retrieve(self::INDEXED_ENTITY, '100.id2');
     $retrieved->setAlpha('omega')->setId1(101);
     $em->persist($retrieved)->flush();
     try {
         $em->retrieveByIndex(self::INDEXED_ENTITY, 'ab', 'alpha.200');
         $this->fail("Former index was found");
     } catch (NotFoundException $e) {
     }
     /** @var IndexedEntity $retrieved_by_index */
     $retrieved_by_index = $em->retrieveByIndex(self::INDEXED_ENTITY, 'ab', 'omega.200');
     $this->assertEquals(101, $retrieved_by_index->getId1());
     $this->assertEquals('id2', $retrieved_by_index->getId2());
     $this->assertSame('omega', $retrieved_by_index->getAlpha());
     $this->assertSame(200, $retrieved_by_index->getBravo());
     $this->assertSame(true, $retrieved_by_index->getCharlie());
 }