Last active
March 30, 2016 05:32
-
-
Save georgestephanis/98b42358032501936ab0 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
To run the tests in
test-class.stephanis-addition.php
from the command line, you would run: