Files
FOSSBilling/tests/bb-modules/Example/Api/ClientTest.php
T
2014-11-03 09:00:47 +02:00

65 lines
1.9 KiB
PHP

<?php
namespace Box\Mod\Example\Api;
class ClientTest extends \PHPUnit_Framework_TestCase {
/**
* @var \Box\Mod\Example\Api\Client
*/
protected $api = null;
public function setup()
{
$this->api= new \Box\Mod\Example\Api\Client();
}
public function testget_info()
{
$data = array('microsoft');
$eventMock = $this->getMockBuilder('\Box_EventManager')->getMock();
$eventMock->expects($this->atLeastOnce())->method('fire');
$modelClient = new \Model_Client();
$modelClient->loadBean(new \RedBeanPHP\OODBBean());
$clientService = $this->getMockBuilder('\Box\Mod\Client\Service')->getMock();
$clientService->expects($this->atLeastOnce())
->method('toApiArray')
->with($modelClient)
->willReturn(array());
$systemService = $this->getMockBuilder('\Box\Mod\System\Service')->getMock();
$systemService->expects($this->atLeastOnce())
->method('getVersion')
->willReturn(\Box_Version::VERSION);
$systemService->expects($this->atLeastOnce())
->method('getMessages')
->willReturn(array());
$di = new \Box_Di();
$di['logger'] = new \Box_Log();
$di['events_manager'] = $eventMock;
$di['mod_service'] = $di->protect(function ($serviceName) use ($clientService, $systemService){
if ($serviceName == 'Client'){
return $clientService;
}
if ($serviceName == 'System'){
return $systemService;
}
return -1;
});
$di['loggedin_client'] = $modelClient;
$this->api->setDi($di);
$result = $this->api->get_info($data);
$this->assertInternalType('array', $result);
$this->assertArrayHasKey('version', $result);
$this->assertArrayHasKey('profile', $result);
$this->assertArrayHasKey('messages', $result);
}
}