Skip to content

Commit fdb2b95

Browse files
author
jasdeepkhalsa
committed
Initial commit
0 parents  commit fdb2b95

7 files changed

Lines changed: 108 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor/
2+
composer.lock

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# PHPUnit Skeleton #
2+
_Get up and running with PHPUnit testing easily for your project_
3+
4+
Are you frustrated with trying to install and configure PHPUnit?
5+
6+
Are you wishing you could use just one command and BANG it was all done for you and you could get on with writing your beautiful unit tests?
7+
8+
Are you having sleepless nights or sleepy afternoons?
9+
10+
Well, I\'m happy to let you know that you just need to `clone` this repo and all your problems will be whisked away (apart from the last one, perhaps).
11+
12+
We have also included a sample class so you can learn a few tricks in how to use PHPUnit in your projects!
13+
14+
HAPPY UNIT TESTING!!!
15+
16+
# Simple-tastic 3 Step Installation #
17+
* Download the repo with `git clone https://github.com/jasdeepkhalsa/tweet-counter.git`
18+
* Run `php composer.phar self-update`
19+
* Run `php composer.phar install`
20+
21+
## Run PHPUnit ##
22+
* Open up a terminal
23+
* `cd` to your project root
24+
* Type `phpunit` and...magic! Tests (should) be running!
25+
26+
# Credits #
27+
* Me and my awesomely laborious efforts in getting to grips with PHPUnit testing
28+
* Constant support from PHP Guru Jujhar Singh from [Buto](http://get.buto.tv/) who also inspired the PHPUnit class style in the examples
29+
* Class examples inspired from video by Jeffrey Way from [Nettuts+](http://net.tutsplus.com/tutorials/php/better-workflow-in-php-with-composer-namespacing-and-phpunit/)

composer.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"require-dev": {
3+
"phpunit/phpunit": "3.7.*",
4+
"phpunit/dbunit": ">=1.2",
5+
"phpunit/phpunit-selenium": ">=1.2"
6+
},
7+
"autoload": {
8+
"psr-0": {
9+
"Application": "lib/"
10+
}
11+
}
12+
}

composer.phar

782 KB
Binary file not shown.

lib/Application/Example.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
namespace Application;
3+
4+
class Example {
5+
6+
private $number = NULL;
7+
8+
function __construct() {
9+
$this->number = 0;
10+
}
11+
12+
public function add($x, $y) {
13+
if(!is_numeric($x) || !is_numeric($y)){
14+
throw new \InvalidArgumentException;
15+
}
16+
$this->number = $x + $y;
17+
return $this->number;
18+
}
19+
20+
}
21+
?>

phpunit.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<phpunit bootstrap="./vendor/autoload.php">
3+
<testsuites>
4+
<testsuite name="The project's test suite">
5+
<directory>./tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
</phpunit>

tests/Application/ExampleTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
class ExampleTest extends PHPUnit_Framework_TestCase {
3+
4+
protected $obj = NULL;
5+
6+
protected function setUp() {
7+
$this->obj = new Application\Example;
8+
}
9+
10+
public function data() {
11+
$data = array();
12+
$data[] = array(3,1,2);
13+
$data[] = array(-5,-1,-4);
14+
$data[] = array(10.5,10,0.5);
15+
return $data;
16+
}
17+
18+
/**
19+
* @dataProvider data
20+
*/
21+
public function testAddNumbers($expected, $actual_1, $actual_2) {
22+
$this->assertEquals($expected, $this->obj->add($actual_1,$actual_2));
23+
}
24+
25+
/**
26+
* @expectedException InvalidArgumentException
27+
*/
28+
public function testThrowsExceptionForNonNumeric(){
29+
$this->assertEquals(3, $this->obj->add(1, array()));
30+
}
31+
32+
protected function tearDown() {
33+
unset($this->obj);
34+
}
35+
}
36+
?>

0 commit comments

Comments
 (0)