You are here

public function FeedTest::testDispatchImportFinishedEvent in Feeds 8.3

Tests that the event 'feeds.import_finished' gets dispatched.

@covers ::finishImport

File

tests/src/Kernel/Entity/FeedTest.php, line 272

Class

FeedTest
@coversDefaultClass \Drupal\feeds\Entity\Feed @group feeds

Namespace

Drupal\Tests\feeds\Kernel\Entity

Code

public function testDispatchImportFinishedEvent() {
  $dispatcher = new EventDispatcher();
  $feed = $this
    ->getMockBuilder(Feed::class)
    ->setMethods([
    'eventDispatcher',
    'getType',
  ])
    ->setConstructorArgs([
    [
      'type' => $this->feedType
        ->id(),
    ],
    'feeds_feed',
    $this->feedType
      ->id(),
  ])
    ->getMock();
  $feed
    ->expects($this
    ->once())
    ->method('getType')
    ->willReturn($this->feedType);
  $feed
    ->expects($this
    ->once())
    ->method('eventDispatcher')
    ->willReturn($dispatcher);
  $dispatcher
    ->addListener(FeedsEvents::IMPORT_FINISHED, function (ImportFinishedEvent $event) {
    throw new Exception();
  });
  $this
    ->expectException(Exception::class);
  $feed
    ->finishImport();
}