From afbe1e03a1cf9e3e978decbf26ac0b3b1877dcae Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Sun, 4 Jan 2015 13:34:59 +0200 Subject: [PATCH] adding unit test for PopulateListener --- Event/PopulateEvent.php | 8 +-- Tests/EventListener/PopulateListenerTest.php | 54 ++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 Tests/EventListener/PopulateListenerTest.php diff --git a/Event/PopulateEvent.php b/Event/PopulateEvent.php index 9bf9dbb..305c393 100644 --- a/Event/PopulateEvent.php +++ b/Event/PopulateEvent.php @@ -46,10 +46,10 @@ class PopulateEvent extends Event private $options; /** - * @param string $index - * @param string $type - * @param boolean $reset - * @param array $options + * @param string $index + * @param string|null $type + * @param boolean $reset + * @param array $options */ public function __construct($index, $type, $reset, $options) { diff --git a/Tests/EventListener/PopulateListenerTest.php b/Tests/EventListener/PopulateListenerTest.php new file mode 100644 index 0000000..6388e79 --- /dev/null +++ b/Tests/EventListener/PopulateListenerTest.php @@ -0,0 +1,54 @@ +resetter = $this->getMockBuilder('FOS\ElasticaBundle\Index\Resetter') + ->disableOriginalConstructor() + ->getMock(); + + $this->listener = new PopulateListener($this->resetter); + } + + public function testPostIndexPopulate() + { + $this->resetter->expects($this->once())->method('postPopulate')->with('indexName'); + $this->listener->postIndexPopulate(new PopulateEvent('indexName', null, true, array())); + } + + public function testPreIndexPopulateWhenNoResetRequired() + { + $this->resetter->expects($this->never())->method('resetIndex'); + $this->resetter->expects($this->never())->method('resetIndexType'); + $this->listener->preIndexPopulate(new PopulateEvent('indexName', null, false, array())); + } + + public function testPreIndexPopulateWhenResetIsRequiredAndNoTypeIsSpecified() + { + $this->resetter->expects($this->once())->method('resetIndex')->with('indexName'); + $this->listener->preIndexPopulate(new PopulateEvent('indexName', null, true, array())); + } + + public function testPreIndexPopulateWhenResetIsRequiredAndTypeIsSpecified() + { + $this->resetter->expects($this->once())->method('resetIndexType')->with('indexName', 'indexType'); + $this->listener->preIndexPopulate(new PopulateEvent('indexName', 'indexType', true, array())); + } +}