From 57483961740d222b92a88ecbaf6ea2a4038b5c8c Mon Sep 17 00:00:00 2001 From: Kennith Leung Date: Fri, 11 Oct 2019 14:06:07 -0700 Subject: [PATCH 1/4] This merge request add partialMock shorthand method Reference: https://github.com/laravel/framework/pull/30202 --- mocking.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mocking.md b/mocking.md index 19696d4a5fe..634304922a9 100644 --- a/mocking.md +++ b/mocking.md @@ -38,6 +38,14 @@ In order to make this more convenient, you may use the `mock` method, which is p $mock->shouldReceive('process')->once(); }); +You may use the `partialMock` method if you only need to mock several methods of an object and leaving the remainder to respond to calls normally. + + use App\Service; + + $this->partialMock(Service::class, function ($mock) { + $mock->shouldReceive('process')->once(); + }); + Similarly, if you want to spy on an object, Laravel's base test case class offers a `spy` method as a convenient wrapper around the `Mockery::spy` method: use App\Service; From 59c6703027f27bacaa7f9ba438dcd59249c42b12 Mon Sep 17 00:00:00 2001 From: Kennith Leung Date: Fri, 11 Oct 2019 14:09:31 -0700 Subject: [PATCH 2/4] Fix description --- mocking.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mocking.md b/mocking.md index 634304922a9..475a1d48bff 100644 --- a/mocking.md +++ b/mocking.md @@ -38,7 +38,7 @@ In order to make this more convenient, you may use the `mock` method, which is p $mock->shouldReceive('process')->once(); }); -You may use the `partialMock` method if you only need to mock several methods of an object and leaving the remainder to respond to calls normally. +You may use the `partialMock` method if you only need to mock several methods of an object and leaving the remainder frees to respond to calls normally. use App\Service; From 97e28a7c98d07634d0143e51ed01c0de61ad1d16 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Mon, 14 Oct 2019 13:51:26 +0200 Subject: [PATCH 3/4] Update mocking.md --- mocking.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mocking.md b/mocking.md index 475a1d48bff..44bb13a58d2 100644 --- a/mocking.md +++ b/mocking.md @@ -43,7 +43,7 @@ You may use the `partialMock` method if you only need to mock several methods of use App\Service; $this->partialMock(Service::class, function ($mock) { - $mock->shouldReceive('process')->once(); + $mock->shouldReceive('process')->once(); }); Similarly, if you want to spy on an object, Laravel's base test case class offers a `spy` method as a convenient wrapper around the `Mockery::spy` method: From 8c4a8a74cae04715c281dd0ed884e30fc8117ece Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 14 Oct 2019 08:14:52 -0500 Subject: [PATCH 4/4] Update mocking.md --- mocking.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mocking.md b/mocking.md index 44bb13a58d2..3960a46292b 100644 --- a/mocking.md +++ b/mocking.md @@ -38,8 +38,8 @@ In order to make this more convenient, you may use the `mock` method, which is p $mock->shouldReceive('process')->once(); }); -You may use the `partialMock` method if you only need to mock several methods of an object and leaving the remainder frees to respond to calls normally. - +You may use the `partialMock` method when you only need to mock a few methods of an object. The methods that are not mocked will be executed normally when called: + use App\Service; $this->partialMock(Service::class, function ($mock) {