You are here

protected function FeedTypeTest::getFeedTypeMock in Feeds 8.3

Gets a feed type for testing.

Parameters

string $feed_type_id: The feed type ID.

array $stubs: (optional) The methods to mock.

Return value

\Drupal\feeds\FeedTypeInterface The mocked feed type.

2 calls to FeedTypeTest::getFeedTypeMock()
FeedTypeTest::setUp in tests/src/Unit/Entity/FeedTypeTest.php
FeedTypeTest::testGetMappedSources in tests/src/Unit/Entity/FeedTypeTest.php
@covers ::getMappedSources

File

tests/src/Unit/Entity/FeedTypeTest.php, line 34

Class

FeedTypeTest
@coversDefaultClass \Drupal\feeds\Entity\FeedType @group feeds

Namespace

Drupal\Tests\feeds\Unit\Entity

Code

protected function getFeedTypeMock($feed_type_id, array $stubs = []) {

  // Plugin manager.
  $pluginManager = $this
    ->getMockBuilder(FeedsPluginManager::class)
    ->disableOriginalConstructor()
    ->getMock();
  $pluginManager
    ->expects($this
    ->any())
    ->method('getDefinitions')
    ->will($this
    ->returnValue([]));
  $default_stubs = [
    'getParser',
    'getSourcePluginManager',
    'alter',
  ];
  $feed_type = $this
    ->getMockBuilder(FeedType::class)
    ->setConstructorArgs([
    [
      'id' => $feed_type_id,
      'label' => 'My Feed',
      'custom_sources' => [
        'source1' => [
          'label' => 'Source 1',
          'value' => 'Source 1',
        ],
      ],
    ],
    'feeds_feed_type',
  ])
    ->setMethods(array_merge($default_stubs, $stubs))
    ->getMock();

  // Parser.
  $parser = $this
    ->getMockBuilder(ParserInterface::class)
    ->getMock();
  $parser
    ->expects($this
    ->any())
    ->method('getMappingSources')
    ->will($this
    ->returnValue([]));
  $feed_type
    ->expects($this
    ->any())
    ->method('getParser')
    ->will($this
    ->returnValue($parser));

  // Source plugin manager.
  $feed_type
    ->expects($this
    ->any())
    ->method('getSourcePluginManager')
    ->will($this
    ->returnValue($pluginManager));
  return $feed_type;
}