本文整理汇总了PHP中Documents\User::setCount方法的典型用法代码示例。如果您正苦于以下问题:PHP User::setCount方法的具体用法?PHP User::setCount怎么用?PHP User::setCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Documents\User
的用法示例。
在下文中一共展示了User::setCount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDistinct
public function testDistinct()
{
$user = new User();
$user->setUsername('distinct_test');
$user->setCount(1);
$this->dm->persist($user);
$user = new User();
$user->setUsername('distinct_test');
$user->setCount(1);
$this->dm->persist($user);
$user = new User();
$user->setUsername('distinct_test');
$user->setCount(2);
$this->dm->persist($user);
$user = new User();
$user->setUsername('distinct_test');
$user->setCount(3);
$this->dm->persist($user);
$this->dm->flush();
$qb = $this->dm->createQueryBuilder('Documents\\User')->distinct('count')->field('username')->equals('distinct_test');
$q = $qb->getQuery();
$results = $q->execute();
$this->assertEquals(new \Doctrine\MongoDB\ArrayIterator(array(1, 2, 3)), $results);
$results = $this->dm->createQueryBuilder('Documents\\User')->distinct('count')->field('username')->equals('distinct_test')->getQuery()->execute();
$this->assertEquals(new \Doctrine\MongoDB\ArrayIterator(array(1, 2, 3)), $results);
}
示例2: testAddGroups
public function testAddGroups()
{
$account = new Account();
$account->setName('Jon Test Account');
$user = new User();
$user->setUsername('jon');
$user->setPassword('changeme');
$user->setAccount($account);
$user->setCount(5);
$user->addGroup(new Group('administrator'));
$user->addGroup(new Group('member'));
$user->addGroup(new Group('moderator'));
$this->dm->persist($user);
$this->persister->expects($this->once())->method('executeInserts');
$this->dm->getUnitOfWork()->computeChangeSets();
$update = $this->persister->prepareUpdateData($user);
$this->assertTrue(array_key_exists('$set', $update));
$this->assertFalse(array_key_exists('$unset', $update));
$this->assertTrue(array_key_exists('$pushAll', $update));
$this->assertTrue(array_key_exists('groups', $update['$pushAll']));
$this->assertEquals(3, count($update['$pushAll']['groups']));
$this->assertFalse(array_key_exists('$pullAll', $update));
$this->assertTrue(array_key_exists('$inc', $update));
$this->assertEquals(5, $update['$inc']['count']);
$user->setCount(20);
$this->dm->getUnitOfWork()->computeChangeSets();
$update = $this->persister->prepareUpdateData($user);
$this->assertTrue(array_key_exists('$inc', $update));
$this->assertEquals(15, $update['$inc']['count']);
$user->setCount(5);
$this->dm->getUnitOfWork()->computeChangeSets();
$update = $this->persister->prepareUpdateData($user);
$this->assertTrue(array_key_exists('$inc', $update));
$this->assertEquals(-15, $update['$inc']['count']);
$this->dm->flush();
}
示例3: testMultipleUpdateQuery
public function testMultipleUpdateQuery()
{
$user = new User();
$user->setUsername('multiple_test');
$user->setCount(1);
$this->dm->persist($user);
$user = new User();
$user->setUsername('multiple_test');
$user->setCount(1);
$this->dm->persist($user);
$user = new User();
$user->setUsername('multiple_test');
$user->setCount(2);
$this->dm->persist($user);
$user = new User();
$user->setUsername('multiple_test');
$user->setCount(3);
$this->dm->persist($user);
$this->dm->flush();
$qb = $this->dm->createQueryBuilder('Documents\\User')->update()->multiple()->field('username')->equals('multiple_test')->field('username')->set('foo');
$q = $qb->getQuery();
$results = $q->execute();
$qb = $this->dm->createQueryBuilder('Documents\\User')->find()->field('username')->equals('foo');
$q = $qb->getQuery();
$users = array_values($q->execute()->toArray());
$this->assertEquals(4, count($users));
}
示例4: testIncrementSetsNull
public function testIncrementSetsNull()
{
$user = new User();
$user->setUsername('jon');
$user->setCount(10);
$this->dm->persist($user);
$this->dm->flush();
$this->dm->clear();
$user = $this->dm->getRepository('Documents\\User')->findOneBy(array('username' => 'jon'));
$this->assertEquals(10, $user->getCount());
$user->incrementCount(1);
$this->dm->flush();
$this->dm->clear();
$user = $this->dm->getRepository('Documents\\User')->findOneBy(array('username' => 'jon'));
$this->assertEquals(11, $user->getCount());
$user->setCount(null);
$this->dm->flush();
$this->dm->clear();
$user = $this->dm->getRepository('Documents\\User')->findOneBy(array('username' => 'jon'));
$this->assertEquals(null, $user->getCount());
}