Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
60f47a7
setUp
nimasdj Sep 27, 2016
8b7434c
Create .travis.yml
nimasdj Sep 27, 2016
8554cbf
Update Calculator.php
nimasdj Sep 27, 2016
13a8c96
Update CalculatorTest.php
nimasdj Sep 27, 2016
69d80d0
Update CalculatorTest.php
nimasdj Sep 27, 2016
6ea953d
Create readme.md
nimasdj Sep 27, 2016
99dda33
Update readme.md
nimasdj Sep 27, 2016
951fb26
Update readme.md
nimasdj Sep 27, 2016
7901c86
Update readme.md
nimasdj Sep 27, 2016
04926aa
Update readme.md
nimasdj Sep 27, 2016
c47dce3
Update CalculatorTest.php
nimasdj Sep 27, 2016
1f8ce27
Update CalculatorTest.php
nimasdj Sep 27, 2016
4f769da
Update CalculatorTest.php
nimasdj Sep 27, 2016
9e2613c
Update CalculatorTest.php
nimasdj Sep 27, 2016
36ecfa3
Update .travis.yml
nimasdj Sep 27, 2016
d4713e8
Update CalculatorTest.php
nimasdj Sep 27, 2016
2fc2e4a
Update Calculator.php
nimasdj Sep 27, 2016
7afd1b9
Update CalculatorTest.php
nimasdj Sep 27, 2016
d5d6599
Update CalculatorTest.php
nimasdj Sep 27, 2016
afd1a5f
Update phpunit.xml
nimasdj Sep 27, 2016
9059e6b
Update CalculatorTest.php
nimasdj Sep 27, 2016
8d87407
Update phpunit.xml
nimasdj Sep 27, 2016
e715523
Update phpunit.xml
nimasdj Sep 27, 2016
c92f60d
Update phpunit.xml
nimasdj Sep 27, 2016
3d2ba39
Update CalculatorTest.php
nimasdj Sep 27, 2016
d07ed38
Update CalculatorTest.php
nimasdj Sep 27, 2016
a2a2244
Update CalculatorTest.php
nimasdj Sep 27, 2016
1f419a1
Update readme.md
nimasdj Sep 27, 2016
2e40726
Update CalculatorTest.php
nimasdj Sep 28, 2016
69b72f0
Update CalculatorTest.php
nimasdj Sep 28, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: php
php:
- '5.4'
- '5.5'
- '5.6'
- '7.0'
- hhvm
- nightly
notifications:
email: false


27 changes: 26 additions & 1 deletion app/libraries/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,29 @@ public function add($x, $y)
}
return $x + $y;
}
}

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;
}

}
10 changes: 7 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
<phpunit
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
syntaxCheck="true"
>
<testsuites>
<testsuite name="App Tests">
<directory>test</directory>
</testsuite>
</testsuites>
</phpunit>
</phpunit>
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[![Build Status](https://travis-ci.org/nimasdj/PHPUnit-Workflow.svg?branch=master)](https://travis-ci.org/nimasdj/PHPUnit-Workflow)
61 changes: 56 additions & 5 deletions test/CalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public function setUp()
$this->calculator = new Calculator;
}

public function inputNumbers()
public function addNumbers()
{
return [
[2, 2, 4],
Expand All @@ -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');
}
}

}