EntityResourceValidationTraitTestClass example

/** * @group rest * @coversDefaultClass \Drupal\rest\Plugin\rest\resource\EntityResourceValidationTrait */
class EntityResourceValidationTraitTest extends UnitTestCase {

  /** * @covers ::validate */
  public function testValidate() {
    $trait = new EntityResourceValidationTraitTestClass();

    $method = new \ReflectionMethod($trait, 'validate');

    $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());
  }
Home | Imprint | This part of the site doesn't use cookies.