Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90a0b0d
commit a2f55c7
Showing
2 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
Backoffice/Tests/Validator/Constraints/RoleStatusesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace OpenOrchestra\Backoffice\Tests\Validator\Constraints; | ||
|
||
use OpenOrchestra\Backoffice\Validator\Constraints\RoleStatuses; | ||
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractBaseTestCase; | ||
use Symfony\Component\Validator\Constraint; | ||
|
||
/** | ||
* Class RoleStatusesTest | ||
*/ | ||
class RoleStatusesTest extends AbstractBaseTestCase | ||
{ | ||
/** | ||
* @var RoleStatuses | ||
*/ | ||
protected $constraint; | ||
|
||
/** | ||
* Set up the test | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->constraint = new RoleStatuses(); | ||
} | ||
|
||
/** | ||
* Test instance | ||
*/ | ||
public function testInstance() | ||
{ | ||
$this->assertInstanceOf('Symfony\Component\Validator\Constraint', $this->constraint); | ||
} | ||
|
||
/** | ||
* Test target | ||
*/ | ||
public function testTarget() | ||
{ | ||
$this->assertSame(Constraint::CLASS_CONSTRAINT, $this->constraint->getTargets()); | ||
} | ||
|
||
/** | ||
* Test messages | ||
*/ | ||
public function testMessages() | ||
{ | ||
$this->assertSame('open_orchestra_backoffice_validators.role.duplicate_statuses', $this->constraint->message); | ||
} | ||
|
||
/** | ||
* Test validate by | ||
*/ | ||
public function testValidateBy() | ||
{ | ||
$this->assertSame('role_statuses', $this->constraint->validatedBy()); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
Backoffice/Tests/Validator/Constraints/RoleStatusesValidatorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace OpenOrchestra\Backoffice\Tests\Validator\Constraints; | ||
|
||
use OpenOrchestra\Backoffice\Validator\Constraints\RoleStatusesValidator; | ||
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractBaseTestCase; | ||
use Phake; | ||
|
||
/** | ||
* Class RoleStatusesValidatorTest | ||
*/ | ||
class RoleStatusesValidatorTest extends AbstractBaseTestCase | ||
{ | ||
/** | ||
* @var RoleStatusesValidator | ||
*/ | ||
protected $validator; | ||
|
||
protected $constraint; | ||
protected $context; | ||
protected $roleId = 'fakeRoleId'; | ||
|
||
/** | ||
* Set up the test | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->constraint = Phake::mock('Symfony\Component\Validator\Constraint'); | ||
$this->context = Phake::mock('Symfony\Component\Validator\Context\ExecutionContextInterface'); | ||
$this->role = Phake::mock('OpenOrchestra\ModelInterface\Model\RoleInterface'); | ||
$constraintViolationBuilder = Phake::mock('Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface'); | ||
|
||
Phake::when($this->context)->buildViolation(Phake::anyParameters())->thenReturn($constraintViolationBuilder); | ||
Phake::when($this->role)->getId()->thenReturn($this->roleId); | ||
Phake::when($this->role)->getFromStatus()->thenReturn(Phake::mock('OpenOrchestra\ModelInterface\Model\StatusInterface')); | ||
Phake::when($this->role)->getToStatus()->thenReturn(Phake::mock('OpenOrchestra\ModelInterface\Model\StatusInterface')); | ||
Phake::when($constraintViolationBuilder)->atPath(Phake::anyParameters())->thenReturn($constraintViolationBuilder); | ||
} | ||
|
||
/** | ||
* Test instance | ||
*/ | ||
public function testClass() | ||
{ | ||
$roleRepository = Phake::mock('OpenOrchestra\ModelInterface\Repository\RoleRepositoryInterface'); | ||
$validator = new RoleStatusesValidator($roleRepository); | ||
$this->assertInstanceOf('Symfony\Component\Validator\ConstraintValidator', $validator); | ||
} | ||
|
||
/** | ||
* @param string|null $roleId | ||
* @param integer $violationTimes | ||
* | ||
* @dataProvider provideAreaIdAndViolation | ||
*/ | ||
public function testValidate($roleId, $violationTimes) | ||
{ | ||
$roleRepository = Phake::mock('OpenOrchestra\ModelInterface\Repository\RoleRepositoryInterface'); | ||
if (!is_null($roleId)) { | ||
$role = Phake::mock('OpenOrchestra\ModelInterface\Model\RoleInterface'); | ||
Phake::when($role)->getId()->thenReturn($roleId); | ||
Phake::when($roleRepository)->findOneByFromStatusAndToStatus(Phake::anyParameters())->thenReturn($role); | ||
} else { | ||
Phake::when($roleRepository)->findOneByFromStatusAndToStatus(Phake::anyParameters())->thenReturn(null); | ||
} | ||
|
||
$validator = new RoleStatusesValidator($roleRepository); | ||
$validator->initialize($this->context); | ||
$validator->validate($this->role, $this->constraint); | ||
|
||
Phake::verify($this->context, Phake::times($violationTimes))->buildViolation(Phake::anyParameters()); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function provideAreaIdAndViolation() | ||
{ | ||
return array( | ||
array(null, 0), | ||
array($this->roleId, 0), | ||
array('fakeAnotherRoleId', 1), | ||
); | ||
} | ||
} |