public function testCannedUpdate() { $dbMock = $this->getMockBuilder('\\Box_Database')->disableOriginalConstructor()->getMock(); $dbMock->expects($this->atLeastOnce())->method('store')->will($this->returnValue(rand(1, 100))); $di = new \Box_Di(); $di['db'] = $dbMock; $di['logger'] = $this->getMockBuilder('Box_Log')->getMock(); $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $this->service->setDi($di); $model = new \Model_SupportPr(); $model->loadBean(new \RedBeanPHP\OODBBean()); $data = array('category_id' => rand(1, 100), 'title' => '*****@*****.**', 'content' => 1); $result = $this->service->cannedUpdate($model, $data); $this->assertTrue($result); }
public function testCanned_get_list() { $resultSet = array('list' => array(0 => array('id' => 1))); $paginatorMock = $this->getMockBuilder('\\Box_Pagination')->disableOriginalConstructor()->getMock(); $paginatorMock->expects($this->atLeastOnce())->method('getSimpleResultSet')->will($this->returnValue($resultSet)); $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Support\\Service')->setMethods(array('cannedGetSearchQuery', 'cannedToApiArray'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('cannedGetSearchQuery')->will($this->returnValue(array('query', array()))); $serviceMock->expects($this->atLeastOnce())->method('cannedToApiArray')->will($this->returnValue(array())); $model = new \Model_SupportPr(); $model->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_DAtabase')->getMock(); $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($model)); $di = new \Box_Di(); $di['pager'] = $paginatorMock; $di['db'] = $dbMock; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $this->adminApi->setDi($di); $this->adminApi->setService($serviceMock); $data = array(); $result = $this->adminApi->canned_get_list($data); $this->assertInternalType('array', $result); }