Skip to content

Instantly share code, notes, and snippets.

@maio
Created June 2, 2011 16:41
Show Gist options
  • Save maio/1004772 to your computer and use it in GitHub Desktop.
Save maio/1004772 to your computer and use it in GitHub Desktop.
First Test in PHPUnit
# Run these commands to install PHPUnit
# More info @ http://www.phpunit.de/manual/current/en/installation.html
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear install phpunit/PHPUnit
# OSX - you may need to upgrade pear before installing PHPUnit
sudo pear upgrade pear
<?
class MyClassTest extends PHPUnit_Framework_TestCase
{
function testSumReturnsSumOfTwoNumbers() {
$myClass = new MyClass();
$this->assertEquals(2, $myClass->sum(1,1));
}
}
class MyClass {
public function sum($a, $b) {
return null; // FIXME: please
}
}
$ phpunit web/app/app/models/t/MyClassTest.php
F
Time: 0 seconds, Memory: 3.75Mb
There was 1 failure:
1) MyClassTest::testSumShouldReturnSumOfTwoNumbers
Failed asserting that <null> matches expected <integer:2>.
MyClassTest.php:6
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment