Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save richaber/1da37cfe3d7a14adb4ca1e79af76eee9 to your computer and use it in GitHub Desktop.
Save richaber/1da37cfe3d7a14adb4ca1e79af76eee9 to your computer and use it in GitHub Desktop.
Unit Tests Demo
<?php
class StephanisAddition {
public static function add_two_numbers( $number_one, $number_two ) {
if ( ! is_numeric( $number_one ) || ! is_numeric( $number_two ) ) {
return null;
}
return $number_one + $number_two;
}
}
<?php
include 'class.stephanis-addition.php';
class StephanisAdditionTest extends PHPUnit_Framework_TestCase {
public function test_adding_two_numbers() {
$this->assertEquals( 12, StephanisAddition::add_two_numbers( 5, 7 ) );
}
public function test_rejection_of_non_numbers() {
$this->assertNull( StephanisAddition::add_two_numbers( 'Blue', 7 ) );
$this->assertNull( StephanisAddition::add_two_numbers( 7, 'Pink' ) );
$this->assertNull( StephanisAddition::add_two_numbers( 'Blue', 'Pink' ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment