Skip to content
Permalink
Browse files

tests: Refactored `EntityReferenceExistsValidatorTest` according to c…

…hanges that have been made for it.
  • Loading branch information...
tarlepp committed Sep 21, 2019
1 parent 3b08671 commit 89e745e85386a73d80a9fb90385f41713ddf28e6
Showing with 33 additions and 8 deletions.
  1. +33 −8 tests/Integration/Validator/Constraints/EntityReferenceExistsValidatorTest.php
@@ -49,16 +49,21 @@ public function testThatValidateMethodThrowsUnexpectedTypeException(): void
* @dataProvider dataProviderTestThatValidateMethodThrowsUnexpectedValueException
*
* @param mixed $value
* @param mixed $entityClass
* @param string $expectedMessage
*/
public function testThatValidateMethodThrowsUnexpectedValueException(
$value,
$entityClass,
string $expectedMessage
): void {
$this->expectException(UnexpectedValueException::class);
$this->expectExceptionMessage($expectedMessage);
(new EntityReferenceExistsValidator())->validate($value, new EntityReferenceExists());
$constraint = new EntityReferenceExists();
$constraint->entityClass = $entityClass;
(new EntityReferenceExistsValidator())->validate($value, $constraint);
}
public function testThatContextAndLoggerMethodsAreNotCalledWithinHappyPath(): void
@@ -70,7 +75,7 @@ public function testThatContextAndLoggerMethodsAreNotCalledWithinHappyPath(): vo
*/
$context = $this->getMockBuilder(ExecutionContext::class)->disableOriginalConstructor()->getMock();
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
$value = $this->getMockForAbstractClass(EntityReference::class);
$value = $this->getMockForAbstractClass(EntityReference::class, [], 'TestClass');
$context
->expects(static::never())
@@ -85,11 +90,14 @@ public function testThatContextAndLoggerMethodsAreNotCalledWithinHappyPath(): vo
->method('getCreatedAt')
->willReturn(null);
$constraint = new EntityReferenceExists();
$constraint->entityClass = 'TestClass';
// Run validator
$validator = new EntityReferenceExistsValidator();
$validator->initialize($context);
$validator->setLogger($logger);
$validator->validate($value, new EntityReferenceExists());
$validator->validate($value, $constraint);
}
public function testThatContextAndLoggerMethodsAreCalledIfEntityReferenceIsNotValidEntity(): void
@@ -138,33 +146,50 @@ public function testThatContextAndLoggerMethodsAreCalledIfEntityReferenceIsNotVa
->method('getCreatedAt')
->willThrowException($exception);
$constraint = new EntityReferenceExists();
$constraint->entityClass = EntityReference::class;
// Run validator
$validator = new EntityReferenceExistsValidator();
$validator->initialize($context);
$validator->setLogger($logger);
$validator->validate($value, new EntityReferenceExists());
$validator->validate($value, $constraint);
}
/**
* @return Generator
*/
public function dataProviderTestThatValidateMethodThrowsUnexpectedValueException(): Generator
{
yield ['', 'Expected argument of type "Doctrine\ORM\Proxy\Proxy", "string" given'];
yield ['', stdClass::class, 'Expected argument of type "stdClass", "string" given'];
yield [new stdClass(), 'Expected argument of type "Doctrine\ORM\Proxy\Proxy", "stdClass" given'];
yield [
new stdClass(),
EntityInterface::class,
'Expected argument of type "App\Entity\EntityInterface", "stdClass" given'
];
yield [[''], 'Expected argument of type "Doctrine\ORM\Proxy\Proxy", "string" given'];
yield [
[''],
EntityInterface::class,
'Expected argument of type "App\Entity\EntityInterface", "string" given'
];
yield [[new stdClass()], 'Expected argument of type "Doctrine\ORM\Proxy\Proxy", "stdClass" given'];
yield [
[new stdClass()],
EntityInterface::class,
'Expected argument of type "App\Entity\EntityInterface", "stdClass" given'
];
yield [
$this->getMockForAbstractClass(Proxy::class, [], 'ProxyClass'),
Proxy::class,
'Expected argument of type "App\Entity\EntityInterface", "ProxyClass" given',
];
yield [
[$this->getMockForAbstractClass(Proxy::class, [], 'ProxyClass')],
Proxy::class,
'Expected argument of type "App\Entity\EntityInterface", "ProxyClass" given',
];
}

0 comments on commit 89e745e

Please sign in to comment.
You can’t perform that action at this time.