Sin descripción

bootstrap.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * Copyright 2015 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. error_reporting(E_ALL | E_STRICT);
  18. require dirname(__DIR__) . '/vendor/autoload.php';
  19. date_default_timezone_set('UTC');
  20. // autoload base test
  21. require_once __DIR__ . '/BaseTest.php';
  22. function buildResponse($code, array $headers = [], $body = null)
  23. {
  24. if (class_exists('GuzzleHttp\HandlerStack')) {
  25. return new \GuzzleHttp\Psr7\Response($code, $headers, $body);
  26. }
  27. return new \GuzzleHttp\Message\Response(
  28. $code,
  29. $headers,
  30. \GuzzleHttp\Stream\Stream::factory((string)$body)
  31. );
  32. }
  33. function getHandler(array $mockResponses = [])
  34. {
  35. if (class_exists('GuzzleHttp\HandlerStack')) {
  36. $mock = new \GuzzleHttp\Handler\MockHandler($mockResponses);
  37. $handler = \GuzzleHttp\HandlerStack::create($mock);
  38. $client = new \GuzzleHttp\Client(['handler' => $handler]);
  39. return new \Google\Auth\HttpHandler\Guzzle6HttpHandler($client);
  40. }
  41. $client = new \GuzzleHttp\Client();
  42. $client->getEmitter()->attach(
  43. new \GuzzleHttp\Subscriber\Mock($mockResponses)
  44. );
  45. return new \Google\Auth\HttpHandler\Guzzle5HttpHandler($client);
  46. }