You are here

protected function FeedsExecutableTest::addDefaultEventListeners in Feeds 8.3

Adds default listeners to event dispatcher.

1 call to FeedsExecutableTest::addDefaultEventListeners()
FeedsExecutableTest::testImport in tests/src/Unit/FeedsExecutableTest.php
@covers ::doFetch @covers ::doParse @covers ::doProcess

File

tests/src/Unit/FeedsExecutableTest.php, line 88

Class

FeedsExecutableTest
@coversDefaultClass \Drupal\feeds\FeedsExecutable @group feeds

Namespace

Drupal\Tests\feeds\Unit

Code

protected function addDefaultEventListeners() {
  $fetcher_result = $this
    ->createMock(FetcherResultInterface::class);
  $parser_result = new ParserResult();
  $parser_result
    ->addItem($this
    ->createMock(ItemInterface::class));
  $this->dispatcher
    ->addListener(FeedsEvents::FETCH, function (FetchEvent $event) use ($fetcher_result) {
    $event
      ->setFetcherResult($fetcher_result);
  });
  $this->dispatcher
    ->addListener(FeedsEvents::PARSE, function (ParseEvent $event) use ($fetcher_result, $parser_result) {
    $this
      ->assertSame($event
      ->getFetcherResult(), $fetcher_result);
    $event
      ->setParserResult($parser_result);
  });
  $this->dispatcher
    ->addListener(FeedsEvents::PROCESS, function (ProcessEvent $event) use ($parser_result) {
    $this
      ->assertInstanceOf(ItemInterface::class, $event
      ->getItem());
  });
}