public function testbatchSend() { $service = new \Box\Mod\Email\Service(); $queueModel = new \Model_ModEmailQueue(); $queueModel->loadBean(new \RedBeanPHP\OODBBean()); $queueModel->priority = 10; $queueModel->tries = 10; $queueModel->subject = 'subject'; $queueModel->client_id = 1; $queueModel->sender = '*****@*****.**'; $queueModel->recipient = '*****@*****.**'; $queueModel->content = 'content'; $queueModel->from_name = 'From Name'; $queueModel->to_name = 'To Name'; $db = $this->getMockBuilder('Box_Database')->getMock(); $db->expects($this->at(0))->method('findOne')->will($this->returnValue($queueModel)); $db->expects($this->at(1))->method('findOne')->will($this->returnValue(false)); $db->expects($this->atLeastOnce())->method('store')->will($this->returnValue(true)); $activityMock = $this->getMockBuilder('\\Box\\Mod\\Activity\\Service')->setMethods(array('logEmail'))->getMock(); $activityMock->expects($this->atLeastOnce())->method('logEmail')->will($this->returnValue(true)); $licenseMock = $this->getMockBuilder('\\Box_License')->getMock(); $licenseMock->expects($this->atLeastOnce())->method('isPro')->will($this->returnValue(false)); $modMock = $this->getMockBuilder('\\Box_Mod')->disableOriginalConstructor()->getMock(); $modMock->expects($this->atLeastOnce())->method('getConfig')->will($this->returnValue(array('log_enabled' => 1, 'cancel_after' => 1))); $mailMock = $this->getMockBuilder('\\Box_Mail')->disableOriginalConstructor()->getMock(); /* Will not work be called because APPLICATION_ENV != 'production' * $mailMock->expects($this->atLeastOnce()) ->method('send') ->will($this->returnValue(true)); */ $di = new \Box_Di(); $di['db'] = $db; $di['mail'] = $mailMock; $di['logger'] = $this->getMockBuilder('Box_Log')->getMock(); $di['mod_service'] = $di->protect(function ($name) use($activityMock) { return $activityMock; }); $di['mod'] = $di->protect(function () use($modMock) { return $modMock; }); $di['license'] = $licenseMock; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $service->setDi($di); $result = $service->batchSend(); $this->assertNull($result); }