Skip to content

Commit

Permalink
Save SpyCall object arguments by reference
Browse files Browse the repository at this point in the history
Reverts changes made in [v1.4.1](92de74c) and [v1.5.1](b3ee2e2) 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.
  • Loading branch information
sirbrillig committed Feb 17, 2017
1 parent 450c2b4 commit 81e5091
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 21 deletions.
19 changes: 0 additions & 19 deletions src/Spies/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
3 changes: 1 addition & 2 deletions src/Spies/Spy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down

0 comments on commit 81e5091

Please sign in to comment.