public function FeedsSubscriberTest::testAfterParseWithSkippingItem in Feeds Tamper 8.2
@covers ::afterParse @covers ::alterItem
File
- tests/
src/ Unit/ EventSubscriber/ FeedsSubscriberTest.php, line 274
Class
- FeedsSubscriberTest
- @coversDefaultClass \Drupal\feeds_tamper\EventSubscriber\FeedsSubscriber @group feeds_tamper
Namespace
Drupal\Tests\feeds_tamper\Unit\EventSubscriberCode
public function testAfterParseWithSkippingItem() {
// Create a tamper plugin that will throw a SkipTamperItemException for some
// values.
$tamper = $this
->createMock(TamperInterface::class);
$tamper
->expects($this
->exactly(2))
->method('tamper')
->will($this
->returnCallback([
$this,
'callbackSkipItem',
]));
$this->tamperMeta
->expects($this
->once())
->method('getTampersGroupedBySource')
->will($this
->returnValue([
'alpha' => [
$tamper,
],
]));
// Create three items. The first item should get removed.
$item1 = new DynamicItem();
$item1
->set('alpha', 'Foo');
$this->event
->getParserResult()
->addItem($item1);
$item2 = new DynamicItem();
$item2
->set('alpha', 'Bar');
$this->event
->getParserResult()
->addItem($item2);
$this->subscriber
->afterParse($this->event);
// Assert that only item 2 still exists.
$this
->assertEquals(1, $this->event
->getParserResult()
->count());
$this
->assertSame($item2, $this->event
->getParserResult()
->offsetGet(0));
}