Forked from georgestephanis/class.stephanis-addition.php
Created
March 30, 2016 05:32
-
-
Save richaber/1da37cfe3d7a14adb4ca1e79af76eee9 to your computer and use it in GitHub Desktop.
Unit Tests Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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