Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Google\Tests\Task; use Google\Client; use Google\Task\Runner; use Google\..

Decoded Output download

<?php
 namespace Google\Tests\Task; use Google\Client; use Google\Task\Runner; use Google\Tests\BaseTest; use Google\Http\Request as GoogleRequest; use Google\Http\REST; use Google\Service\Exception as ServiceException; use Google\Task\Exception as TaskException; use GuzzleHttp\Psr7; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Prophecy\Argument; use Exception; class RunnerTest extends BaseTest { private $client; private $mockedCallsCount = 0; private $currentMockedCall = 0; private $mockedCalls = array(); private $retryMap; private $retryConfig; public function setUp() : void { $this->client = new Client(); } public function testRestRetryOffByDefault($errorCode, $errorBody = "{}") { $this->expectException(ServiceException::class); $this->setNextResponse($errorCode, $errorBody)->makeRequest(); } public function testOneRestRetryWithError($errorCode, $errorBody = "{}") { $this->expectException(ServiceException::class); $this->setRetryConfig(array("retries" => 1)); $this->setNextResponses(2, $errorCode, $errorBody)->makeRequest(); } public function testMultipleRestRetriesWithErrors($errorCode, $errorBody = "{}") { $this->expectException(ServiceException::class); $this->setRetryConfig(array("retries" => 5)); $this->setNextResponses(6, $errorCode, $errorBody)->makeRequest(); } public function testOneRestRetryWithSuccess($errorCode, $errorBody = "{}") { $this->setRetryConfig(array("retries" => 1)); $result = $this->setNextResponse($errorCode, $errorBody)->setNextResponse(200, "{"success": true}")->makeRequest(); $this->assertEquals("{"success": true}", (string) $result->getBody()); } public function testMultipleRestRetriesWithSuccess($errorCode, $errorBody = "{}") { $this->setRetryConfig(array("retries" => 5)); $result = $this->setNextResponses(2, $errorCode, $errorBody)->setNextResponse(200, "{"success": true}")->makeRequest(); $this->assertEquals("{"success": true}", (string) $result->getBody()); } public function testCustomRestRetryMapReplacesDefaults($errorCode, $errorBody = "{}") { $this->expectException(ServiceException::class); $this->setRetryMap(array()); $this->setRetryConfig(array("retries" => 5)); $this->setNextResponse($errorCode, $errorBody)->makeRequest(); } public function testCustomRestRetryMapAddsNewHandlers() { $this->setRetryMap(array("403" => Runner::TASK_RETRY_ALWAYS)); $this->setRetryConfig(array("retries" => 5)); $result = $this->setNextResponses(2, 403)->setNextResponse(200, "{"success": true}")->makeRequest(); $this->assertEquals("{"success": true}", (string) $result->getBody()); } public function testCustomRestRetryMapWithCustomLimits($limit) { $this->expectException(ServiceException::class); $this->setRetryMap(array("403" => $limit)); $this->setRetryConfig(array("retries" => 5)); $this->setNextResponses($limit + 1, 403)->makeRequest(); } public function testRestTimeouts($config, $minTime) { $this->setRetryConfig($config); $this->setNextResponses($config["retries"], 500)->setNextResponse(200, "{"success": true}"); $this->assertTaskTimeGreaterThanOrEqual($minTime, array($this, "makeRequest"), $config["initial_delay"] / 10); } public function testCurlRetryOffByDefault($errorCode, $errorMessage = '') { $this->expectException(ServiceException::class); $this->setNextResponseThrows($errorMessage, $errorCode)->makeRequest(); } public function testOneCurlRetryWithError($errorCode, $errorMessage = '') { $this->expectException(ServiceException::class); $this->setRetryConfig(array("retries" => 1)); $this->setNextResponsesThrow(2, $errorMessage, $errorCode)->makeRequest(); } public function testMultipleCurlRetriesWithErrors($errorCode, $errorMessage = '') { $this->expectException(ServiceException::class); $this->setRetryConfig(array("retries" => 5)); $this->setNextResponsesThrow(6, $errorMessage, $errorCode)->makeRequest(); } public function testOneCurlRetryWithSuccess($errorCode, $errorMessage = '') { $this->setRetryConfig(array("retries" => 1)); $result = $this->setNextResponseThrows($errorMessage, $errorCode)->setNextResponse(200, "{"success": true}")->makeRequest(); $this->assertEquals("{"success": true}", (string) $result->getBody()); } public function testMultipleCurlRetriesWithSuccess($errorCode, $errorMessage = '') { $this->setRetryConfig(array("retries" => 5)); $result = $this->setNextResponsesThrow(2, $errorMessage, $errorCode)->setNextResponse(200, "{"success": true}")->makeRequest(); $this->assertEquals("{"success": true}", (string) $result->getBody()); } public function testCustomCurlRetryMapReplacesDefaults($errorCode, $errorMessage = '') { $this->expectException(ServiceException::class); $this->setRetryMap(array()); $this->setRetryConfig(array("retries" => 5)); $this->setNextResponseThrows($errorMessage, $errorCode)->makeRequest(); } public function testCustomCurlRetryMapAddsNewHandlers() { $this->setRetryMap(array(CURLE_COULDNT_RESOLVE_PROXY => Runner::TASK_RETRY_ALWAYS)); $this->setRetryConfig(array("retries" => 5)); $result = $this->setNextResponsesThrow(2, '', CURLE_COULDNT_RESOLVE_PROXY)->setNextResponse(200, "{"success": true}")->makeRequest(); $this->assertEquals("{"success": true}", (string) $result->getBody()); } public function testCustomCurlRetryMapWithCustomLimits($limit) { $this->expectException(ServiceException::class); $this->setRetryMap(array(CURLE_COULDNT_RESOLVE_PROXY => $limit)); $this->setRetryConfig(array("retries" => 5)); $this->setNextResponsesThrow($limit + 1, '', CURLE_COULDNT_RESOLVE_PROXY)->makeRequest(); } public function testCurlTimeouts($config, $minTime) { $this->setRetryConfig($config); $this->setNextResponsesThrow($config["retries"], '', CURLE_GOT_NOTHING)->setNextResponse(200, "{"success": true}"); $this->assertTaskTimeGreaterThanOrEqual($minTime, array($this, "makeRequest"), $config["initial_delay"] / 10); } public function testBadTaskConfig($config, $message) { $this->expectException(TaskException::class); $this->expectExceptionMessage($message); $this->setRetryConfig($config); new Runner($this->retryConfig, '', array($this, "testBadTaskConfig")); } public function testBadTaskCallback() { $this->expectException(TaskException::class); $config = array(); new Runner($config, '', 5); } public function testTaskRetryOffByDefault() { $this->expectException(ServiceException::class); $this->setNextTaskAllowedRetries(Runner::TASK_RETRY_ALWAYS)->runTask(); } public function testOneTaskRetryWithError() { $this->expectException(ServiceException::class); $this->setRetryConfig(array("retries" => 1)); $this->setNextTasksAllowedRetries(2, Runner::TASK_RETRY_ALWAYS)->runTask(); } public function testMultipleTaskRetriesWithErrors() { $this->expectException(ServiceException::class); $this->setRetryConfig(array("retries" => 5)); $this->setNextTasksAllowedRetries(6, Runner::TASK_RETRY_ALWAYS)->runTask(); } public function testOneTaskRetryWithSuccess() { $this->setRetryConfig(array("retries" => 1)); $result = $this->setNextTaskAllowedRetries(Runner::TASK_RETRY_ALWAYS)->setNextTaskReturnValue("success")->runTask(); $this->assertEquals("success", $result); } public function testMultipleTaskRetriesWithSuccess() { $this->setRetryConfig(array("retries" => 5)); $result = $this->setNextTasksAllowedRetries(2, Runner::TASK_RETRY_ALWAYS)->setNextTaskReturnValue("success")->runTask(); $this->assertEquals("success", $result); } public function testTaskRetryWithCustomLimits($limit) { $this->expectException(ServiceException::class); $this->setRetryConfig(array("retries" => 5)); $this->setNextTasksAllowedRetries($limit + 1, $limit)->runTask(); } public function testTaskTimeouts($config, $minTime) { $this->setRetryConfig($config); $this->setNextTasksAllowedRetries($config["retries"], $config["retries"] + 1)->setNextTaskReturnValue("success"); $this->assertTaskTimeGreaterThanOrEqual($minTime, array($this, "runTask"), $config["initial_delay"] / 10); } public function testTaskWithManualRetries() { $this->setRetryConfig(array("retries" => 2)); $this->setNextTasksAllowedRetries(2, Runner::TASK_RETRY_ALWAYS); $task = new Runner($this->retryConfig, '', array($this, "runNextTask")); $this->assertTrue($task->canAttempt()); $this->assertTrue($task->attempt()); $this->assertTrue($task->canAttempt()); $this->assertTrue($task->attempt()); $this->assertTrue($task->canAttempt()); $this->assertTrue($task->attempt()); $this->assertFalse($task->canAttempt()); $this->assertFalse($task->attempt()); } public function timeoutProvider() { $config = array("initial_delay" => 0.001, "max_delay" => 0.01); return array(array(array_merge($config, array("retries" => 1)), 0.001), array(array_merge($config, array("retries" => 2)), 0.0015), array(array_merge($config, array("retries" => 3)), 0.00225), array(array_merge($config, array("retries" => 4)), 0.00375), array(array_merge($config, array("retries" => 5)), 0.005625)); } public function customLimitsProvider() { return array(array(Runner::TASK_RETRY_NEVER), array(Runner::TASK_RETRY_ONCE)); } public function badTaskConfigProvider() { return array(array(array("initial_delay" => -1), "must not be negative"), array(array("max_delay" => 0), "must be greater than 0"), array(array("factor" => 0), "must be greater than 0"), array(array("jitter" => 0), "must be greater than 0"), array(array("retries" => -1), "must not be negative")); } public function defaultRestErrorProvider() { return array(array(500), array(503), array(403, "{"error":{"errors":[{"reason":"rateLimitExceeded"}]}}"), array(403, "{"error":{"errors":[{"reason":"userRateLimitExceeded"}]}}")); } public function defaultCurlErrorProvider() { return array(array(6), array(7), array(28), array(35), array(52)); } public static function assertTaskTimeGreaterThanOrEqual($expected, $callback, $delta = 0.0) { $time = microtime(true); call_user_func($callback); self::assertThat(microtime(true) - $time, self::logicalOr(self::greaterThan($expected), self::equalTo($expected, $delta))); } private function setRetryConfig(array $config) { $config += array("initial_delay" => 0.0001, "max_delay" => 0.001, "factor" => 2, "jitter" => 0.5, "retries" => 1); $this->retryConfig = $config; } private function setRetryMap(array $retryMap) { $this->retryMap = $retryMap; } private function setNextResponses($count, $code = "200", $body = "{}", array $headers = array()) { while ($count-- > 0) { $this->setNextResponse($code, $body, $headers); } return $this; } private function setNextResponse($code = "200", $body = "{}", array $headers = array()) { $this->mockedCalls[$this->mockedCallsCount++] = array("code" => (string) $code, "headers" => $headers, "body" => is_string($body) ? $body : json_encode($body)); return $this; } private function setNextResponsesThrow($count, $message, $code) { while ($count-- > 0) { $this->setNextResponseThrows($message, $code); } return $this; } private function setNextResponseThrows($message, $code) { $this->mockedCalls[$this->mockedCallsCount++] = new ServiceException($message, $code, null, array()); return $this; } private function makeRequest() { $request = new Request("GET", "/test"); $http = $this->prophesize("GuzzleHttp\ClientInterface"); $http->send(Argument::type("Psr\Http\Message\RequestInterface"), array())->shouldBeCalledTimes($this->mockedCallsCount)->will(array($this, "getNextMockedCall")); return REST::execute($http->reveal(), $request, '', $this->retryConfig, $this->retryMap); } public function getNextMockedCall($request) { $current = $this->mockedCalls[$this->currentMockedCall++]; if ($current instanceof Exception) { throw $current; } $stream = Psr7\Utils::streamFor($current["body"]); $response = new Response($current["code"], $current["headers"], $stream); return $response; } private function setNextTaskReturnValue($value) { $this->mockedCalls[$this->mockedCallsCount++] = $value; return $this; } private function setNextTaskAllowedRetries($allowedRetries) { $this->mockedCalls[$this->mockedCallsCount++] = $allowedRetries; return $this; } private function setNextTasksAllowedRetries($count, $allowedRetries) { while ($count-- > 0) { $this->setNextTaskAllowedRetries($allowedRetries); } return $this; } private function runTask() { $task = new Runner($this->retryConfig, '', array($this, "runNextTask")); if (null !== $this->retryMap) { $task->setRetryMap($this->retryMap); } $exception = $this->prophesize(ServiceException::class); $exceptionCount = 0; $exceptionCalls = array(); for ($i = 0; $i < $this->mockedCallsCount; $i++) { if (is_int($this->mockedCalls[$i])) { $exceptionCalls[$exceptionCount++] = $this->mockedCalls[$i]; $this->mockedCalls[$i] = $exception->reveal(); } } $task->setRetryMap($exceptionCalls); return $task->run(); } public function runNextTask() { $current = $this->mockedCalls[$this->currentMockedCall++]; if ($current instanceof Exception) { throw $current; } return $current; } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace Google\Tests\Task; use Google\Client; use Google\Task\Runner; use Google\Tests\BaseTest; use Google\Http\Request as GoogleRequest; use Google\Http\REST; use Google\Service\Exception as ServiceException; use Google\Task\Exception as TaskException; use GuzzleHttp\Psr7; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use Prophecy\Argument; use Exception; class RunnerTest extends BaseTest { private $client; private $mockedCallsCount = 0; private $currentMockedCall = 0; private $mockedCalls = array(); private $retryMap; private $retryConfig; public function setUp() : void { $this->client = new Client(); } public function testRestRetryOffByDefault($errorCode, $errorBody = "\173\175") { $this->expectException(ServiceException::class); $this->setNextResponse($errorCode, $errorBody)->makeRequest(); } public function testOneRestRetryWithError($errorCode, $errorBody = "\x7b\175") { $this->expectException(ServiceException::class); $this->setRetryConfig(array("\x72\145\164\x72\151\145\x73" => 1)); $this->setNextResponses(2, $errorCode, $errorBody)->makeRequest(); } public function testMultipleRestRetriesWithErrors($errorCode, $errorBody = "\x7b\175") { $this->expectException(ServiceException::class); $this->setRetryConfig(array("\x72\x65\164\162\x69\x65\163" => 5)); $this->setNextResponses(6, $errorCode, $errorBody)->makeRequest(); } public function testOneRestRetryWithSuccess($errorCode, $errorBody = "\x7b\x7d") { $this->setRetryConfig(array("\x72\x65\x74\162\x69\145\x73" => 1)); $result = $this->setNextResponse($errorCode, $errorBody)->setNextResponse(200, "\x7b\x22\163\x75\143\x63\x65\x73\x73\42\x3a\40\164\x72\x75\x65\175")->makeRequest(); $this->assertEquals("\173\42\163\x75\x63\143\x65\x73\x73\42\72\40\164\x72\165\145\x7d", (string) $result->getBody()); } public function testMultipleRestRetriesWithSuccess($errorCode, $errorBody = "\173\175") { $this->setRetryConfig(array("\x72\x65\164\x72\x69\x65\x73" => 5)); $result = $this->setNextResponses(2, $errorCode, $errorBody)->setNextResponse(200, "\173\x22\x73\x75\x63\x63\145\163\x73\42\72\x20\164\162\165\145\175")->makeRequest(); $this->assertEquals("\173\42\163\165\143\x63\x65\x73\x73\42\x3a\40\164\x72\165\x65\175", (string) $result->getBody()); } public function testCustomRestRetryMapReplacesDefaults($errorCode, $errorBody = "\173\175") { $this->expectException(ServiceException::class); $this->setRetryMap(array()); $this->setRetryConfig(array("\x72\145\164\x72\151\x65\x73" => 5)); $this->setNextResponse($errorCode, $errorBody)->makeRequest(); } public function testCustomRestRetryMapAddsNewHandlers() { $this->setRetryMap(array("\64\60\x33" => Runner::TASK_RETRY_ALWAYS)); $this->setRetryConfig(array("\162\145\164\162\151\x65\x73" => 5)); $result = $this->setNextResponses(2, 403)->setNextResponse(200, "\x7b\42\163\165\143\143\x65\x73\x73\42\72\40\x74\x72\x75\145\175")->makeRequest(); $this->assertEquals("\x7b\42\x73\x75\143\x63\x65\163\x73\42\x3a\x20\164\x72\x75\x65\175", (string) $result->getBody()); } public function testCustomRestRetryMapWithCustomLimits($limit) { $this->expectException(ServiceException::class); $this->setRetryMap(array("\64\60\x33" => $limit)); $this->setRetryConfig(array("\162\x65\164\x72\x69\x65\x73" => 5)); $this->setNextResponses($limit + 1, 403)->makeRequest(); } public function testRestTimeouts($config, $minTime) { $this->setRetryConfig($config); $this->setNextResponses($config["\162\x65\164\x72\151\145\x73"], 500)->setNextResponse(200, "\x7b\x22\x73\x75\x63\x63\x65\163\163\42\72\x20\x74\x72\x75\x65\175"); $this->assertTaskTimeGreaterThanOrEqual($minTime, array($this, "\x6d\141\x6b\x65\x52\145\161\165\x65\163\164"), $config["\151\156\x69\x74\x69\x61\154\137\x64\x65\x6c\141\171"] / 10); } public function testCurlRetryOffByDefault($errorCode, $errorMessage = '') { $this->expectException(ServiceException::class); $this->setNextResponseThrows($errorMessage, $errorCode)->makeRequest(); } public function testOneCurlRetryWithError($errorCode, $errorMessage = '') { $this->expectException(ServiceException::class); $this->setRetryConfig(array("\162\x65\164\x72\x69\x65\163" => 1)); $this->setNextResponsesThrow(2, $errorMessage, $errorCode)->makeRequest(); } public function testMultipleCurlRetriesWithErrors($errorCode, $errorMessage = '') { $this->expectException(ServiceException::class); $this->setRetryConfig(array("\162\x65\164\x72\x69\145\x73" => 5)); $this->setNextResponsesThrow(6, $errorMessage, $errorCode)->makeRequest(); } public function testOneCurlRetryWithSuccess($errorCode, $errorMessage = '') { $this->setRetryConfig(array("\162\145\x74\x72\151\145\163" => 1)); $result = $this->setNextResponseThrows($errorMessage, $errorCode)->setNextResponse(200, "\173\42\163\x75\x63\x63\145\163\x73\42\x3a\x20\x74\x72\x75\145\175")->makeRequest(); $this->assertEquals("\x7b\x22\163\165\x63\143\145\x73\x73\x22\x3a\40\x74\x72\165\x65\175", (string) $result->getBody()); } public function testMultipleCurlRetriesWithSuccess($errorCode, $errorMessage = '') { $this->setRetryConfig(array("\x72\x65\x74\x72\151\x65\x73" => 5)); $result = $this->setNextResponsesThrow(2, $errorMessage, $errorCode)->setNextResponse(200, "\173\42\163\x75\x63\143\x65\163\163\42\72\x20\164\x72\165\145\175")->makeRequest(); $this->assertEquals("\173\x22\163\165\x63\x63\145\163\x73\42\x3a\x20\x74\162\165\145\175", (string) $result->getBody()); } public function testCustomCurlRetryMapReplacesDefaults($errorCode, $errorMessage = '') { $this->expectException(ServiceException::class); $this->setRetryMap(array()); $this->setRetryConfig(array("\162\145\x74\162\x69\x65\163" => 5)); $this->setNextResponseThrows($errorMessage, $errorCode)->makeRequest(); } public function testCustomCurlRetryMapAddsNewHandlers() { $this->setRetryMap(array(CURLE_COULDNT_RESOLVE_PROXY => Runner::TASK_RETRY_ALWAYS)); $this->setRetryConfig(array("\x72\x65\164\x72\x69\145\x73" => 5)); $result = $this->setNextResponsesThrow(2, '', CURLE_COULDNT_RESOLVE_PROXY)->setNextResponse(200, "\x7b\x22\163\x75\143\x63\145\163\x73\x22\x3a\40\x74\162\x75\x65\x7d")->makeRequest(); $this->assertEquals("\173\42\x73\165\x63\143\145\x73\x73\x22\72\x20\x74\x72\165\145\175", (string) $result->getBody()); } public function testCustomCurlRetryMapWithCustomLimits($limit) { $this->expectException(ServiceException::class); $this->setRetryMap(array(CURLE_COULDNT_RESOLVE_PROXY => $limit)); $this->setRetryConfig(array("\162\x65\x74\x72\x69\x65\163" => 5)); $this->setNextResponsesThrow($limit + 1, '', CURLE_COULDNT_RESOLVE_PROXY)->makeRequest(); } public function testCurlTimeouts($config, $minTime) { $this->setRetryConfig($config); $this->setNextResponsesThrow($config["\x72\145\x74\x72\x69\145\x73"], '', CURLE_GOT_NOTHING)->setNextResponse(200, "\173\42\x73\165\143\143\x65\163\163\x22\x3a\40\x74\x72\165\145\175"); $this->assertTaskTimeGreaterThanOrEqual($minTime, array($this, "\x6d\141\153\x65\x52\x65\161\x75\145\163\164"), $config["\151\156\x69\x74\x69\x61\154\x5f\144\145\154\141\x79"] / 10); } public function testBadTaskConfig($config, $message) { $this->expectException(TaskException::class); $this->expectExceptionMessage($message); $this->setRetryConfig($config); new Runner($this->retryConfig, '', array($this, "\164\145\163\x74\102\141\144\x54\141\x73\x6b\x43\157\x6e\x66\x69\x67")); } public function testBadTaskCallback() { $this->expectException(TaskException::class); $config = array(); new Runner($config, '', 5); } public function testTaskRetryOffByDefault() { $this->expectException(ServiceException::class); $this->setNextTaskAllowedRetries(Runner::TASK_RETRY_ALWAYS)->runTask(); } public function testOneTaskRetryWithError() { $this->expectException(ServiceException::class); $this->setRetryConfig(array("\162\145\164\162\x69\145\x73" => 1)); $this->setNextTasksAllowedRetries(2, Runner::TASK_RETRY_ALWAYS)->runTask(); } public function testMultipleTaskRetriesWithErrors() { $this->expectException(ServiceException::class); $this->setRetryConfig(array("\162\x65\164\162\x69\x65\x73" => 5)); $this->setNextTasksAllowedRetries(6, Runner::TASK_RETRY_ALWAYS)->runTask(); } public function testOneTaskRetryWithSuccess() { $this->setRetryConfig(array("\162\145\164\x72\x69\145\x73" => 1)); $result = $this->setNextTaskAllowedRetries(Runner::TASK_RETRY_ALWAYS)->setNextTaskReturnValue("\163\165\143\x63\x65\x73\163")->runTask(); $this->assertEquals("\163\x75\143\143\x65\163\163", $result); } public function testMultipleTaskRetriesWithSuccess() { $this->setRetryConfig(array("\x72\145\164\162\151\x65\163" => 5)); $result = $this->setNextTasksAllowedRetries(2, Runner::TASK_RETRY_ALWAYS)->setNextTaskReturnValue("\x73\x75\x63\x63\145\x73\x73")->runTask(); $this->assertEquals("\163\x75\143\x63\145\x73\x73", $result); } public function testTaskRetryWithCustomLimits($limit) { $this->expectException(ServiceException::class); $this->setRetryConfig(array("\x72\x65\x74\162\151\x65\x73" => 5)); $this->setNextTasksAllowedRetries($limit + 1, $limit)->runTask(); } public function testTaskTimeouts($config, $minTime) { $this->setRetryConfig($config); $this->setNextTasksAllowedRetries($config["\162\x65\164\x72\151\145\163"], $config["\162\x65\x74\x72\151\145\x73"] + 1)->setNextTaskReturnValue("\163\x75\143\x63\145\x73\x73"); $this->assertTaskTimeGreaterThanOrEqual($minTime, array($this, "\x72\165\x6e\x54\x61\163\153"), $config["\151\156\151\164\x69\x61\154\x5f\x64\145\x6c\141\171"] / 10); } public function testTaskWithManualRetries() { $this->setRetryConfig(array("\162\x65\164\x72\x69\145\x73" => 2)); $this->setNextTasksAllowedRetries(2, Runner::TASK_RETRY_ALWAYS); $task = new Runner($this->retryConfig, '', array($this, "\x72\x75\x6e\x4e\145\x78\x74\x54\x61\163\x6b")); $this->assertTrue($task->canAttempt()); $this->assertTrue($task->attempt()); $this->assertTrue($task->canAttempt()); $this->assertTrue($task->attempt()); $this->assertTrue($task->canAttempt()); $this->assertTrue($task->attempt()); $this->assertFalse($task->canAttempt()); $this->assertFalse($task->attempt()); } public function timeoutProvider() { $config = array("\151\156\151\x74\151\141\154\137\x64\145\154\141\171" => 0.001, "\155\x61\x78\x5f\144\145\x6c\141\x79" => 0.01); return array(array(array_merge($config, array("\x72\145\164\x72\x69\x65\163" => 1)), 0.001), array(array_merge($config, array("\x72\145\x74\x72\x69\145\163" => 2)), 0.0015), array(array_merge($config, array("\162\145\x74\162\151\x65\163" => 3)), 0.00225), array(array_merge($config, array("\x72\x65\164\x72\151\x65\x73" => 4)), 0.00375), array(array_merge($config, array("\x72\x65\x74\x72\151\x65\x73" => 5)), 0.005625)); } public function customLimitsProvider() { return array(array(Runner::TASK_RETRY_NEVER), array(Runner::TASK_RETRY_ONCE)); } public function badTaskConfigProvider() { return array(array(array("\x69\x6e\151\164\x69\141\154\x5f\x64\x65\154\x61\x79" => -1), "\x6d\x75\x73\x74\x20\156\x6f\x74\x20\x62\145\x20\156\145\147\x61\x74\x69\x76\x65"), array(array("\155\x61\170\x5f\144\145\x6c\x61\171" => 0), "\x6d\165\163\164\40\142\145\40\147\162\x65\141\x74\x65\x72\x20\164\150\141\x6e\x20\60"), array(array("\146\141\x63\164\157\x72" => 0), "\x6d\165\163\164\x20\x62\x65\x20\147\162\x65\x61\x74\145\162\40\x74\x68\141\x6e\x20\x30"), array(array("\x6a\x69\164\x74\x65\162" => 0), "\x6d\x75\163\164\40\142\x65\x20\147\162\x65\x61\x74\145\x72\x20\164\150\141\156\40\60"), array(array("\162\x65\164\x72\x69\145\x73" => -1), "\x6d\165\x73\164\40\x6e\x6f\x74\x20\142\x65\x20\x6e\145\147\141\164\x69\166\145")); } public function defaultRestErrorProvider() { return array(array(500), array(503), array(403, "\173\x22\145\x72\162\x6f\x72\x22\x3a\173\x22\145\162\x72\157\x72\x73\x22\72\133\x7b\x22\162\x65\x61\163\x6f\x6e\42\72\42\x72\141\164\x65\114\151\x6d\x69\x74\105\x78\x63\x65\145\144\x65\x64\x22\175\135\x7d\x7d"), array(403, "\173\42\x65\162\x72\x6f\162\42\72\x7b\42\x65\x72\x72\x6f\x72\163\42\x3a\x5b\x7b\x22\x72\x65\x61\x73\157\156\x22\72\42\x75\163\x65\x72\122\141\x74\x65\114\151\155\151\164\105\x78\143\x65\x65\x64\x65\x64\x22\175\x5d\175\x7d")); } public function defaultCurlErrorProvider() { return array(array(6), array(7), array(28), array(35), array(52)); } public static function assertTaskTimeGreaterThanOrEqual($expected, $callback, $delta = 0.0) { $time = microtime(true); call_user_func($callback); self::assertThat(microtime(true) - $time, self::logicalOr(self::greaterThan($expected), self::equalTo($expected, $delta))); } private function setRetryConfig(array $config) { $config += array("\151\x6e\x69\x74\151\x61\154\137\144\145\154\141\x79" => 0.0001, "\x6d\141\170\137\x64\145\x6c\141\x79" => 0.001, "\146\x61\143\x74\x6f\x72" => 2, "\152\151\x74\164\x65\x72" => 0.5, "\x72\145\x74\162\x69\145\x73" => 1); $this->retryConfig = $config; } private function setRetryMap(array $retryMap) { $this->retryMap = $retryMap; } private function setNextResponses($count, $code = "\62\x30\x30", $body = "\173\x7d", array $headers = array()) { while ($count-- > 0) { $this->setNextResponse($code, $body, $headers); } return $this; } private function setNextResponse($code = "\62\60\60", $body = "\x7b\175", array $headers = array()) { $this->mockedCalls[$this->mockedCallsCount++] = array("\143\x6f\x64\x65" => (string) $code, "\150\145\x61\x64\x65\162\x73" => $headers, "\142\157\144\x79" => is_string($body) ? $body : json_encode($body)); return $this; } private function setNextResponsesThrow($count, $message, $code) { while ($count-- > 0) { $this->setNextResponseThrows($message, $code); } return $this; } private function setNextResponseThrows($message, $code) { $this->mockedCalls[$this->mockedCallsCount++] = new ServiceException($message, $code, null, array()); return $this; } private function makeRequest() { $request = new Request("\107\x45\124", "\x2f\164\x65\163\x74"); $http = $this->prophesize("\107\x75\172\172\154\x65\110\164\164\x70\134\103\154\151\145\x6e\x74\x49\x6e\x74\x65\x72\146\x61\x63\x65"); $http->send(Argument::type("\120\163\x72\x5c\110\164\x74\x70\x5c\115\145\x73\163\x61\147\145\x5c\122\x65\x71\165\145\163\164\x49\x6e\164\145\x72\x66\141\143\145"), array())->shouldBeCalledTimes($this->mockedCallsCount)->will(array($this, "\147\x65\x74\116\145\170\164\x4d\157\143\153\145\144\x43\x61\154\x6c")); return REST::execute($http->reveal(), $request, '', $this->retryConfig, $this->retryMap); } public function getNextMockedCall($request) { $current = $this->mockedCalls[$this->currentMockedCall++]; if ($current instanceof Exception) { throw $current; } $stream = Psr7\Utils::streamFor($current["\x62\x6f\144\x79"]); $response = new Response($current["\143\157\144\x65"], $current["\150\x65\141\144\x65\x72\163"], $stream); return $response; } private function setNextTaskReturnValue($value) { $this->mockedCalls[$this->mockedCallsCount++] = $value; return $this; } private function setNextTaskAllowedRetries($allowedRetries) { $this->mockedCalls[$this->mockedCallsCount++] = $allowedRetries; return $this; } private function setNextTasksAllowedRetries($count, $allowedRetries) { while ($count-- > 0) { $this->setNextTaskAllowedRetries($allowedRetries); } return $this; } private function runTask() { $task = new Runner($this->retryConfig, '', array($this, "\162\x75\156\116\145\x78\x74\124\x61\x73\x6b")); if (null !== $this->retryMap) { $task->setRetryMap($this->retryMap); } $exception = $this->prophesize(ServiceException::class); $exceptionCount = 0; $exceptionCalls = array(); for ($i = 0; $i < $this->mockedCallsCount; $i++) { if (is_int($this->mockedCalls[$i])) { $exceptionCalls[$exceptionCount++] = $this->mockedCalls[$i]; $this->mockedCalls[$i] = $exception->reveal(); } } $task->setRetryMap($exceptionCalls); return $task->run(); } public function runNextTask() { $current = $this->mockedCalls[$this->currentMockedCall++]; if ($current instanceof Exception) { throw $current; } return $current; } }

Function Calls

None

Variables

None

Stats

MD5 ead7db0e674acfe689f604d8aaed13ab
Eval Count 0
Decode Time 88 ms