Exemplo n.º 1
0
 /**
  * @dataProvider queryRepositoryStatements
  */
 public function testRepositporyQuery($statement, $rowCount)
 {
     if ($rowCount == -1) {
         // magic to tell this is an invalid query
         $this->setExpectedException('PHPCR\\Query\\InvalidQueryException');
     }
     $repository = $this->dm->getRepository($this->type);
     $query = $repository->createQuery($statement, \PHPCR\Query\QueryInterface::JCR_SQL2);
     $this->assertInstanceOf('PHPCR\\Query\\QueryInterface', $query);
     $result = $this->dm->getDocumentsByQuery($query, $this->type);
     $this->assertCount($rowCount, $result);
 }
Exemplo n.º 2
0
 public function testFindTypeValidation()
 {
     // hackish: forcing the class metadata to be loaded for those two classes so that the alias mapper finds them
     $this->dm->getRepository($this->type);
     $this->dm->getRepository($this->type . '2');
     // --
     $this->dm->getConfiguration()->setValidateDoctrineMetadata(false);
     $user = $this->dm->find($this->type . '2', '/functional/user');
     $this->assertNotInstanceOf($this->type, $user);
     $this->dm->getConfiguration()->setValidateDoctrineMetadata(true);
     $this->setExpectedException('InvalidArgumentException');
     $this->dm->find($this->type, '/functional/user');
 }
Exemplo n.º 3
0
 public function testFindByManyConstraints()
 {
     for ($i = 0; $i < 10; $i++) {
         $user = new \Doctrine\Tests\Models\CMS\CmsUser();
         $user->username = "******" . $i;
         $user->status = $i % 2 == 0 ? "active" : "inactive";
         $user->name = "Benjamin" . $i;
         $this->dm->persist($user);
     }
     $this->dm->flush();
     $users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findBy(array('username' => 'beberlei0'));
     $this->assertEquals(1, count($users));
     $this->assertEquals('beberlei0', $users[0]->username);
 }
Exemplo n.º 4
0
 public function testFindByReusesIdentities()
 {
     $this->dm = $this->createDocumentManager();
     $user = new \Doctrine\Tests\Models\CMS\CmsUser();
     $user->username = "******";
     $user->status = "active";
     $user->name = "Benjamin";
     $this->dm->persist($user);
     $this->dm->flush();
     $this->dm->clear();
     $user1 = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findOneBy(array('username' => 'beberlei'));
     $user2 = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findOneBy(array('username' => 'beberlei'));
     $this->assertSame($user1, $user2);
 }