diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0b0f784 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: php +php: + - '5.4' + - '5.5' + - '5.6' + - '7.0' + - hhvm + - nightly +notifications: + email: false + + diff --git a/app/libraries/Calculator.php b/app/libraries/Calculator.php index 3fd2190..bfb0c9b 100644 --- a/app/libraries/Calculator.php +++ b/app/libraries/Calculator.php @@ -8,4 +8,29 @@ public function add($x, $y) } return $x + $y; } -} \ No newline at end of file + + public function sub($x, $y) + { + if ( !is_numeric($x) || !is_numeric($y) ) { + throw new \InvalidArgumentException; + } + return $x - $y; + } + + public function mul($x, $y) + { + if ( !is_numeric($x) || !is_numeric($y) ) { + throw new \InvalidArgumentException; + } + return $x * $y; + } + + public function div($x, $y) + { + if ( !is_numeric($x) || !is_numeric($y) ) { + throw new \InvalidArgumentException; + } + return $x / $y; + } + +} diff --git a/phpunit.xml b/phpunit.xml index b8361cd..8be99e9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,16 +1,20 @@ - test - \ No newline at end of file + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..3ae0bec --- /dev/null +++ b/readme.md @@ -0,0 +1 @@ +[![Build Status](https://travis-ci.org/nimasdj/PHPUnit-Workflow.svg?branch=master)](https://travis-ci.org/nimasdj/PHPUnit-Workflow) diff --git a/test/CalculatorTest.php b/test/CalculatorTest.php index 6e5dff9..ea25ed2 100644 --- a/test/CalculatorTest.php +++ b/test/CalculatorTest.php @@ -9,7 +9,7 @@ public function setUp() $this->calculator = new Calculator; } - public function inputNumbers() + public function addNumbers() { return [ [2, 2, 4], @@ -18,19 +18,70 @@ public function inputNumbers() } /** - * @dataProvider inputNumbers + * @dataProvider addNumbers */ public function testCanAddNumbers($x, $y, $sum) { $this->assertEquals($sum, $this->calculator->add($x, $y)); } + public function subNumbers() + { + return [ + [4, 2, 2], + [2, 4, -2] + ]; + } + + /** + * @dataProvider subNumbers + */ + public function testCanSubNumbers($x, $y, $sum) + { + $this->assertEquals($sum, $this->calculator->sub($x, $y)); + } + + public function mulNumbers() + { + return [ + [4, 2, 8], + [4, 4, 16] + ]; + } + /** + * @dataProvider mulNumbers + */ + public function testCanMulNumbers($x, $y, $sum) + { + $this->assertEquals($sum, $this->calculator->mul($x, $y)); + } + + public function divNumbers() + { + return [ + [4, 2, 2], + [8, 2, 4] + ]; + } + + /** + * @dataProvider divNumbers + */ + public function testCanDivNumbers($x, $y, $sum) + { + $this->assertEquals($sum, $this->calculator->div($x, $y)); + } + + /** * @expectedException InvalidArgumentException */ public function testThrowsExceptionIfNonNumberIsPassed() { - $calc = new Calculator; - $calc->add('a', 'b'); + $this->calculator->add('a', 'b'); + $this->calculator->sub('a', 'b'); + $this->calculator->mul('a', 'b'); + $this->calculator->div('a', 'b'); } -} \ No newline at end of file + +}