Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@markwalet
Copy link
Contributor

@markwalet markwalet commented Feb 27, 2025

Unfortunately, #424 (released in v3.11.0) introduced a breaking change in my testsuite:

Saloon::fake([
    MockResponse::make(['data' => ['shipmentKey' => 'ABC123']]),
    MockResponse::make(['data' => ['shipmentKey' => 'ABC123']]),
]);

/// ... Send requests

Saloon::assertSent(fn (GetShipmentKeyRequest $request) => $request->orderItem === 123); // Working
Saloon::assertSent(fn (GetShipmentKeyRequest $request) => $request->orderItem === 234); // Failing

The new logic only looks for the first match in the list of pending requests. But later in the code, we can see it is always looping through all requests to see if any of them match. I've copied over this behaviour to the class typehinted assertion.

Adjusted the tests accordingly. Is there a chance we can get this patched in? Thanks in advance and keep up the good work! 🚀

@Sammyjo20
Copy link
Member

I'm so sorry @markwalet! I'll roll this one out, thank you for finding this.

@Sammyjo20 Sammyjo20 merged commit cbb1d7e into saloonphp:v3 Feb 28, 2025
17 of 18 checks passed
@relaypilot
Copy link

This update broke my "requests" tests. I'll circle if I can find the issue.

Tests\Unit\Http\Services\Prestashop\Requests\SearchProductTest::test_endpoint_can_be_resolved
An expected request was not sent.
Failed asserting that false is true.

/home/runner/work/mywebsite/vendor/saloonphp/saloon/src/Http/Faking/MockClient.php:249
    public function test_endpoint_can_be_resolved(): void
    {
        $mockClient = Saloon::fake([
            SearchProduct::class => MockResponse::fixture('prestashop/SearchProduct'),
        ]);

        $response = $this->connector->send($this->searchProduct);

        $mockClient->assertSent(SearchProduct::class);
        $mockClient->assertSent('/products');
        $mockClient->assertSent(function (Request $request, Response $response) {
            return $request instanceof SearchProduct;
        });

        $this->assertEquals(200, $response->status());
    }

@Sammyjo20
Copy link
Member

I'm going to revert both PRs that caused the issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants