public function testApply() { $categoryId = 123; $requestVar = 'test_request_var'; $this->target->setRequestVar($requestVar); $this->request->expects($this->exactly(2))->method('getParam')->will($this->returnCallback(function ($field) use($requestVar, $categoryId) { $this->assertTrue(in_array($field, [$requestVar, 'id'])); return $categoryId; })); $this->dataProvider->expects($this->once())->method('setCategoryId')->with($categoryId)->will($this->returnSelf()); $this->category->expects($this->once())->method('getId')->will($this->returnValue($categoryId)); $this->fulltextCollection->expects($this->once())->method('addCategoryFilter')->with($this->category)->will($this->returnSelf()); $this->target->apply($this->request); }