function EntityResourceValidationTraitTest::testValidate

Same name in other branches
  1. 9 core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php \Drupal\Tests\rest\Unit\EntityResourceValidationTraitTest::testValidate()
  2. 10 core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php \Drupal\Tests\rest\Unit\EntityResourceValidationTraitTest::testValidate()
  3. 11.x core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php \Drupal\Tests\rest\Unit\EntityResourceValidationTraitTest::testValidate()

@covers ::validate

File

core/modules/rest/tests/src/Unit/EntityResourceValidationTraitTest.php, line 22

Class

EntityResourceValidationTraitTest
@group rest @coversDefaultClass \Drupal\rest\Plugin\rest\resource\EntityResourceValidationTrait

Namespace

Drupal\Tests\rest\Unit

Code

public function testValidate() {
    $trait = new EntityResourceValidationTraitTestClass();
    $method = new \ReflectionMethod($trait, 'validate');
    $method->setAccessible(TRUE);
    $violations = $this->prophesize(EntityConstraintViolationList::class);
    $violations->filterByFieldAccess()
        ->shouldBeCalled()
        ->willReturn([]);
    $violations->count()
        ->shouldBeCalled()
        ->willReturn(0);
    $entity = $this->prophesize(Node::class);
    $entity->validate()
        ->shouldBeCalled()
        ->willReturn($violations->reveal());
    $method->invoke($trait, $entity->reveal());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.