Skip to content

Instantly share code, notes, and snippets.

@yuya-takeyama
Created July 18, 2010 04:47
Show Gist options
  • Save yuya-takeyama/480133 to your computer and use it in GitHub Desktop.
Save yuya-takeyama/480133 to your computer and use it in GitHub Desktop.
<?php
class Calc
{
public function add($a, $b, $c = NULL)
{
if (isset($c)) {
return $a + $b + $c;
} else {
return $a + $b;
}
}
}
<?php
class Calc
{
public function add()
{
$num = 0;
$cnt = func_num_args();
for ($i = 0; $i < $cnt; $i++) {
$num += func_get_arg($i);
}
return $num;
}
}
<?php
require_once 'PHPUnit/Framework.php';
require_once './Calc.php';
class CalcTest extends PHPUnit_Framework_TestCase
{
public function testAdd()
{
$calc = new Calc;
$this->assertEquals(2, $calc->add(1, 1));
}
public function testAddThreeNumbers()
{
$calc = new Calc;
$this->assertEquals(3, $calc->add(1, 1, 1));
}
}
<?php
require_once 'PHPUnit/Framework.php';
require_once './Calc.php';
class CalcTest extends PHPUnit_Framework_TestCase
{
protected $calc;
public function setUp()
{
$this->calc = new Calc;
}
public function testAdd()
{
$this->assertEquals(2, $this->calc->add(1, 1));
}
public function testAddThreeNumbers()
{
$this->assertEquals(3, $this->calc->add(1, 1, 1));
}
}
<?php
require_once 'PHPUnit/Framework.php';
require_once './Calc.php';
class CalcTest extends PHPUnit_Framework_TestCase
{
protected $calc;
public function setUp()
{
$this->calc = new Calc;
}
public function testAdd()
{
$this->assertEquals(2, $this->calc->add(1, 1));
}
public function testAddThreeNumbers()
{
$this->assertEquals(3, $this->calc->add(1, 1, 1));
}
public function testAddTenNumbers()
{
$this->assertEquals(55, $this->calc->add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment