Skip to content

Commit

Permalink
refactor: FFI client hide call() method
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Sep 28, 2024
1 parent 32ccb7a commit fe463e1
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 32 deletions.
19 changes: 0 additions & 19 deletions helper/FFI/ClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,6 @@ trait ClientTrait
{
protected ClientInterface&MockObject $client;

/**
* @param mixed[][] $calls
*/
protected function assertClientCalls(array $calls): void
{
$this->client
->expects($this->exactly(count($calls)))
->method('call')
->willReturnCallback(function (...$args) use (&$calls) {
$call = array_shift($calls);
$return = array_pop($call);
foreach ($args as $key => $arg) {
$this->assertThat($arg, $call[$key] instanceof Constraint ? $call[$key] : new IsIdentical($call[$key]));
}

return $return;
});
}

protected function expectsSetInteractionKey(int $interaction, string $description, ?string $key, bool $result): void
{
$this->client
Expand Down
2 changes: 1 addition & 1 deletion src/PhpPact/FFI/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ private function getEnum(string $name): int
return $value;
}

public function call(string $name, ...$arguments): mixed
private function call(string $name, mixed ...$arguments): mixed
{
return $this->ffi->{$name}(...$arguments);
}
Expand Down
5 changes: 0 additions & 5 deletions src/PhpPact/FFI/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,4 @@ public function getPactSpecificationV3(): int;
public function getPactSpecificationV4(): int;

public function getPactSpecificationUnknown(): int;

/**
* @param array<int, mixed> $arguments
*/
public function call(string $name, ...$arguments): mixed;
}
7 changes: 0 additions & 7 deletions tests/PhpPact/FFI/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,4 @@ public function testGetPactSpecificationUnknown(): void
{
$this->assertSame(0, $this->client->getPactSpecificationUnknown());
}

#[TestWith(['abc123', true])]
#[TestWith(['testing', false])]
public function testCall(string $example, bool $result): void
{
$this->assertSame($result, $this->client->call('pactffi_check_regex', '\w{3}\d+', $example));
}
}

0 comments on commit fe463e1

Please sign in to comment.