Skip to content

Instantly share code, notes, and snippets.

@JusteLeblanc
Last active November 14, 2018 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JusteLeblanc/57ec96029e33488561074da4baecc264 to your computer and use it in GitHub Desktop.
Save JusteLeblanc/57ec96029e33488561074da4baecc264 to your computer and use it in GitHub Desktop.
<?php
namespace Test\AssuranceVieBundle\Validator\Constraints;
use AssuranceVieBundle\Entity\ContractType;
use AssuranceVieBundle\Entity\Subscription;
use AssuranceVieBundle\Validator\Constraints\AreInformationNoteAndKidAccepted;
use AssuranceVieBundle\Validator\Constraints\AreInformationNoteAndKidAcceptedValidator;
use Symfony\Component\Validator\Context\ExecutionContext;
use Tests\AbstractBaseUnitTestCase;
/**
* Class AreInformationNoteAndKidAcceptedValidatorTest
*/
class AreInformationNoteAndKidAcceptedValidatorTest extends AbstractBaseUnitTestCase
{
/**
* @var ExecutionContext|\PHPUnit_Framework_MockObject_MockObject $context;
*/
private $context;
/**
* SetUp before every tests
*/
public function setUp()
{
$this->context = $this->createMock(ExecutionContext::class);
}
/**
* @param ContractType $contractType
* @param bool $isKidAccepted
* @param bool $isInformationNoteAccepted
* @param bool $countViolation
*
* @dataProvider validateProvider
*/
public function testValidate($contractType, $isKidAccepted, $isInformationNoteAccepted, $countViolation)
{
$subscription = new Subscription();
$subscription->setContractType($contractType);
$subscription->setKidAccepted($isKidAccepted);
$subscription->setInformationNoteAccepted($isInformationNoteAccepted);
$constraint = new AreInformationNoteAndKidAccepted();
$areInformationNoteAndKidAcceptedValidator = new AreInformationNoteAndKidAcceptedValidator();
$this->context->expects($this->exactly($countViolation))->method('addViolation')->with($constraint->message);
$areInformationNoteAndKidAcceptedValidator->initialize($this->context);
$areInformationNoteAndKidAcceptedValidator->validate($subscription, $constraint);
}
/**
* @return array
*/
public function validateProvider()
{
$contractTypeWithoutKid = new ContractType();
$contractTypeWithoutKid->setKidUrl(null);
$contractTypeWithoutKid->setKidText(null);
$contractTypeWithKid = new ContractType();
$contractTypeWithKid->setKidUrl('test.com');
$contractTypeWithKid->setKidText('du Kid');
return [
[null, null, null, 0],
[$contractTypeWithoutKid, null, null, 0],
[$contractTypeWithoutKid, true, true, 0],
[$contractTypeWithoutKid, true, false, 1],
[$contractTypeWithoutKid, false, true, 0],
[$contractTypeWithoutKid, false, false, 1],
[$contractTypeWithKid, null, null, 0],
[$contractTypeWithKid, true, true, 0],
[$contractTypeWithKid, true, false, 1],
[$contractTypeWithKid, false, true, 1],
[$contractTypeWithKid, false, false, 1],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment