public function testGetSize() { $countSql = 500; $adapterMock = $this->getMock('Zend_Db_Adapter_Pdo_Mysql', ['select', 'quoteInto', 'prepareSqlCondition', 'fetchOne'], [], '', false); $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', ['orWhere', 'where', 'reset', 'columns'], ['adapter' => $adapterMock]); $selectMock->expects($this->exactly(4))->method('reset'); $selectMock->expects($this->once())->method('columns')->with('COUNT(*)'); $adapterMock->expects($this->once())->method('select')->will($this->returnValue($selectMock)); $adapterMock->expects($this->exactly(2))->method('quoteInto')->will($this->returnValueMap([['testField1=?', 'testValue1', null, null, 'testField1=testValue1'], ['testField4=?', 'testValue4', null, null, 'testField4=testValue4']])); $selectMock->expects($this->once())->method('orWhere')->with('testField1=testValue1'); $selectMock->expects($this->exactly(3))->method('where')->will($this->returnValueMap([['testValue2', $this->returnSelf()], ['testField3 = testValue3', null, \Magento\Framework\DB\Select::TYPE_CONDITION, $this->returnSelf()], ['testField4=testValue4', $this->returnSelf()]])); $adapterMock->expects($this->once())->method('prepareSqlCondition')->with('testField3', 'testValue3')->will($this->returnValue('testField3 = testValue3')); $adapterMock->expects($this->once())->method('fetchOne')->with($selectMock, [])->will($this->returnValue($countSql)); $this->collection->addFilter('testField1', 'testValue1', 'or'); $this->collection->addFilter('testField2', 'testValue2', 'string'); $this->collection->addFilter('testField3', 'testValue3', 'public'); $this->collection->addFilter('testField4', 'testValue4'); $this->collection->setConnection($adapterMock); $this->assertEquals($countSql, $this->collection->getSize()); $this->assertEquals($countSql, $this->collection->getSize()); }