No Description

SimpleSubscriberTest.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /*
  3. * Copyright 2010 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. namespace Google\Auth\Tests;
  18. use Google\Auth\Subscriber\SimpleSubscriber;
  19. use GuzzleHttp\Client;
  20. use GuzzleHttp\Event\BeforeEvent;
  21. use GuzzleHttp\Transaction;
  22. class SimpleSubscriberTest extends BaseTest
  23. {
  24. protected function setUp()
  25. {
  26. $this->onlyGuzzle5();
  27. }
  28. /**
  29. * @expectedException InvalidArgumentException
  30. */
  31. public function testRequiresADeveloperKey()
  32. {
  33. new SimpleSubscriber(['not_key' => 'a test key']);
  34. }
  35. public function testSubscribesToEvents()
  36. {
  37. $events = (new SimpleSubscriber(['key' => 'a test key']))->getEvents();
  38. $this->assertArrayHasKey('before', $events);
  39. }
  40. public function testAddsTheKeyToTheQuery()
  41. {
  42. $s = new SimpleSubscriber(['key' => 'test_key']);
  43. $client = new Client();
  44. $request = $client->createRequest('GET', 'http://testing.org',
  45. ['auth' => 'simple']);
  46. $before = new BeforeEvent(new Transaction($client, $request));
  47. $s->onBefore($before);
  48. $this->assertCount(1, $request->getQuery());
  49. $this->assertTrue($request->getQuery()->hasKey('key'));
  50. $this->assertSame($request->getQuery()->get('key'), 'test_key');
  51. }
  52. public function testOnlyTouchesWhenAuthConfigIsSimple()
  53. {
  54. $s = new SimpleSubscriber(['key' => 'test_key']);
  55. $client = new Client();
  56. $request = $client->createRequest('GET', 'http://testing.org',
  57. ['auth' => 'notsimple']);
  58. $before = new BeforeEvent(new Transaction($client, $request));
  59. $s->onBefore($before);
  60. $this->assertCount(0, $request->getQuery());
  61. }
  62. }