Skip to content

Instantly share code, notes, and snippets.

@proofek
Created February 9, 2012 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save proofek/1779262 to your computer and use it in GitHub Desktop.
Save proofek/1779262 to your computer and use it in GitHub Desktop.
phpunit assertion gotcha
<?php
class myClass
{
public function __toString()
{
return "mememe";
}
}
class TestCase extends PHPUnit_Framework_TestCase
{
public function testAssertStringWithObject()
{
$class = new myClass();
$this->assertEquals('mememe', $class);
}
public function testAssertStringWithSerialisedObject()
{
$class = new myClass();
$this->assertEquals('mememe', "$class");
}
}
@proofek
Copy link
Author

proofek commented Feb 9, 2012

$ phpunit testCaseTest.php 
PHPUnit 3.6.10 by Sebastian Bergmann.

..

Time: 1 second, Memory: 5.50Mb

OK (2 tests, 2 assertions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment