You are here

public function TestImporter::testConstruct in Feeds Paragraphs 8

@covers ::__construct

File

tests/src/Unit/TestImporter.php, line 78

Class

TestImporter
@group Feeds Paragraphs @coversDefaultClass \Drupal\feeds_para_mapper\Importer

Namespace

Drupal\Tests\feeds_para_mapper\Unit

Code

public function testConstruct() {
  $entity_manager = $this->entityHelper
    ->getEntityTypeManagerMock();
  $field_manager = $this->fieldHelper
    ->getEntityFieldManagerMock();
  $mapper = $this
    ->getMapperObject();

  // Get mock, without the constructor being called
  $mock = $this
    ->getMockBuilder(Importer::class)
    ->disableOriginalConstructor()
    ->getMock();
  $reflectedClass = new \ReflectionClass(Importer::class);
  $constructor = $reflectedClass
    ->getConstructor();

  // Force the constructor to throw error:
  $entity_manager
    ->getStorage('paragraph')
    ->willThrow(InvalidPluginDefinitionException::class);

  // now call the constructor
  $exception = null;
  try {
    $constructor
      ->invoke($mock, $entity_manager
      ->reveal(), $field_manager, $mapper);
  } catch (\Exception $e) {
    $exception = $e;
  }
  $entity_manager
    ->getStorage('paragraph')
    ->shouldHaveBeenCalled();
  self::assertInstanceOf(InvalidPluginDefinitionException::class, $exception);
}