| @@ 5-30 (lines=26) @@ | ||
| 2 | ||
| 3 | namespace Amock\MockMethod; |
|
| 4 | ||
| 5 | class ArrayReturn extends Handler |
|
| 6 | { |
|
| 7 | public function handle(): bool |
|
| 8 | { |
|
| 9 | if (!$this->canHandle()) { |
|
| 10 | return false; |
|
| 11 | } |
|
| 12 | ||
| 13 | $this->initialStub |
|
| 14 | ->method($this->methodName) |
|
| 15 | ->willReturn($this->returnLiteral()); |
|
| 16 | ||
| 17 | return true; |
|
| 18 | } |
|
| 19 | ||
| 20 | private function canHandle(): bool |
|
| 21 | { |
|
| 22 | return is_string($this->methodMockConfig) |
|
| 23 | && substr($this->methodMockConfig, 0, 7) === '@array:'; |
|
| 24 | } |
|
| 25 | ||
| 26 | private function returnLiteral() |
|
| 27 | { |
|
| 28 | return json_decode(substr($this->methodMockConfig, 7), true); |
|
| 29 | } |
|
| 30 | } |
|
| 31 | ||
| @@ 5-30 (lines=26) @@ | ||
| 2 | ||
| 3 | namespace Amock\MockMethod; |
|
| 4 | ||
| 5 | class IntegerReturn extends Handler |
|
| 6 | { |
|
| 7 | public function handle(): bool |
|
| 8 | { |
|
| 9 | if (!$this->canHandle()) { |
|
| 10 | return false; |
|
| 11 | } |
|
| 12 | ||
| 13 | $this->initialStub |
|
| 14 | ->method($this->methodName) |
|
| 15 | ->willReturn($this->returnValue()); |
|
| 16 | ||
| 17 | return true; |
|
| 18 | } |
|
| 19 | ||
| 20 | private function canHandle(): bool |
|
| 21 | { |
|
| 22 | return is_string($this->methodMockConfig) |
|
| 23 | && substr($this->methodMockConfig, 0, 9) === '@integer:'; |
|
| 24 | } |
|
| 25 | ||
| 26 | private function returnValue(): int |
|
| 27 | { |
|
| 28 | return intval(substr($this->methodMockConfig, 9)); |
|
| 29 | } |
|
| 30 | } |
|
| 31 | ||
| @@ 5-30 (lines=26) @@ | ||
| 2 | ||
| 3 | namespace Amock\MockMethod; |
|
| 4 | ||
| 5 | class StringReturn extends Handler |
|
| 6 | { |
|
| 7 | public function handle(): bool |
|
| 8 | { |
|
| 9 | if (!$this->canHandle()) { |
|
| 10 | return false; |
|
| 11 | } |
|
| 12 | ||
| 13 | $this->initialStub |
|
| 14 | ->method($this->methodName) |
|
| 15 | ->willReturn($this->returnValue()); |
|
| 16 | ||
| 17 | return true; |
|
| 18 | } |
|
| 19 | ||
| 20 | private function canHandle(): bool |
|
| 21 | { |
|
| 22 | return is_string($this->methodMockConfig) |
|
| 23 | && substr($this->methodMockConfig, 0, 8) === '@string:'; |
|
| 24 | } |
|
| 25 | ||
| 26 | private function returnValue(): string |
|
| 27 | { |
|
| 28 | return substr($this->methodMockConfig, 8); |
|
| 29 | } |
|
| 30 | } |
|
| 31 | ||