auth0 / auth0-PHP

PHP SDK for Auth0 Authentication and Management APIs.
https://auth0.com/docs/libraries/auth0-php
MIT License
380 stars 209 forks source link

Callback never called #768

Closed midnite81 closed 1 month ago

midnite81 commented 1 month ago

Checklist

SDK Version

Other (specify below)

PHP Version

Other (specify below)

Description

SDK version: auth0/auth0-php 8.11.1 PHP SDK for Auth0 Authentication and Management APIs. PHP version: PHP 8.3.9

In this file, src/Utility/HttpRequest.php, it checks to see if a method exists on the $mockedResponse object but it's not a method, it's a property, so this will always return false. I am happy to create a PR for this but I wanted just to make sure I wasn't doing something wrong in the first place.

From: src/Utility/HttpRequest.php

 if ($mockedResponse && method_exists($mockedResponse, 'callback') && is_callable($mockedResponse->callback)) { // @phpstan-ignore-line
                ($mockedResponse->callback)($httpRequest, $httpResponse);
            }

How can we reproduce this issue?

If you create a mock, you'll find the closure is never run. For example;

   $service->getHttpClient()->mockResponse(
            $this->createResponseInterface(),
            function ($request) {
                $this->assertEquals('/api/v2/users', $request->getUri()->getPath());
            }
        );
evansims commented 1 month ago

Thanks for reporting and patching this, @midnite81! The contribution is much appreciated.