Example #1
0
 /**
  * Test manipulation of votes collection.
  *
  * @covers Application\Sonata\UserBundle\Entity\User::addVote()
  * @covers Application\Sonata\UserBundle\Entity\User::removeVote()
  * @covers Application\Sonata\UserBundle\Entity\User::getVotes()
  */
 public function testAddVote()
 {
     $votes[0] = new Vote();
     $votes[1] = new Vote();
     $votes[2] = new Vote();
     $this->assertTrue($this->object->getVotes() instanceof Collection);
     $this->assertEquals(0, $this->object->getVotes()->count());
     $this->object->addVote($votes[0]);
     $this->assertEquals(1, $this->object->getVotes()->count());
     $this->assertTrue($this->object->getVotes()->contains($votes[0]));
     $this->assertFalse($this->object->getVotes()->contains($votes[1]));
     $this->assertFalse($this->object->getVotes()->contains($votes[2]));
     $this->object->addVote($votes[1]);
     $this->assertEquals(2, $this->object->getVotes()->count());
     $this->assertTrue($this->object->getVotes()->contains($votes[0]));
     $this->assertTrue($this->object->getVotes()->contains($votes[1]));
     $this->assertFalse($this->object->getVotes()->contains($votes[2]));
     $this->object->removeVote($votes[2]);
     $this->assertEquals(2, $this->object->getVotes()->count());
     $this->assertTrue($this->object->getVotes()->contains($votes[0]));
     $this->assertTrue($this->object->getVotes()->contains($votes[1]));
     $this->assertFalse($this->object->getVotes()->contains($votes[2]));
     $this->object->removeVote($votes[0]);
     $this->assertEquals(1, $this->object->getVotes()->count());
     $this->assertFalse($this->object->getVotes()->contains($votes[0]));
     $this->assertTrue($this->object->getVotes()->contains($votes[1]));
     $this->assertFalse($this->object->getVotes()->contains($votes[2]));
 }