Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 19, 2024
1 parent a806e30 commit 6f86088
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/Framework/MockObject/Runtime/Builder/InvocationMocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public function willReturn(mixed $value, mixed ...$nextValues): self

$stub = $value instanceof Stub ? $value : new ReturnStub($value);

return $this->will($stub);
$this->matcher->setStub($stub);

return $this;
}

$values = array_merge([$value], $nextValues);
Expand All @@ -108,14 +110,18 @@ public function willReturn(mixed $value, mixed ...$nextValues): self

$stub = new ConsecutiveCalls($values);

return $this->will($stub);
$this->matcher->setStub($stub);

return $this;
}

public function willReturnReference(mixed &$reference): self
{
$stub = new ReturnReference($reference);

return $this->will($stub);
$this->matcher->setStub($stub);

return $this;
}

public function willReturnMap(array $valueMap): self
Expand Down Expand Up @@ -158,44 +164,44 @@ public function willReturnMap(array $valueMap): self
$_valueMap[] = $_mapping;
}

$stub = new ReturnValueMap($_valueMap);
$this->matcher->setStub(new ReturnValueMap($_valueMap));

return $this->will($stub);
return $this;
}

public function willReturnArgument(int $argumentIndex): self
{
$stub = new ReturnArgument($argumentIndex);
$this->matcher->setStub(new ReturnArgument($argumentIndex));

return $this->will($stub);
return $this;
}

public function willReturnCallback(callable $callback): self
{
$stub = new ReturnCallback($callback);
$this->matcher->setStub(new ReturnCallback($callback));

return $this->will($stub);
return $this;
}

public function willReturnSelf(): self
{
$stub = new ReturnSelf;
$this->matcher->setStub(new ReturnSelf);

return $this->will($stub);
return $this;
}

public function willReturnOnConsecutiveCalls(mixed ...$values): self
{
$stub = new ConsecutiveCalls($values);
$this->matcher->setStub(new ConsecutiveCalls($values));

return $this->will($stub);
return $this;
}

public function willThrowException(Throwable $exception): self
{
$stub = new Exception($exception);
$this->matcher->setStub(new Exception($exception));

return $this->will($stub);
return $this;
}

/**
Expand Down

0 comments on commit 6f86088

Please sign in to comment.