in Education by
The following script both demonstrates and documents (in the header comment) the issue, namely that I am unable to detect any difference between the "expected" and "actual" strings: <?php /* $ phpunit MyTest.php PHPUnit 3.4.0 by Sebastian Bergmann. F Time: 0 seconds There was 1 failure: 1) MyTest::test_print_r Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -O:7:"MyClass":2:{s:13:"MyClassvar3";N;s:4:"var1";N;} +O:7:"MyClass":2:{s:13:"MyClassvar3";N;s:4:"var1";N;} .../MyTest.php:41 .../bin/phpunit:54 FAILURES! Tests: 1, Assertions: 1, Failures: 1. */ class MyClass { static protected $var2; private $var3; public $var1; public function foo($item) { echo $item . "\n"; } } class MyTest extends PHPUnit_Framework_TestCase { function test_print_r() { $m = new MyClass(); $this->assertEquals(trim('O:7:"MyClass":2:{s:13:"MyClassvar3";N;s:4:"var1";N;}'), trim(serialize($m))); } } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You don't see the Problem because you are using a quite old PHPUnit Version. The current version is 3.6.5 and if you can you should upgrade. PHPUnit > 3.6 will show a differnt diff to you when the string contains unprintable characters. As is the case here. Here is the output using a more current Version. The explanation on why it fails is below: phpunit PHPUnit 3.6.5 by Sebastian Bergmann. F Time: 0 seconds, Memory: 3.25Mb There was 1 failure: 1) MyTest::test_print_r Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'O:7:"MyClass":2:{s:13:"MyClassvar3";N;s:4:"var1";N;}' +Binary String: 0x4f3a373a224d79436c617373223a323a7b733a31333a22004d79436c6173730076617233223b4e3b733a343a2276617231223b4e3b7d FAILURES! Tests: 1, Assertions: 1, Failures: 1. Explanation A serialized php string contains NULL BYTES to denote private and protected class variables. The string "MyClassvar3" is really "\0MyClass\0var3". To fix the assertion: $this->assertEquals( "O:7:\"MyClass\":2:{s:13:\"\x00MyClass\x00var3\";N;s:4:\"var1\";N;}", serialize($m) ); Using this will result in the test working.

Related questions

0 votes
    I've set two variables to the value 'qwerty' in Python. In a conditional expression which fails i.e. var1 is ... mistakes I am doing? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    This is my code it's just starting the scan but it is not completing ,where is the error in it. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    function add() and operator + gives the same result true Or f plzzzz give me answer fast……. dud Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    Wt is coding classes please help me in this question give a valid answer please I will mark them brainlist and ... give valid answer. Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    Any one pls give me solved question papers of computer icse 2014-2018 Select the correct answer from above options...
asked Dec 23, 2021 in Education by JackTerrance
0 votes
    plss give me some questions of HTML programming…plss fast…. don’t report the question Select the correct answer from above options...
asked Dec 16, 2021 in Education by JackTerrance
0 votes
    Give me some Information about Quantum Computer… Please…don’t copy from Google or any other sites… Don’t give me any irrelevant answer… Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    Plzz give me solution of ch 1 number system of it apps class 7 . Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    dograschit3 if u will give me the point I wasted on you than I will leave those things Select the correct answer from above options...
asked Dec 11, 2021 in Education by JackTerrance
0 votes
    What are the 5 functions or features of headphones?? plzz answer me and give me atleast 5 to 6 not only 1 ... waiting for your answer Select the correct answer from above options...
asked Nov 29, 2021 in Education by JackTerrance
0 votes
    I am able to create and run a simple GWT application by creating all the files myself. It works ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 20, 2022 in Education by JackTerrance
0 votes
    Why Zn reacts with dilute H2SO4 to give H2 gas but Cu does not ? Select the correct answer from above options...
asked Jan 5, 2022 in Education by JackTerrance
0 votes
    Does Go language use Copy-on-write for strings as in Java? I.e. if I pass a string by value to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    program code for this question: Raju has a lot of strings but he does not like all of them.He likes only Swaggy ... at least K times. Select the correct answer from above options...
asked Dec 29, 2021 in Education by JackTerrance
0 votes
    I am trying to find out the best, or correct, way to check if a class has a constant defined ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 19, 2022 in Education by JackTerrance
...