From 81e50918ff87a7ba4ace151c512d974dca0d5d4d Mon Sep 17 00:00:00 2001 From: Payton Swick Date: Fri, 17 Feb 2017 10:35:09 -0500 Subject: [PATCH] Save SpyCall object arguments by reference Reverts changes made in [v1.4.1](https://github.com/sirbrillig/spies/commit/92de74cb8d4d60b5da1beda95fb9479457e95d52) and [v1.5.1](https://github.com/sirbrillig/spies/commit/b3ee2e2e13cc14487cdba16a804167943cedfa57) as I think I was wrong to copy objects. Objects are passed by reference and should be treated that way by Spies. Unexpected mutations are part of the language and should be considered while writing tests. --- src/Spies/Helpers.php | 19 ------------------- src/Spies/Spy.php | 3 +-- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/src/Spies/Helpers.php b/src/Spies/Helpers.php index f2e0b01..10d39dc 100644 --- a/src/Spies/Helpers.php +++ b/src/Spies/Helpers.php @@ -28,28 +28,9 @@ private static function do_vals_match( $a, $b ) { if ( $a === $b ) { return true; } - if ( is_object( $a ) || is_object( $b ) ) { - $array_a = is_object( $a ) ? (array) $a : $a; - $array_b = is_object( $b ) ? (array) $b : $b; - if ( $array_a === $array_b ) { - return true; - } - } if ( $a instanceof \Spies\AnyValue || $b instanceof \Spies\AnyValue ) { return true; } return false; } - - public static function array_clone( $array ) { - return array_map( function( $element ) { - return ( ( is_array( $element ) ) - ? Helpers::array_clone( $element ) - : ( ( is_object( $element ) ) - ? clone $element - : $element - ) - ); - }, $array ); - } } diff --git a/src/Spies/Spy.php b/src/Spies/Spy.php index b6aa56d..f584f6d 100644 --- a/src/Spies/Spy.php +++ b/src/Spies/Spy.php @@ -367,8 +367,7 @@ private function set_arguments( $args ) { * * You should not need to call this directly. */ - private function record_function_call( $orig_args ) { - $args = Helpers::array_clone( $orig_args ); + private function record_function_call( $args ) { $this->call_record[] = new SpyCall( $args ); }