From 59da440c7adf36f79cb4fcf67acb5dc1a68984b4 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sat, 22 Mar 2014 00:01:19 +0100 Subject: [PATCH] Test decorators are a no-no in PHPUnit --- src/TestSuite/TestPermutationDecorator.php | 89 ------------------- .../TestPermutationDecoratorTest.php | 75 ---------------- 2 files changed, 164 deletions(-) delete mode 100644 src/TestSuite/TestPermutationDecorator.php delete mode 100644 tests/TestCase/TestSuite/TestPermutationDecoratorTest.php diff --git a/src/TestSuite/TestPermutationDecorator.php b/src/TestSuite/TestPermutationDecorator.php deleted file mode 100644 index 8481f1963b8..00000000000 --- a/src/TestSuite/TestPermutationDecorator.php +++ /dev/null @@ -1,89 +0,0 @@ -_permutations = $permutations; - } - -/** - * Returns the count of single test methods that this decorator contains, taking in - * consideration the possible permutations - * - * @return void - */ - public function count() { - return count($this->_permutations) * $this->test->count(); - } - -/** - * Runs each of the test methods for this test suite for each of the provided - * permutations. - * - * @param PHPUnit_Framework_TestResult $result - * @param mixed $filter - * @param array $groups - * @param array $excludeGroups - * @param boolean $processIsolation - * @return PHPUnit_Framework_TestResult - */ - public function run(PHPUnit_Framework_TestResult $result = null, $filter = false, array $groups = [], array $excludeGroups = [], $processIsolation = false) { - if ($result === null) { - $result = $this->createResult(); - } - - foreach ($this->_permutations as $permutation) { - if ($result->shouldStop()) { - break; - } - if (is_callable($permutation)) { - $permutation($this->test); - } - $this->test->run($result, $filter, $groups, $excludeGroups, $processIsolation); - } - - return $result; - } - -} diff --git a/tests/TestCase/TestSuite/TestPermutationDecoratorTest.php b/tests/TestCase/TestSuite/TestPermutationDecoratorTest.php deleted file mode 100644 index f5bb7f9f076..00000000000 --- a/tests/TestCase/TestSuite/TestPermutationDecoratorTest.php +++ /dev/null @@ -1,75 +0,0 @@ -getMockForAbstractClass('\PHPUnit_Framework_Test', ['count']); - $test->expects($this->once())->method('count')->will($this->returnValue(5)); - $decorated = new TestPermutationDecorator($test, $permutations); - $this->assertEquals(15, $decorated->count()); - } - -/** - * Tests that the decorated test is run once per permutation - * - * @return void - */ - public function testRunNoCallbacks() { - $permutations = [1, 2, 3]; - $test = $this->getMockForAbstractClass('\PHPUnit_Framework_Test', ['run', 'count']); - $test->expects($this->exactly(3))->method('run'); - $decorated = new TestPermutationDecorator($test, $permutations); - $decorated->run(); - } - -/** - * Tests that the decorated test is run once per permutation and the supplied - * callback is executed - * - * @return void - */ - public function testRunWithCallback() { - $callback1 = $this->getMock('stdClass', ['__invoke']); - $callback2 = $this->getMock('stdClass', ['__invoke']); - $permutations = [$callback1, $callback2]; - $test = $this->getMockForAbstractClass('\PHPUnit_Framework_Test', ['run', 'count']); - $test->expects($this->exactly(2))->method('run'); - $callback1->expects($this->once())->method('__invoke')->with($test); - $callback2->expects($this->once())->method('__invoke')->with($test); - $decorated = new TestPermutationDecorator($test, $permutations); - $decorated->run(); - } - -}