From 7c90660e02e45e7dbab20bfd2b3e5159c089a29d Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Sun, 4 Jan 2015 20:57:08 +0200 Subject: [PATCH] attempt to make scrutinizer happy, about duplicate code in test --- Tests/EventListener/PopulateListenerTest.php | 49 +++++++++++++++----- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/Tests/EventListener/PopulateListenerTest.php b/Tests/EventListener/PopulateListenerTest.php index 6388e79..3d653d3 100644 --- a/Tests/EventListener/PopulateListenerTest.php +++ b/Tests/EventListener/PopulateListenerTest.php @@ -33,22 +33,47 @@ class PopulateListenerTest extends \PHPUnit_Framework_TestCase $this->listener->postIndexPopulate(new PopulateEvent('indexName', null, true, array())); } - public function testPreIndexPopulateWhenNoResetRequired() + public function preIndexPopulateDataProvider() { - $this->resetter->expects($this->never())->method('resetIndex'); - $this->resetter->expects($this->never())->method('resetIndexType'); - $this->listener->preIndexPopulate(new PopulateEvent('indexName', null, false, array())); + return array( + array( + array( + array('resetIndex', $this->never()), + array('resetIndexType', $this->never()) + ), + array('indexName', true), + new PopulateEvent('indexName', null, false, array()) + ), + array( + array( + array('resetIndex', $this->once()) + ), + array('indexName', true), + new PopulateEvent('indexName', null, true, array()) + ), + array( + array( + array('resetIndexType', $this->once()) + ), + array('indexName', 'indexType'), + new PopulateEvent('indexName', 'indexType', true, array()) + ) + ); } - public function testPreIndexPopulateWhenResetIsRequiredAndNoTypeIsSpecified() + /** + * @param array $asserts + * @param array $withArgs + * @param PopulateEvent $event + * + * @dataProvider preIndexPopulateDataProvider + */ + public function testPreIndexPopulate(array $asserts, array $withArgs, PopulateEvent $event) { - $this->resetter->expects($this->once())->method('resetIndex')->with('indexName'); - $this->listener->preIndexPopulate(new PopulateEvent('indexName', null, true, array())); - } + foreach ($asserts as $assert) { + $this->resetter->expects($assert[1])->method($assert[0])->with($withArgs[0], $withArgs[1]); + } - public function testPreIndexPopulateWhenResetIsRequiredAndTypeIsSpecified() - { - $this->resetter->expects($this->once())->method('resetIndexType')->with('indexName', 'indexType'); - $this->listener->preIndexPopulate(new PopulateEvent('indexName', 'indexType', true, array())); + $this->listener->preIndexPopulate($event); } }