GoutteDriver.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. * This file is part of the Behat\Mink.
  4. * (c) Konstantin Kudryashov <ever.zet@gmail.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace Behat\Mink\Driver;
  10. use Behat\Mink\Driver\Goutte\Client as ExtendedClient;
  11. use Goutte\Client;
  12. /**
  13. * Goutte driver.
  14. *
  15. * @author Konstantin Kudryashov <ever.zet@gmail.com>
  16. */
  17. class GoutteDriver extends BrowserKitDriver
  18. {
  19. /**
  20. * Initializes Goutte driver.
  21. *
  22. * @param Client $client Goutte client instance
  23. */
  24. public function __construct(Client $client = null)
  25. {
  26. parent::__construct($client ?: new ExtendedClient());
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function setBasicAuth($user, $password)
  32. {
  33. if (false === $user) {
  34. $this->getClient()->resetAuth();
  35. return;
  36. }
  37. $this->getClient()->setAuth($user, $password);
  38. }
  39. /**
  40. * Gets the Goutte client.
  41. *
  42. * The method is overwritten only to provide the appropriate return type hint.
  43. *
  44. * @return Client
  45. */
  46. public function getClient()
  47. {
  48. return parent::getClient();
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function reset()
  54. {
  55. parent::reset();
  56. $this->getClient()->resetAuth();
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. protected function prepareUrl($url)
  62. {
  63. return $url;
  64. }
  65. }