From d72fcea8e5023996f7681994658ec7ed4cbbe986 Mon Sep 17 00:00:00 2001 From: eparusov Date: Wed, 11 Dec 2024 12:50:22 +0300 Subject: [PATCH] #145: Fix bug with empty arguments --- src/Traits/MockTrait.php | 4 ++-- tests/MockTraitTest.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Traits/MockTrait.php b/src/Traits/MockTrait.php index 36585ab..b1f5442 100644 --- a/src/Traits/MockTrait.php +++ b/src/Traits/MockTrait.php @@ -58,7 +58,7 @@ public function mockClass(string $class, array $callChain, bool $disableConstruc $callIndex = $this->getInvocationCount($matcher) - 1; $expectedCall = $calls[$callIndex]; - $expectedArguments = Arr::get($expectedCall, 'arguments'); + $expectedArguments = Arr::get($expectedCall, 'arguments', []); $this->assertArguments( $args, @@ -107,7 +107,7 @@ public function mockNativeFunction(string $namespace, array $callChain) $callIndex = $this->getInvocationCount($matcher) - 1; $expectedCall = $calls[$callIndex]; - $expectedArguments = Arr::get($expectedCall, 'arguments'); + $expectedArguments = Arr::get($expectedCall, 'arguments', []); $this->assertArguments( $args, diff --git a/tests/MockTraitTest.php b/tests/MockTraitTest.php index b182adb..5d2a248 100644 --- a/tests/MockTraitTest.php +++ b/tests/MockTraitTest.php @@ -47,6 +47,7 @@ public function testMockWithDifferentFunction() $this->functionCall('is_array', [123]), $this->functionCall('rand', [6, 10], 7), $this->functionCall('uniqid', [], '0987654321'), + $this->functionCall(name: 'uniqid', result: '0987654321'), $this->functionCall('array_slice', [[1, 2, 3, 4, 5], 2, 2], [3, 4]), $this->functionCall('array_slice', [[1, 2, 3, 4, 5], 2], [3, 4, 5]), ]); @@ -55,6 +56,7 @@ public function testMockWithDifferentFunction() $this->assertTrue(is_array(123)); $this->assertEquals(7, rand(6, 10)); $this->assertEquals('0987654321', uniqid()); + $this->assertEquals('0987654321', uniqid()); $this->assertEquals([3, 4], array_slice([1, 2, 3, 4, 5], 2, 2)); $this->assertEquals([3, 4, 5], array_slice([1, 2, 3, 4, 5], 2)); }