From 472953dd930b65922d0c7929ad87c7c6c7d1f0e6 Mon Sep 17 00:00:00 2001 From: Dan Revah Date: Sat, 14 Mar 2015 14:09:18 +0200 Subject: [PATCH] Changed spy name to Partial Mock --- README.md | 14 +++++++------- src/ShortifyPunit.php | 22 +++++++++++++++------- tests/ShortifyPunitTest.php | 10 +++++----- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 5420649..a291e47 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ * [Installation](#installation) * [Mocking](#mocking-examples) * [Stubbing](#stubbing) - * [Spies](#spies) + * [Partial Mock](#partial-mock) * [Stubbing Method Chaining](#stubbing-method-chaining) * [Verifying](#verifying) * [Argument Matcher](#argument-matcher) @@ -66,9 +66,9 @@ Methods: * `returns($response)` - Returns a $response * `callback(function() { /*...*/ })` - Calling a callback -## Spies +## Partial Mock -Spies are a partial mock, sometimes you need some of the methods to behave normally except for the one method that you need to test. That so called partial mocking can be done using the spy method +sometimes you need some of the methods to behave normally except for the one method that you need to test. That so called partial mocking can be done using the partialMock method ```php class Foo { @@ -76,13 +76,13 @@ class Foo { } $mock = ShortifyPunit::mock('Foo'); -$spy = ShortifyPunit::spy('Foo'); +$partialMock = ShortifyPunit::partialMock('Foo'); $mock->bar(); // returns NULL -echo $spy->bar(); // prints 'bar' +echo $partialMock->bar(); // prints 'bar' -ShortifyPunit::when($spy)->bar()->returns('foo'); // stubbing spy -echo $spy->bar(); // prints 'foo' +ShortifyPunit::when($partialMock)->bar()->returns('foo'); // stubbing partialMock +echo $partialMock->bar(); // prints 'foo' ``` ## Stubbing Method Chaining diff --git a/src/ShortifyPunit.php b/src/ShortifyPunit.php index b29e490..b07c9e6 100644 --- a/src/ShortifyPunit.php +++ b/src/ShortifyPunit.php @@ -134,29 +134,29 @@ public static function mock($mockedClass) } /** - * Partial Mocking interfaces|classes + * Partial Mocking interfaces & classes * * @desc Partial mock is not stubbing any function by default (to NULL) like in regular mock() * * Examples: - * // class to partial mock / spy + * // class to partial mock * class Foo { * function bar() { return 'bar'; } * } * * $mock = ShortifyPunit::mock('Foo'); - * $spy = ShortifyPunit::spy('Foo'); + * $partialMock = ShortifyPunit::partialMock('Foo'); * * $mock->bar(); // returns NULL - * echo $spy->bar(); // prints 'bar' + * echo $partialMock->bar(); // prints 'bar' * - * ShortifyPunit::when($spy)->bar()->returns('foo'); // stubbing spy - * echo $spy->bar(); // prints 'foo' + * ShortifyPunit::when($partialMock)->bar()->returns('foo'); // stubbing partial mock + * echo $partialMock->bar(); // prints 'foo' * * @param $mockedClass * @return mixed */ - public static function spy($mockedClass) + public static function partialMock($mockedClass) { $reflection = self::getMockReflection($mockedClass); @@ -168,6 +168,14 @@ public static function spy($mockedClass) ); } + /** + * @deprecated use partialMock($mockedClass) instead + */ + public static function spy($mockedClass) + { + return self::partialMock($mockedClass); + } + /** * Setting up a when case * diff --git a/tests/ShortifyPunitTest.php b/tests/ShortifyPunitTest.php index 925c59c..b33d14b 100644 --- a/tests/ShortifyPunitTest.php +++ b/tests/ShortifyPunitTest.php @@ -345,10 +345,10 @@ public function testMultipleMocking() */ public function testMultipleClassMocking() { - $mockSimple1 = ShortifyPunit::spy('SimpleClassForMocking'); - $mockSimple2 = ShortifyPunit::spy('SimpleClassForMocking'); - $mockFoo1 = ShortifyPunit::spy('Foo'); - $mockFoo2 = ShortifyPunit::spy('Foo'); + $mockSimple1 = ShortifyPunit::partialMock('SimpleClassForMocking'); + $mockSimple2 = ShortifyPunit::partialMock('SimpleClassForMocking'); + $mockFoo1 = ShortifyPunit::partialMock('Foo'); + $mockFoo2 = ShortifyPunit::partialMock('Foo'); ShortifyPunit::when($mockSimple1)->first_method(1)->returns(1); ShortifyPunit::when($mockSimple2)->first_method(1)->returns(2); @@ -366,7 +366,7 @@ public function testMultipleClassMocking() */ public function testSpies() { - $spy = ShortifyPunit::spy('SimpleClassForMocking'); + $spy = ShortifyPunit::partialMock('SimpleClassForMocking'); $this->assertEquals($spy->first_method(), 1); // default value $this->assertEquals($spy->second_method(), 2); // default value