public function ContentEntityBaseUnitTest::testValidate in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php \Drupal\Tests\Core\Entity\ContentEntityBaseUnitTest::testValidate()
@covers ::validate
File
- core/
tests/ Drupal/ Tests/ Core/ Entity/ ContentEntityBaseUnitTest.php, line 339
Class
- ContentEntityBaseUnitTest
- @coversDefaultClass \Drupal\Core\Entity\ContentEntityBase @group Entity @group Access
Namespace
Drupal\Tests\Core\EntityCode
public function testValidate() {
$validator = $this
->createMock(ValidatorInterface::class);
/** @var \Symfony\Component\Validator\ConstraintViolationList|\PHPUnit\Framework\MockObject\MockObject $empty_violation_list */
$empty_violation_list = $this
->getMockBuilder('\\Symfony\\Component\\Validator\\ConstraintViolationList')
->setMethods(NULL)
->getMock();
$non_empty_violation_list = clone $empty_violation_list;
$violation = $this
->createMock('\\Symfony\\Component\\Validator\\ConstraintViolationInterface');
$non_empty_violation_list
->add($violation);
$validator
->expects($this
->exactly(2))
->method('validate')
->with($this->entity
->getTypedData())
->willReturnOnConsecutiveCalls($empty_violation_list, $non_empty_violation_list);
$this->typedDataManager
->expects($this
->exactly(2))
->method('getValidator')
->will($this
->returnValue($validator));
$this
->assertCount(0, $this->entity
->validate());
$this
->assertCount(1, $this->entity
->validate());
}