From 8a8eab4bf1dfcc77bbb5ddce8ebedf7b42d872fd Mon Sep 17 00:00:00 2001 From: soyuka Date: Mon, 1 Oct 2018 09:11:08 +0200 Subject: [PATCH] Fix data persister remove stops after 1st match --- src/DataPersister/ChainDataPersister.php | 2 +- tests/DataPersister/ChainDataPersisterTest.php | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/DataPersister/ChainDataPersister.php b/src/DataPersister/ChainDataPersister.php index 6abf03987a6..2883aa1d63b 100644 --- a/src/DataPersister/ChainDataPersister.php +++ b/src/DataPersister/ChainDataPersister.php @@ -63,7 +63,7 @@ public function remove($data) { foreach ($this->persisters as $persister) { if ($persister->supports($data)) { - $persister->remove($data); + return $persister->remove($data); } } } diff --git a/tests/DataPersister/ChainDataPersisterTest.php b/tests/DataPersister/ChainDataPersisterTest.php index 82d82631bed..c68b8e8b47f 100644 --- a/tests/DataPersister/ChainDataPersisterTest.php +++ b/tests/DataPersister/ChainDataPersisterTest.php @@ -60,7 +60,11 @@ public function testPersist() $barPersisterProphecy->supports($dummy)->willReturn(true)->shouldBeCalled(); $barPersisterProphecy->persist($dummy)->shouldBeCalled(); - (new ChainDataPersister([$fooPersisterProphecy->reveal(), $barPersisterProphecy->reveal()]))->persist($dummy); + $foobarPersisterProphecy = $this->prophesize(DataPersisterInterface::class); + $foobarPersisterProphecy->supports($dummy)->shouldNotBeCalled(); + $foobarPersisterProphecy->persist($dummy)->shouldNotBeCalled(); + + (new ChainDataPersister([$fooPersisterProphecy->reveal(), $barPersisterProphecy->reveal(), $foobarPersisterProphecy->reveal()]))->persist($dummy); } public function testRemove() @@ -75,6 +79,10 @@ public function testRemove() $barPersisterProphecy->supports($dummy)->willReturn(true)->shouldBeCalled(); $barPersisterProphecy->remove($dummy)->shouldBeCalled(); - (new ChainDataPersister([$fooPersisterProphecy->reveal(), $barPersisterProphecy->reveal()]))->remove($dummy); + $foobarPersisterProphecy = $this->prophesize(DataPersisterInterface::class); + $foobarPersisterProphecy->supports($dummy)->shouldNotBeCalled(); + $foobarPersisterProphecy->remove($dummy)->shouldNotBeCalled(); + + (new ChainDataPersister([$fooPersisterProphecy->reveal(), $barPersisterProphecy->reveal(), $foobarPersisterProphecy->reveal()]))->remove($dummy); } }