getMockBuilder('Doctrine\ORM\EntityRepository') ->disableOriginalConstructor() ->setMethods(['findValidToken']) ->getMock(); $tokenValue = self::$DI['app']['random.low']->generateString(8); $repo ->expects($this->once()) ->method('findValidToken') ->with($tokenValue) ->will($this->returnValue(null)); $constraint = new PasswordToken($repo); $this->assertFalse($constraint->isValid($tokenValue)); } public function testValidTokenIsValid() { $repo = $this ->getMockBuilder('Doctrine\ORM\EntityRepository') ->disableOriginalConstructor() ->setMethods(['findValidToken']) ->getMock(); $tokenValue = self::$DI['app']['random.low']->generateString(8); $token = new Token(); $token->setType(TokenManipulator::TYPE_PASSWORD); $repo ->expects($this->once()) ->method('findValidToken') ->with($tokenValue) ->will($this->returnValue($token)); $constraint = new PasswordToken($repo); $this->assertTrue($constraint->isValid($tokenValue)); } }