Skip to content

Commit

Permalink
Fix getResolved that were converting the underlying array to array (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaconnier authored Oct 26, 2023
1 parent 0c5a1c5 commit 0f1c41b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/HttpPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getResolved(): array
{
return collect($this->getResponses())
->map(fn (Response $response, $key) => $this->pool[$key]->handlePromiseResolved($response))
->toArray();
->all();
}

/** @return array<array-key, Response> */
Expand Down
16 changes: 15 additions & 1 deletion tests/HttpPoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class HttpPoolTest extends TestCase
{
protected HttpPool $httpPool;

protected CustomTestRepository $customTestRepository;

public function setUp(): void
Expand All @@ -20,7 +21,6 @@ public function setUp(): void
$this->customTestRepository = new CustomTestRepository();
}


/** @test */
public function it_executes_the_callback(): void
{
Expand Down Expand Up @@ -144,4 +144,18 @@ public function it_create_async_requests(): void
$this->assertInstanceOf(PromiseInterface::class, $pendingRequest?->getPromise());
}

/** @test */
public function it_preserve_the_data(): void
{
Http::fake();

$expected = collect();

$results = $this->httpPool->runAsync([
$this->customTestRepository->async(fn (CustomTestRepository $repository) => $repository->getAsyncWithCallback($expected)),
])->getResolved();

$this->assertSame($expected, $results[0]);
}

}

0 comments on commit 0f1c41b

Please sign in to comment.