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 ); } diff --git a/tests/SpyTest.php b/tests/SpyTest.php index 5105613..4166dec 100644 --- a/tests/SpyTest.php +++ b/tests/SpyTest.php @@ -118,6 +118,13 @@ public function test_spy_was_called_with_returns_true_if_the_spy_was_called_with $this->assertTrue( $spy->was_called_with( $obj ) ); } + public function test_spy_was_called_with_returns_true_if_the_spy_was_called_with_the_deep_object_arguments_provided() { + $spy = \Spies\make_spy(); + $obj = [ (object) [ 'ID' => 5, 'names' => [ 'bob' ], 'colors' => [ 'red' => '#f00' ] ] ]; + $spy( [ 'foo' => $obj[0] ] ); + $this->assertTrue( $spy->was_called_with( [ 'foo' => $obj[0] ] ) ); + } + public function test_spy_was_called_with_returns_false_if_the_spy_was_not_called_with_the_arguments_provided() { $spy = \Spies\make_spy(); $spy( 'foo' ); @@ -153,14 +160,24 @@ public function test_spy_was_called_when_returns_false_if_the_spy_was_called_whe } ) ); } - public function test_spy_was_called_when_uses_a_copy_of_the_arguments_as_they_were_when_the_call_occurred() { + public function test_spy_was_called_when_tests_object_arguments_by_reference() { $spy = \Spies\make_spy(); $obj = new \StdClass(); $obj->foo = 'original'; $spy( $obj ); $obj->foo = 'modified'; $this->assertTrue( $spy->was_called_when( function( $args ) { - return $args[0]->foo === 'original'; + return $args[0]->foo === 'modified'; + } ) ); + } + + public function test_spy_was_called_when_tests_array_arguments_by_value() { + $spy = \Spies\make_spy(); + $obj = [ 'foo' => 'original' ]; + $spy( $obj ); + $obj['foo'] = 'modified'; + $this->assertTrue( $spy->was_called_when( function( $args ) { + return $args[0]['foo'] === 'original'; } ) ); }