guard-phpunit 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. data/CHANGELOG.md +37 -0
  2. data/LICENSE +19 -19
  3. data/README.md +106 -106
  4. data/lib/guard/phpunit.rb +112 -112
  5. data/lib/guard/phpunit/formatter.rb +64 -64
  6. data/lib/guard/phpunit/formatters/PHPUnit-Progress/PHPUnit/Extensions/Progress/ResultPrinter.php +498 -498
  7. data/lib/guard/phpunit/formatters/PHPUnit-Progress/README.markdown +44 -0
  8. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/_files/Number.php +78 -0
  9. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/_files/NumberTest.php +99 -0
  10. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/_files/emptyTest.php +6 -0
  11. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_basic.phpt +22 -0
  12. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_errors.phpt +27 -0
  13. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_errors_variation.phpt +28 -0
  14. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_failing.phpt +31 -0
  15. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_failing_variation.phpt +32 -0
  16. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_incomplete.phpt +19 -0
  17. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_incomplete_variation.phpt +20 -0
  18. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_passing.phpt +19 -0
  19. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_passing_variation.phpt +20 -0
  20. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_skipped.phpt +19 -0
  21. data/lib/guard/phpunit/formatters/PHPUnit-Progress/Tests/printer_skipped_variation.phpt +20 -0
  22. data/lib/guard/phpunit/formatters/PHPUnit-Progress/phpunit.xml +4 -0
  23. data/lib/guard/phpunit/formatters/PHPUnit-Progress/screenshot.png +0 -0
  24. data/lib/guard/phpunit/inspector.rb +54 -54
  25. data/lib/guard/phpunit/notifier.rb +68 -68
  26. data/lib/guard/phpunit/runner.rb +197 -194
  27. data/lib/guard/phpunit/templates/Guardfile +3 -3
  28. data/lib/guard/phpunit/version.rb +6 -6
  29. metadata +37 -3
@@ -0,0 +1,44 @@
1
+ Progress results printer for PHPUnit
2
+ ====================================
3
+
4
+ This PHPUnit extention makes the printed tests results look similar to
5
+ Rspec's default formatter called "progress".
6
+
7
+ The progress printer tries to focus on the tests results only; That's why
8
+ a lot of the info printed by the default PHPUnit printer was removed.
9
+
10
+ Test results have the same colors and spacing as the Rspec's results.
11
+ If you want to see how results look, check out the screenshot below!
12
+
13
+
14
+ Usage
15
+ -----
16
+
17
+ There is more than one way to use this printer with PHPUnit. Probably
18
+ the easiest way is to pass the the printer (with it's location) as
19
+ arguments to the `phpunit` command.
20
+
21
+ So clone this repo to someplace on your machine. Then copy the following
22
+ command and paste it to your terminal
23
+ (**Don't** forget to replace the things inside brackets)
24
+
25
+ phpunit --include-path [Path to your clone of this repo] \
26
+ --printer PHPUnit_Extensions_Progress_ResultPrinter \
27
+ --colors [Tests Path]
28
+
29
+ If you want to see a the skipped and incomplete tests too in the results,
30
+ you can add the `--verbose` argument the the command above.
31
+
32
+ Another way is to use a `phpunit.xml` file and pass its location as an argument.
33
+ If you are intrested in this way, I would recommend that you read [PHPUnit's
34
+ docs][docs].
35
+
36
+
37
+ Screenshot
38
+ ----------
39
+
40
+ Here is how the results of this extention look using the progress printer:
41
+ ![Progress printer results in the terminal][shot]
42
+
43
+ [docs]:http://www.phpunit.de/manual/current/en/index.html
44
+ [shot]:https://github.com/Maher4Ever/phpunit-progress/raw/master/screenshot.png
@@ -0,0 +1,78 @@
1
+ <?php
2
+
3
+ /**
4
+ * A generic number class
5
+ */
6
+ class Number {
7
+
8
+ /**
9
+ * The number
10
+ *
11
+ * @var integer
12
+ */
13
+ protected $number;
14
+
15
+ /**
16
+ * The constructor
17
+ *
18
+ * @param integer $num
19
+ */
20
+ public function __construct($num) {
21
+ $this->number = $num;
22
+ }
23
+
24
+ /**
25
+ * Adds a number.
26
+ *
27
+ * @param integer $num
28
+ */
29
+ public function add($num) {
30
+ $this->number += $num;
31
+ }
32
+
33
+ /**
34
+ * Substracts a number.
35
+ *
36
+ * @param integer $num
37
+ */
38
+ public function substract($num) {
39
+ $this->number -= $num;
40
+ }
41
+
42
+ /**
43
+ * Multiplies by number.
44
+ *
45
+ * @param integer $num
46
+ */
47
+ public function multiplyBy($num) {
48
+ $this->number *= $num;
49
+ }
50
+
51
+ /**
52
+ * Divides by number.
53
+ *
54
+ * @param integer $num
55
+ * @throws NumberException
56
+ */
57
+ public function divideBy($num) {
58
+ if ( $num !== 0 ) {
59
+ $this->number /= $num;
60
+ } else {
61
+ throw new NumberException('Division by zero!');
62
+ }
63
+ }
64
+
65
+ /*
66
+ * Returns the number.
67
+ *
68
+ * @return integer
69
+ */
70
+ public function get() {
71
+ return $this->number;
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Number exceptions class.
77
+ */
78
+ class NumberException extends RuntimeException {}
@@ -0,0 +1,99 @@
1
+ <?php
2
+
3
+ require_once 'Number.php';
4
+
5
+ /**
6
+ * Tests for the number class.
7
+ */
8
+ class NumberTest extends PHPUnit_Framework_TestCase {
9
+
10
+ protected $number;
11
+
12
+ public function setUp()
13
+ {
14
+ $this->number = new Number(0);
15
+ }
16
+
17
+ /**
18
+ * @covers Number::add
19
+ * @group passing
20
+ */
21
+ public function testAdditionWorks()
22
+ {
23
+ $this->number->add(1);
24
+ $this->assertSame($this->number->get(), 1);
25
+ }
26
+
27
+ /**
28
+ * @covers Number::substract
29
+ * @group passing
30
+ */
31
+ public function testSubstractionWorks()
32
+ {
33
+ $this->number->substract(1);
34
+ $this->assertSame($this->number->get(), -1);
35
+ }
36
+
37
+ /**
38
+ * @covers Number::multiplyBy
39
+ * @group skipped
40
+ */
41
+ public function testMultiplicationWorks()
42
+ {
43
+ $this->markTestSkipped();
44
+ }
45
+
46
+ /**
47
+ * @covers Number::divideBy
48
+ * @group skipped
49
+ */
50
+ public function testDivisionWorks()
51
+ {
52
+ $this->markTestSkipped('Division is hard!');
53
+ }
54
+
55
+ /**
56
+ * @covers Number::add
57
+ * @group failing
58
+ */
59
+ public function testThatMyMathTeacherSucked()
60
+ {
61
+ $this->number->add(1);
62
+ $this->assertSame($this->number->get(), 10);
63
+ }
64
+
65
+ /**
66
+ * @covers Number::substract
67
+ * @group failing
68
+ */
69
+ public function testThatMyMathTeacherSuckedEvenMore()
70
+ {
71
+ $this->number->substract(1);
72
+ $this->assertSame($this->number->get(), "I don't know!");
73
+ }
74
+
75
+ /**
76
+ * @covers Number::divideBy
77
+ * @group errors
78
+ */
79
+ public function testMathStillWorks()
80
+ {
81
+ $this->number->divideBy(0);
82
+ $this->assertSame($this->number->get(), 0);
83
+ }
84
+
85
+ /**
86
+ * @covers Number::add
87
+ * @covers Number::substract
88
+ * @covers Number::multiplyBy
89
+ * @covers Number::divideBy
90
+ * @group incomplete
91
+ */
92
+ public function testArithmeticMethodsOnlyAcceptIntegers()
93
+ {
94
+ $this->markTestIncomplete(
95
+ 'This test has not been implemented yet.'
96
+ );
97
+ }
98
+
99
+ }
@@ -0,0 +1,6 @@
1
+ <?php
2
+
3
+ /**
4
+ * Empty test, literally!
5
+ */
6
+ class emptyTest extends PHPUnit_Framework_TestCase {}
@@ -0,0 +1,22 @@
1
+ --TEST--
2
+ phpunit empryTest - An empty test
3
+ --FILE--
4
+ <?php
5
+ $testClass = 'emptyTest';
6
+
7
+ $_SERVER['argv'][1] = dirname(__FILE__) . "/_files/${testClass}.php";
8
+
9
+ require_once 'PHPUnit/Autoload.php';
10
+ PHPUnit_TextUI_Command::main();
11
+ ?>
12
+ --EXPECTF--
13
+ %rF+%r
14
+
15
+ Failures:
16
+
17
+ 1) Warning
18
+ No tests found in class "emptyTest".
19
+ # %s:%i
20
+
21
+ Finished in %i second%S
22
+ 1 test, 0 assertions, 1 failures
@@ -0,0 +1,27 @@
1
+ --TEST--
2
+ phpunit Number - Only tests with errors
3
+ --FILE--
4
+ <?php
5
+ $group = 'errors';
6
+ $testClass = 'NumberTest';
7
+
8
+ $_SERVER['argv'][1] = '--group';
9
+ $_SERVER['argv'][2] = $group;
10
+ $_SERVER['argv'][3] = dirname(__FILE__) . "/_files/${testClass}.php";
11
+
12
+ require_once 'PHPUnit/Autoload.php';
13
+ PHPUnit_TextUI_Command::main();
14
+ ?>
15
+ --EXPECTF--
16
+ %rE+%r
17
+
18
+ Errors:
19
+
20
+ 1) NumberTest::testMathStillWorks
21
+ NumberException: Division by zero!
22
+ # %s:%i
23
+ # %s:%i
24
+ # %s:%i
25
+
26
+ Finished in %i second%S
27
+ %i test, 0 assertions, %i errors
@@ -0,0 +1,28 @@
1
+ --TEST--
2
+ phpunit Number - Only tests with errors and colors enabled
3
+ --FILE--
4
+ <?php
5
+ $group = 'errors';
6
+ $testClass = 'NumberTest';
7
+
8
+ $_SERVER['argv'][1] = '--group';
9
+ $_SERVER['argv'][2] = $group;
10
+ $_SERVER['argv'][3] = '--colors';
11
+ $_SERVER['argv'][4] = dirname(__FILE__) . "/_files/${testClass}.php";
12
+
13
+ require_once 'PHPUnit/Autoload.php';
14
+ PHPUnit_TextUI_Command::main();
15
+ ?>
16
+ --EXPECTF--
17
+ %r(.+31.+E.+)+%r
18
+
19
+ Errors:
20
+
21
+ 1) NumberTest::testMathStillWorks
22
+ NumberException: Division by zero!
23
+ # %s:%i
24
+ # %s:%i
25
+ # %s:%i
26
+
27
+ Finished in %i second%S
28
+ %i test, 0 assertions, %i errors
@@ -0,0 +1,31 @@
1
+ --TEST--
2
+ phpunit Number - Only failing tests
3
+ --FILE--
4
+ <?php
5
+ $group = 'failing';
6
+ $testClass = 'NumberTest';
7
+
8
+ $_SERVER['argv'][1] = '--group';
9
+ $_SERVER['argv'][2] = $group;
10
+ $_SERVER['argv'][3] = dirname(__FILE__) . "/_files/${testClass}.php";
11
+
12
+ require_once 'PHPUnit/Autoload.php';
13
+ PHPUnit_TextUI_Command::main();
14
+ ?>
15
+ --EXPECTF--
16
+ %rF+%r
17
+
18
+ Failures:
19
+
20
+ 1) NumberTest::testThatMyMathTeacherSucked
21
+ Failed asserting that 10 is identical to 1.
22
+ # %s:%i
23
+ # %s:%i
24
+
25
+ 2) NumberTest::testThatMyMathTeacherSuckedEvenMore
26
+ Failed asserting that 'I don't know!' is identical to -1.
27
+ # %s:%i
28
+ # %s:%i
29
+
30
+ Finished in %i second%S
31
+ 2 tests, 2 assertions, 2 failures
@@ -0,0 +1,32 @@
1
+ --TEST--
2
+ phpunit Number - Only failing tests and colors enabled
3
+ --FILE--
4
+ <?php
5
+ $group = 'failing';
6
+ $testClass = 'NumberTest';
7
+
8
+ $_SERVER['argv'][1] = '--group';
9
+ $_SERVER['argv'][2] = $group;
10
+ $_SERVER['argv'][3] = '--colors';
11
+ $_SERVER['argv'][4] = dirname(__FILE__) . "/_files/${testClass}.php";
12
+
13
+ require_once 'PHPUnit/Autoload.php';
14
+ PHPUnit_TextUI_Command::main();
15
+ ?>
16
+ --EXPECTF--
17
+ FF
18
+
19
+ Failures:
20
+
21
+ 1) NumberTest::testThatMyMathTeacherSucked
22
+ Failed asserting that 10 is identical to 1.
23
+ # %s:%i
24
+ # %s:%i
25
+
26
+ 2) NumberTest::testThatMyMathTeacherSuckedEvenMore
27
+ Failed asserting that 'I don't know!' is identical to -1.
28
+ # %s:%i
29
+ # %s:%i
30
+
31
+ Finished in %i second%S
32
+ 2 tests, 2 assertions, 2 failures
@@ -0,0 +1,19 @@
1
+ --TEST--
2
+ phpunit Number - Only incomplete tests
3
+ --FILE--
4
+ <?php
5
+ $group = 'incomplete';
6
+ $testClass = 'NumberTest';
7
+
8
+ $_SERVER['argv'][1] = '--group';
9
+ $_SERVER['argv'][2] = $group;
10
+ $_SERVER['argv'][3] = dirname(__FILE__) . "/_files/${testClass}.php";
11
+
12
+ require_once 'PHPUnit/Autoload.php';
13
+ PHPUnit_TextUI_Command::main();
14
+ ?>
15
+ --EXPECTF--
16
+ %rI+%r
17
+
18
+ Finished in %i second%S
19
+ 1 test, 0 assertions, 1 incomplete
@@ -0,0 +1,20 @@
1
+ --TEST--
2
+ phpunit Number - Only incomplete tests and colors enabled
3
+ --FILE--
4
+ <?php
5
+ $group = 'incomplete';
6
+ $testClass = 'NumberTest';
7
+
8
+ $_SERVER['argv'][1] = '--group';
9
+ $_SERVER['argv'][2] = $group;
10
+ $_SERVER['argv'][3] = '--colors';
11
+ $_SERVER['argv'][4] = dirname(__FILE__) . "/_files/${testClass}.php";
12
+
13
+ require_once 'PHPUnit/Autoload.php';
14
+ PHPUnit_TextUI_Command::main();
15
+ ?>
16
+ --EXPECTF--
17
+ I
18
+
19
+ Finished in %i second%S
20
+ 1 test, 0 assertions, 1 incomplete
@@ -0,0 +1,19 @@
1
+ --TEST--
2
+ phpunit Number - Only passing tests
3
+ --FILE--
4
+ <?php
5
+ $group = 'passing';
6
+ $testClass = 'NumberTest';
7
+
8
+ $_SERVER['argv'][1] = '--group';
9
+ $_SERVER['argv'][2] = $group;
10
+ $_SERVER['argv'][3] = dirname(__FILE__) . "/_files/${testClass}.php";
11
+
12
+ require_once 'PHPUnit/Autoload.php';
13
+ PHPUnit_TextUI_Command::main();
14
+ ?>
15
+ --EXPECTF--
16
+ %r[.]+%r
17
+
18
+ Finished in %i second%S
19
+ %i tests, %i assertions
@@ -0,0 +1,20 @@
1
+ --TEST--
2
+ phpunit Number - Only passing tests and colors enabled
3
+ --FILE--
4
+ <?php
5
+ $group = 'passing';
6
+ $testClass = 'NumberTest';
7
+
8
+ $_SERVER['argv'][1] = '--group';
9
+ $_SERVER['argv'][2] = $group;
10
+ $_SERVER['argv'][3] = '--colors';
11
+ $_SERVER['argv'][4] = dirname(__FILE__) . "/_files/${testClass}.php";
12
+
13
+ require_once 'PHPUnit/Autoload.php';
14
+ PHPUnit_TextUI_Command::main();
15
+ ?>
16
+ --EXPECTF--
17
+ ..
18
+
19
+ Finished in %i second%S
20
+ 2 tests, 2 assertions