From b48238fc9aefb8b8215c5c08d151f1ca8ad10753 Mon Sep 17 00:00:00 2001 From: Titas Gailius Date: Mon, 30 Mar 2020 10:35:52 +0200 Subject: [PATCH] Fix Builder Proxy (#6) --- src/Builder.php | 4 ++-- tests/BuilderTest.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Builder.php b/src/Builder.php index 89a7ff8..5a91daf 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -394,8 +394,8 @@ public function __call(string $method, array $parameters) return static::$extensions[$method]($this); } - if (method_exists($this->process(), $method)) { - return $this->process()->{$method}(...$parameters); + if (method_exists($process = $this->process(), $method)) { + return $process->{$method}(...$parameters); } throw new BadMethodCallException(sprintf( diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index 330444a..9dfcf26 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -226,6 +226,22 @@ public function testDataWithMissingBinding() $this->assertEquals("Hello, \n", $process->getOutput()); } + /** + * Test that missing methods are passed to the Proccess instance. + * + * @return void + */ + public function testBuilderProxy() + { + $builder = $this->builderWithMockedProccess(function ($mock) { + $mock->shouldReceive('getPid') + ->once() + ->andReturn(123); + }); + + $this->assertEquals(123, $builder->getPid()); + } + /** * Create a new builder instance with a mocked process instance. *