本文整理汇总了PHP中DocumentManager::clear方法的典型用法代码示例。如果您正苦于以下问题:PHP DocumentManager::clear方法的具体用法?PHP DocumentManager::clear怎么用?PHP DocumentManager::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocumentManager
的用法示例。
在下文中一共展示了DocumentManager::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFindMany
public function testFindMany()
{
$this->dm = $this->createDocumentManager();
$user1 = new \Doctrine\Tests\Models\CMS\CmsUser();
$user1->username = "beberlei";
$user1->status = "active";
$user1->name = "Benjamin";
$user2 = new \Doctrine\Tests\Models\CMS\CmsUser();
$user2->username = "lsmith";
$user2->status = "active";
$user2->name = "Lukas";
$this->dm = $this->createDocumentManager();
$this->dm->persist($user1);
$this->dm->persist($user2);
$this->dm->flush();
$users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array($user1->id, $user2->id));
$this->assertEquals(2, count($users));
$this->assertSame($user1, $users[0]);
$this->assertSame($user2, $users[1]);
$users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array($user1->id, $user2->id), 1, 0);
$this->assertEquals(1, count($users));
$this->assertSame($user1, $users[0]);
$users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array($user1->id, $user2->id), 1, 1);
$this->assertEquals(1, count($users));
$this->assertSame($user2, $users[1]);
$this->dm->clear();
$users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array($user1->id, $user2->id));
$this->assertEquals($user1->id, $users[0]->id);
$this->assertEquals($user2->id, $users[1]->id);
}
示例2: testReferenceOneDifferentTargetDocuments
public function testReferenceOneDifferentTargetDocuments()
{
$ref1 = new MODEL\RefType1TestObj();
$ref1->id = '/functional/ref1';
$ref1->name = 'Ref1';
$ref2 = new MODEL\RefType2TestObj();
$ref2->id = '/functional/ref2';
$ref2->name = 'Ref2';
$this->dm->persist($ref1);
$this->dm->persist($ref2);
$referer1 = new ReferenceOneObj();
$referer1->id = '/functional/referer1';
$referer1->reference = $ref1;
$this->dm->persist($referer1);
$referer2 = new ReferenceOneObj();
$referer2->id = '/functional/referer2';
$referer2->reference = $ref2;
$this->dm->persist($referer2);
$this->dm->flush();
$this->dm->clear();
$referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer1');
$this->assertTrue($referer->reference instanceof MODEL\RefType1TestObj);
$referer = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ReferenceOneObj', '/functional/referer2');
$this->assertTrue($referer->reference instanceof MODEL\RefType2TestObj);
}
示例3: testPropertyname
public function testPropertyname()
{
$doc = new PropertyTestObj();
$doc->id = '/functional/p';
$doc->string = 'astring';
$doc->long = 123;
$doc->int = 321;
$doc->decimal = '343';
$doc->double = 3.14;
$doc->float = 2.8;
$date = new \DateTime();
$doc->date = $date;
$doc->boolean = true;
$doc->name = 'aname';
$doc->path = '../';
$doc->uri = 'http://cmf.symfony.com:8080/about.html#there';
$this->dm->persist($doc);
$this->dm->flush();
$this->dm->clear();
$this->assertTrue($this->node->getNode('p')->hasProperty('string'));
$this->assertTrue($this->node->getNode('p')->hasProperty('long'));
$this->assertTrue($this->node->getNode('p')->hasProperty('int'));
$this->assertTrue($this->node->getNode('p')->hasProperty('decimal'));
$this->assertTrue($this->node->getNode('p')->hasProperty('double'));
$this->assertTrue($this->node->getNode('p')->hasProperty('float'));
$this->assertTrue($this->node->getNode('p')->hasProperty('date'));
$this->assertTrue($this->node->getNode('p')->hasProperty('boolean'));
$this->assertTrue($this->node->getNode('p')->hasProperty('name'));
$this->assertTrue($this->node->getNode('p')->hasProperty('path'));
$this->assertTrue($this->node->getNode('p')->hasProperty('uri'));
$doc = $this->dm->find($this->type, '/functional/p');
$this->assertNotNull($doc->string);
$this->assertEquals('astring', $doc->string);
$this->assertNotNull($doc->long);
$this->assertEquals(123, $doc->long);
$this->assertNotNull($doc->int);
$this->assertEquals(321, $doc->int);
$this->assertNotNull($doc->decimal);
$this->assertEquals('343', $doc->decimal);
$this->assertNotNull($doc->double);
$this->assertEquals(3.14, $doc->double);
$this->assertNotNull($doc->float);
$this->assertEquals(2.8, $doc->float);
$this->assertNotNull($doc->date);
$this->assertEquals($date->getTimestamp(), $doc->date->getTimestamp());
$this->assertNotNull($doc->boolean);
$this->assertEquals(true, $doc->boolean);
$this->assertNotNull($doc->name);
$this->assertEquals('aname', $doc->name);
$this->assertNotNull($doc->path);
$this->assertEquals('../', $doc->path);
$this->assertNotNull($doc->uri);
$this->assertEquals('http://cmf.symfony.com:8080/about.html#there', $doc->uri);
}
示例4: testCreatedDate
public function testCreatedDate()
{
$parent = new FileTestObj();
$parent->file = new File();
$parent->id = '/functional/filetest';
$parent->file->setFileContentFromFilesystem(dirname(__FILE__) . '/_files/foo.txt');
$this->dm->persist($parent);
$this->dm->flush();
$this->dm->clear();
$file = $this->dm->find('Doctrine\\ODM\\PHPCR\\Document\\File', '/functional/filetest/file');
$this->assertNotNull($file);
$this->assertNotNull($file->getCreated());
}
示例5: testCreateFromFile
public function testCreateFromFile()
{
$parent = new FixPHPCR1TestObj();
$parent->id = '/functional/filetest';
$this->dm->persist($parent);
$parent->file = new File();
$parent->file->setFileContentFromFilesystem(dirname(__FILE__) . '/_files/foo.txt');
$this->dm->flush();
$this->dm->clear();
$this->assertTrue($this->node->getNode('filetest')->hasNode('file'));
$this->assertTrue($this->node->getNode('filetest')->getNode('file')->hasNode('jcr:content'));
$this->assertTrue($this->node->getNode('filetest')->getNode('file')->getNode('jcr:content')->hasProperty('jcr:data'));
}
示例6: testLoadManyWithMissingIds
public function testLoadManyWithMissingIds()
{
$this->dm = $this->createDocumentManager();
$users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array('missing-id-1', 'missing-id-2'));
$this->assertEmpty($users);
$user1 = new \Doctrine\Tests\Models\CMS\CmsUser();
$user1->username = "beberlei";
$user1->status = "active";
$user1->name = "Benjamin";
$this->dm = $this->createDocumentManager();
$this->dm->persist($user1);
$this->dm->flush();
$this->dm->clear();
$users = $this->dm->getRepository('Doctrine\\Tests\\Models\\CMS\\CmsUser')->findMany(array($user1->id, 'missing-id-2'));
$this->assertEquals(1, count($users));
}
示例7: testReorderChildren
public function testReorderChildren()
{
$this->testModifyChildren();
try {
$parent = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ChildrenTestObj', '/functional/parent');
$this->assertCount(2, $parent->allChildren);
$data = array('child-g' => $parent->allChildren->last(), 'child-f' => $parent->allChildren->first());
$parent->allChildren = new ArrayCollection($data);
$this->dm->flush();
$this->dm->clear();
$parent = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ChildrenTestObj', '/functional/parent');
$this->assertCount(count($data), $parent->allChildren);
$this->assertEquals(array_keys($data), $parent->allChildren->getKeys());
$child1 = new ChildrenTestObj();
$child1->name = 'Child H';
$child2 = new ChildrenTestObj();
$child2->name = 'Child I';
$child3 = new ChildrenTestObj();
$child3->name = 'Child J';
$data = array('child-i' => $child2, 'child-h' => $child1, 'child-f' => $parent->allChildren->last(), 'child-g' => $parent->allChildren->first(), 'child-j' => $child3);
$parent->allChildren = new ArrayCollection($data);
$this->dm->flush();
$this->dm->clear();
$parent = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ChildrenTestObj', '/functional/parent');
$this->assertCount(count($data), $parent->allChildren);
$this->assertEquals(array_keys($data), $parent->allChildren->getKeys());
} catch (UnsupportedRepositoryOperationException $e) {
$this->markTestSkipped('Reordering of children not supported');
}
}
示例8: testPropertyname
public function testPropertyname()
{
$doc = new TestObj();
$doc->id = '/functional/pn';
$doc->name = 'Testname';
$doc->othername = 'Testothername';
$this->dm->persist($doc);
$this->dm->flush();
$this->dm->clear();
$this->assertTrue($this->node->getNode('pn')->hasProperty('name'));
$this->assertTrue($this->node->getNode('pn')->hasProperty('myname'));
$doc = $this->dm->find($this->type, '/functional/pn');
$this->assertNotNull($doc->name);
$this->assertEquals('Testname', $doc->name);
$this->assertNotNull($doc->othername);
$this->assertEquals('Testothername', $doc->othername);
}
示例9: testAddRemoveAttachment
public function testAddRemoveAttachment()
{
$fh = fopen(__DIR__ . '/_files/logo.jpg', 'r');
$user = $this->dm->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'user_with_attachment');
$user->attachments['logo.jpg'] = Attachment::createFromBinaryData($fh, 'image/jpeg');
$this->dm->flush();
$this->dm->clear();
// dont re-use identity map
$user = $this->dm->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'user_with_attachment');
unset($user->attachments['foo.txt']);
$this->dm->flush();
$this->dm->clear();
// dont re-use identity map
$user = $this->dm->find('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'user_with_attachment');
$this->assertArrayHasKey('logo.jpg', $user->attachments);
$this->assertArrayNotHasKey('foo.txt', $user->attachments);
}
示例10: testProxyForChildIsUsed
function testProxyForChildIsUsed()
{
$doc = $this->dm->find($this->type, '/functional/thename');
$doc->child = new NameDoc();
$this->dm->flush();
$this->dm->clear();
$doc = $this->dm->find($this->type, '/functional/thename');
$this->assertTrue($doc->child instanceof Proxy);
}
示例11: testNullConversionHandledAutomatically
public function testNullConversionHandledAutomatically()
{
$user1 = $this->dm->find($this->type, 1);
$user1->username = null;
$this->dm->flush();
$this->dm->clear();
$pUser1 = $this->dm->find($this->type, 1);
$this->assertNull($pUser1->username);
}
示例12: testRemoveChildParent
public function testRemoveChildParent()
{
$parent = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ChildrenTestObj', '/functional/parent');
$this->assertCount(4, $parent->allChildren);
$this->dm->remove($parent);
$this->dm->flush();
$this->dm->clear();
$parent = $this->dm->find('Doctrine\\Tests\\ODM\\PHPCR\\Functional\\ChildrenTestObj', '/functional/parent');
$this->assertNull($parent);
}
示例13: testDetach
public function testDetach()
{
$user = $this->dm->find($this->type, '/functional/user');
$user->username = "new-name";
$this->dm->detach($user);
$this->dm->flush();
$this->dm->clear();
$newUser = $this->dm->find($this->type, '/functional/user');
$this->assertEquals('lsmith', $newUser->username);
}
示例14: testCreateCascade
public function testCreateCascade()
{
$folder = new Folder();
$folder->setId('/functional/folder');
$file = new File();
$file->setFileContent('Lorem ipsum dolor sit amet');
$file->setNodename('file');
$folder->addChild($file);
$this->dm->persist($folder);
$this->dm->flush();
$this->dm->clear();
$this->assertTrue($this->node->hasNode('folder'));
$this->assertTrue($this->node->getNode('folder')->hasNode('file'));
$this->assertTrue($this->node->getNode('folder')->getNode('file')->hasNode('jcr:content'));
$this->assertTrue($this->node->getNode('folder')->getNode('file')->getNode('jcr:content')->hasProperty('jcr:data'));
$binaryStream = $this->node->getNode('folder')->getNode('file')->getNode('jcr:content')->getProperty('jcr:data')->getBinary();
$content = stream_get_contents($binaryStream);
$this->assertEquals('Lorem ipsum dolor sit amet', $content);
}
示例15: testRemoveThenMove
public function testRemoveThenMove()
{
$this->dm->clear();
$user = $this->dm->find($this->type, '/functional/lsmith');
$this->assertNotNull($user, 'User must exist');
$this->dm->remove($user);
$this->dm->move($user, '/functional/user2');
$this->dm->flush();
$user = $this->dm->find($this->type, '/functional/user2');
$this->assertNotNull($user, 'User must exist');
$user = $this->dm->find($this->type, '/functional/lsmith');
$this->assertNull($user, 'User must be null after deletion');
}