Codewars/codewars-runner — pull request #124 by ankr (2014-10-05 16:43:39+00:00)
Title: Add PHPUnit support for testing PHP

**First draft implementation of PHPUnit for testing.**

# Installation
Using composer to install PHPUnit with dependencies.
```
composer intall
```

# Tests
So far I've only tested my implementation using the `node run` interface. Here are some of the tests I've been using. With a little more time and knowledge about the system I will create real test cases.

## Simple var test
Testing variables from user script is available in test method.
```bash
node run -l php \
-c '$a = "foo";' \
-f '$this->assertEquals("foo", $a);'
```

## Function test
Testing functions can be called and tested.
```bash
node run -l php -c '
function do_you_play_banjo($name) {
return strtolower($name[0]) === "r" ? $name . " plays banjo" : $name . " does not play banjo";
}
' -f '
$this->assertEquals("ronnie plays banjo", do_you_play_banjo("ronnie"));
$this->assertEquals("mark does not play banjo", do_you_play_banjo("mark"));'
```

## Class test
Testing classes and mock objects can be created.
```bash
node run -l php -c '
class A {
function f1() {
$this->f2("foo");
}
function f2() {
}
}
' -f '
$mock = $this->getMock("A", ["f2"]);
$mock->expects($this->once())
->method("f2")
->with("foo");
$mock->f1();'
```

# Successful test
If all expectations passes the output is `All test passed`

# Failed test
Example output of when we make the "Class test" fail.
```
PHPUnit 4.3.0 by Sebastian Bergmann.

F

Time: 21 ms, Memory: 3.00Mb

There was 1 failure:

1) KataTest::testSolution
Expectation failed for method name is equal to when invoked 1 time(s)
Parameter 0 for invocation A::f2('foo') does not match expected value.
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'bar'
+'foo'

FAILURES!
Tests: 1, Assertions: 0, Failures: 1.
```