vendor/bundles/FOS/UserBundle/Tests/Validation/UniqueValidatorTest.php
changeset 3 e54dfe4d0b2b
equal deleted inserted replaced
2:806e57d67020 3:e54dfe4d0b2b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the FOSUserBundle package.
       
     5  *
       
     6  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 namespace FOS\UserBundle\Tests\Validation;
       
    13 
       
    14 use FOS\UserBundle\Validator\UniqueValidator;
       
    15 use FOS\UserBundle\Validator\Unique;
       
    16 
       
    17 class UniqueValidatorTest extends \PHPUnit_Framework_TestCase
       
    18 {
       
    19     private $validator;
       
    20     private $userManagerMock;
       
    21     private $constraint;
       
    22     private $user;
       
    23 
       
    24     public function setUp()
       
    25     {
       
    26         $this->userManagerMock = $this->getMock('FOS\UserBundle\Model\UserManagerInterface');
       
    27         $this->constraint = new Unique();
       
    28         $this->validator = new UniqueValidator($this->userManagerMock);
       
    29         $this->user = $this->getMock('FOS\UserBundle\Model\UserInterface');
       
    30     }
       
    31 
       
    32     public function testFalseOnDuplicateUserProperty()
       
    33     {
       
    34         $this->userManagerMock->expects($this->once())
       
    35                 ->method('validateUnique')
       
    36                 ->will($this->returnValue(false))
       
    37                 ->with($this->equalTo($this->user), $this->equalTo($this->constraint));
       
    38 
       
    39         $this->assertFalse($this->validator->isValid($this->user, $this->constraint));
       
    40     }
       
    41 
       
    42     public function testTrueOnUniqueUserProperty()
       
    43     {
       
    44         $this->userManagerMock->expects($this->once())
       
    45                 ->method('validateUnique')
       
    46                 ->will($this->returnValue(true))
       
    47                 ->with($this->equalTo($this->user), $this->equalTo($this->constraint));
       
    48 
       
    49         $this->assertTrue($this->validator->isValid($this->user, $this->constraint));
       
    50     }
       
    51 }