本文整理汇总了PHP中Box_Di::protect方法的典型用法代码示例。如果您正苦于以下问题:PHP Box_Di::protect方法的具体用法?PHP Box_Di::protect怎么用?PHP Box_Di::protect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box_Di
的用法示例。
在下文中一共展示了Box_Di::protect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testget_info
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;
$di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
return isset($array[$key]) ? $array[$key] : $default;
});
$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);
}
示例2: testrecaptcha
/**
* @dataProvider datarecaptchaConfig
*/
public function testrecaptcha($config, $expected)
{
$di = new \Box_Di();
$di['mod_config'] = $di->protect(function () use($config) {
return $config;
});
$di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
return isset($array[$key]) ? $array[$key] : $default;
});
$this->api->setDi($di);
$result = $this->api->recaptcha(array());
$this->assertEquals($expected, $result);
}
示例3: testTicket_get_list
public function testTicket_get_list()
{
$simpleResultArr = array('list' => array(array('id' => 1)));
$paginatorMock = $this->getMockBuilder('\\Box_Pagination')->disableOriginalConstructor()->getMock();
$paginatorMock->expects($this->atLeastOnce())->method('getAdvancedResultSet')->will($this->returnValue($simpleResultArr));
$serviceMock = $this->getMockBuilder('\\Box\\Mod\\Support\\Service')->setMethods(array('getSearchQuery', 'toApiArray'))->getMock();
$serviceMock->expects($this->atLeastOnce())->method('getSearchQuery')->will($this->returnValue(array('query', array())));
$serviceMock->expects($this->atLeastOnce())->method('toApiArray')->will($this->returnValue(array()));
$model = new \Model_SupportTicket();
$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->clientApi->setDi($di);
$client = new \Model_Client();
$client->loadBean(new \RedBeanPHP\OODBBean());
$client->id = rand(1, 100);
$this->clientApi->setService($serviceMock);
$this->clientApi->setIdentity($client);
$data = array();
$result = $this->clientApi->ticket_get_list($data);
$this->assertInternalType('array', $result);
}
示例4: testdeductFunds
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);
}
示例5: testGet_list
public function testGet_list()
{
$clientApi = new \Box\Mod\Email\Api\Client();
$emailService = new \Box\Mod\Email\Service();
$willReturn = array("list" => array('id' => 1));
$pager = $this->getMockBuilder('Box_Pagination')->getMock();
$pager->expects($this->atLeastOnce())->method('getSimpleResultSet')->will($this->returnValue($willReturn));
$di = new \Box_Di();
$di['pager'] = $pager;
$di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
return isset($array[$key]) ? $array[$key] : $default;
});
$clientApi->setDi($di);
$emailService->setDi($di);
$service = $emailService;
$clientApi->setService($service);
$client = new \Model_Client();
$client->loadBean(new \RedBeanPHP\OODBBean());
$client->id = rand(1, 100);
$clientApi->setIdentity($client);
$result = $clientApi->get_list(array());
$this->assertInternalType('array', $result);
$this->assertArrayHasKey('list', $result);
$this->assertInternalType('array', $result['list']);
}
示例6: testEvents
public function testEvents()
{
$di = new \Box_Di();
$di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
return isset($array[$key]) ? $array[$key] : $default;
});
$this->service->setDi($di);
$result = $this->service->getSearchQuery(array());
$this->assertInternalType('array', $result);
}
示例7: testlanguages
public function testlanguages()
{
$systemServiceMock = $this->getMockBuilder('\\Box\\Mod\\System\\Service')->getMock();
$systemServiceMock->expects($this->atLeastOnce())->method('getLanguages')->will($this->returnValue(array()));
$di = new \Box_Di();
$di['mod_service'] = $di->protect(function ($name) use($systemServiceMock) {
return $systemServiceMock;
});
$this->api->setDi($di);
$result = $this->api->languages();
$this->assertInternalType('array', $result);
}
示例8: testbatch_connect
public function testbatch_connect()
{
$serviceMock = $this->getMockBuilder('\\Box\\Mod\\Hook\\Service')->getMock();
$serviceMock->expects($this->atLeastOnce())->method('batchConnect')->will($this->returnValue(1));
$di = new \Box_Di();
$di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
return isset($array[$key]) ? $array[$key] : $default;
});
$this->api->setDi($di);
$this->api->setService($serviceMock);
$result = $this->api->batch_connect(array());
$this->assertNotEmpty($result);
}
示例9: testgetPairs
public function testgetPairs()
{
$service = new \Box\Mod\Page\Service();
$themeService = $this->getMockBuilder('\\Box\\Mod\\Theme\\Service')->getMock();
$themeService->expects($this->atLeastOnce())->method('getCurrentClientAreaThemeCode');
$di = new \Box_Di();
$di['mod_service'] = $di->protect(function () use($themeService) {
return $themeService;
});
$service->setDi($di);
$result = $service->getPairs();
$this->assertInternalType('array', $result);
}
示例10: testgetLastExecutionTime
public function testgetLastExecutionTime()
{
$systemServiceMock = $this->getMockBuilder('\\Box\\Mod\\System\\Service')->getMock();
$systemServiceMock->expects($this->atLeastOnce())->method('getParamValue')->will($this->returnValue('2012-12-12 12:12:12'));
$di = new \Box_Di();
$di['mod_service'] = $di->protect(function ($name) use($systemServiceMock) {
return $systemServiceMock;
});
$service = new \Box\Mod\Cron\Service();
$service->setDi($di);
$result = $service->getLastExecutionTime();
$this->assertInternalType('string', $result);
}
示例11: testGet
public function testGet()
{
$clientService = $this->getMockBuilder('\\Box\\Mod\\Client\\Service')->getMock();
$clientService->expects($this->atLeastOnce())->method('toApiArray')->will($this->returnValue(array()));
$di = new \Box_Di();
$di['mod_service'] = $di->protect(function () use($clientService) {
return $clientService;
});
$this->clientApi->setDi($di);
$this->clientApi->setIdentity(new \Model_Client());
$result = $this->clientApi->get();
$this->assertInternalType('array', $result);
}
示例12: testtop_songs
public function testtop_songs()
{
$xmlString = "<note>\n<to>Tove</to>\n<from>Jani</from>\n<heading>Reminder</heading>\n<body>Don't forget me this weekend!</body>\n</note>";
$data = array();
$toolsMock = $this->getMockBuilder('\\Box_Tools')->getMock();
$toolsMock->expects($this->atLeastOnce())->method('file_get_contents')->willReturn($xmlString);
$di = new \Box_Di();
$di['tools'] = $toolsMock;
$di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
return isset($array[$key]) ? $array[$key] : $default;
});
$this->api->setDi($di);
$result = $this->api->top_songs($data);
$this->assertInternalType('array', $result);
}
示例13: testGetSearchQuery
public function testGetSearchQuery()
{
$service = new Box\Mod\Example\Service();
$di = new \Box_Di();
$di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
return isset($array[$key]) ? $array[$key] : $default;
});
$service->setDi($di);
$data = array('client_id' => 1);
list($sql, $params) = $service->getSearchQuery($data);
$this->assertInternalType('string', $sql);
$this->assertInternalType('array', $params);
$this->assertArrayHasKey(':client_id', $params);
$this->assertEquals($params[':client_id'], $data['client_id']);
}
示例14: testTlds
public function testTlds()
{
$serviceMock = $this->getMockBuilder('\\Box\\Mod\\Servicedomain\\Service')->setMethods(array('tldToApiArray'))->getMock();
$serviceMock->expects($this->atLeastOnce())->method('tldToApiArray')->will($this->returnValue(array()));
$this->guestApi->setService($serviceMock);
$dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
$dbMock->expects($this->atLeastOnce())->method('find')->will($this->returnValue(array(new \Model_Tld())));
$di = new \Box_Di();
$di['db'] = $dbMock;
$di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
return isset($array[$key]) ? $array[$key] : $default;
});
$this->guestApi->setDi($di);
$result = $this->guestApi->tlds(array());
$this->assertInternalType('array', $result);
$this->assertInternalType('array', $result[0]);
}
示例15: testgetAmountInCents
public function testgetAmountInCents()
{
$model = new \Model_Invoice();
$model->loadBean(new RedBeanPHP\OODBBean());
$totalAmountWithTax = 12.23;
$invoiceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->getMock();
$invoiceServiceMock->expects($this->atLeastOnce())->method('getTotalWithTax')->with($model)->willReturn($totalAmountWithTax);
$di = new \Box_Di();
$di['mod_service'] = $di->protect(function ($serviceName) use($invoiceServiceMock) {
if ($serviceName == 'Invoice') {
return $invoiceServiceMock;
}
});
$adapter = new Payment_Adapter_Stripe($this->defaultConfig);
$adapter->setDi($di);
$result = $adapter->getAmountInCents($model);
$this->assertEquals($totalAmountWithTax * 100, $result);
}