diff --git a/src/AmoCRM/Filters/EventsFilter.php b/src/AmoCRM/Filters/EventsFilter.php index 7fb4c09..ef99b51 100755 --- a/src/AmoCRM/Filters/EventsFilter.php +++ b/src/AmoCRM/Filters/EventsFilter.php @@ -205,7 +205,7 @@ public function getEntityIds() */ public function setEntityIds($entityIds) { - $this->entityIds = $entityIds; + $this->entityIds = $this->parseArrayOrNumberFilter($entityIds); return $this; } diff --git a/tests/Cases/AmoCRM/Filters/EventsFilterTest.php b/tests/Cases/AmoCRM/Filters/EventsFilterTest.php new file mode 100644 index 0000000..6931fe7 --- /dev/null +++ b/tests/Cases/AmoCRM/Filters/EventsFilterTest.php @@ -0,0 +1,104 @@ +eventsFilter = new EventsFilter(); + } + + /** + * @dataProvider getValidArrayOrNumericFilter + * + * @param $entityIds + * @param $expected + */ + public function testValidEntityIds($entityIds, $expected) + { + $this->eventsFilter->setEntityIds($entityIds); + $this->assertEquals($expected, array_values($this->eventsFilter->getEntityIds())); + } + + /** + * @dataProvider getInvalidArrayOrNumericFilter + * + * @param $entityIds + */ + public function testInvalidEntityIds($entityIds) + { + $this->eventsFilter->setEntityIds($entityIds); + $this->assertNull($this->eventsFilter->getEntityIds()); + } + + /** + * @return array + */ + public function getInvalidArrayOrNumericFilter() { + return [ + [ + -1, + ], + [ + [ + -1, + -100 + ], + ], + [ + [ + -100, + ], + ], + [ + "hello" + ], + [ + [ + true, + false + ] + ], + [ + false + ], + [ + null + ], + ]; + } + + /** + * @return array + */ + public function getValidArrayOrNumericFilter() { + return [ + [ + 0, [0], + ], + [ + 100, [100], + ], + [ + "100", [100], + ], + [ + [1, 2, 3, 4], [1, 2, 3, 4], + ], + [ + [-1, 1, 2], [1 , 2], + ] + ]; + } +}