skip to Main Content

i want to test an api-client. the api-client uses IlluminateSupportFacadesHttp to make requests. when i use it in tinker everything is ok:

> $response = Bitwarden::listItems()
= IlluminateSupportCollection {#6782
    all: [
      {#6854
        +"object": "item",
       ....
      },
    ],
  }

My test looks like this:

it('can list the items', function () {
   $response = Bitwarden::listItems();
   expect($response)->toBeArray();
});

and result is

 FAILED  TestsBitwardenCliTest > it can list the items                              Error   
  Class "GuzzleHttpHandlerStack" not found

  at vendor/laravel/framework/src/Illuminate/Http/Client/PendingRequest.php:1145
    1141▕      * @return GuzzleHttpHandlerStack
    1142▕      */
    1143▕     public function buildHandlerStack()
    1144▕     {
  ➜ 1145▕         return $this->pushHandlers(HandlerStack::create($this->handler));
    1146▕     }
    1147▕ 
    1148▕     /**
    1149▕      * Add the necessary handlers to the given handler stack.

i guess i missed something in setting up pest. please give me a hint. thx 🙂

i want the client to work in test like it does in tinker

2

Answers



  1. The error message "Class ‘GuzzleHttpHandlerStack’ not found" typically indicates that Laravel Pest is unable to find the HandlerStack class from the Guzzle HTTP client library. To resolve this issue, you can follow these steps:

    Install Guzzle HTTP Client:

    Ensure that you have Guzzle HTTP Client installed as a dependency in your Laravel project. You can install it using Composer:

    composer require guzzlehttp/guzzle

    Make sure you see Guzzle in your composer.json file’s require section.

    Check Composer Autoloading:

    Laravel should automatically load the Guzzle HTTP client through Composer’s autoloading. However, it’s a good practice to run composer dump-autoload to refresh the autoloader:

    composer dump-autoload

    Verify Pest Configuration:

    Verify that your Pest tests are set up correctly. Ensure that you’ve imported Pest at the beginning of your test file:

    use PestTestingTestCase;

    Check for Namespace Issues:

    Ensure that you are using the correct namespaces for Guzzle and Pest. Your test file should start with Pest’s namespace declaration, and if you’re using Guzzle within your test, make sure you import it correctly:

    namespace TestsUnit;

    use PestTestingTestCase;
    use GuzzleHttpHandlerStack; // Make sure this is imported

    // Your test code here

    Update Pest and Laravel:

    Ensure that you are using the latest versions of Pest and Laravel. Update your packages:

    composer update

    Clear Caches:

    Sometimes, Laravel’s cache can cause issues. Clear your configuration cache and other caches:

    php artisan config:clear
    php artisan cache:clear

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search