I am using phpunit to do some testing and I ran into a problem with
print json_encode($assoc_array);
I have an associative array
$assoc_array("username":"xxx");
In my_function() I print it out like this
print json_encode($assoc_array);
Then in my phpunit test I assert this
$output=my_function($assoc_array);
$expected='{"username":"xxx"}';
$this->assertEquals($expected,$output);
The assert returns false because $output is
$output='
{"username";"xxx"}';
and $expected is
$expected='{"username";"xxx"}';
For some reason I am getting a line break at the beginning when I use print json_encode();
I could just add a line break to all of my $expected
values, but I really don't want to do that. Why am I getting the line break? Can anyone else get the line break too?
Thanks for the help @Barmar. I found a line break after a ?>
in a controller. I will remove all the ?>
from the class files.