public function testdeductFunds()
 {
     $di = new \Box_Di();
     $clientBalance = new \Model_ClientBalance();
     $clientBalance->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('dispense')->with('ClientBalance')->willReturn($clientBalance);
     $dbMock->expects($this->atLeastOnce())->method('store')->with($clientBalance);
     $di['db'] = $dbMock;
     $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
         return isset($array[$key]) ? $array[$key] : $default;
     });
     $service = new \Box\Mod\Client\ServiceBalance();
     $service->setDi($di);
     $clientModel = new \Model_Client();
     $clientModel->loadBean(new \RedBeanPHP\OODBBean());
     $description = 'Charged for product';
     $amount = 5.55;
     $extra = array('rel_id' => 1);
     $result = $service->deductFunds($clientModel, $amount, $description, $extra);
     $this->assertInstanceOf('\\Model_ClientBalance', $result);
     $this->assertEquals(-$amount, $result->amount);
     $this->assertEquals($description, $result->description);
     $this->assertEquals($extra['rel_id'], $result->rel_id);
     $this->assertEquals('default', $result->type);
 }
Beispiel #2
0
 /**
  * @dataProvider searchBalanceQueryData
  */
 public function testgetBalanceSearchQuery($data, $expectedStr, $expectedParams)
 {
     $di = new \Box_Di();
     $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
         return isset($array[$key]) ? $array[$key] : $default;
     });
     $clientBalanceService = new \Box\Mod\Client\ServiceBalance();
     $clientBalanceService->setDi($di);
     list($sql, $params) = $clientBalanceService->getSearchQuery($data);
     $this->assertNotEmpty($sql);
     $this->assertInternalType('string', $sql);
     $this->assertInternalType('array', $params);
     $this->assertTrue(strpos($sql, $expectedStr) !== false, $sql);
     $this->assertTrue(array_diff_key($params, $expectedParams) == array());
 }