From 31d9d069c79c61abd22f713292baed9cf3d0b0a1 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 30 Jan 2014 09:22:37 +0100 Subject: [PATCH 01/11] Also test with PHP 5.3.3 on Travis CI --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 2ea0401ccc1..08b3b7c425b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: php php: + - 5.3.3 - 5.3 - 5.4 - 5.5 From 36cc20f7f7efa52947a48cd0d11de1742a28231e Mon Sep 17 00:00:00 2001 From: Jeroen Versteeg Date: Thu, 30 Jan 2014 19:46:27 +0100 Subject: [PATCH 02/11] Fixed a bug in PHPUnit_Framework_Constraint_Count For instances of Iterator, it called [iterator_count](php.net/manual/en/function.iterator-count.php), which (unfortunately) changes the instance's key. This fix `rewind`s the iterator's key to where it was --- PHPUnit/Framework/Constraint/Count.php | 14 ++- Tests/Framework/Constraint/CountTest.php | 130 +++++++++++++++++++++++ Tests/_files/TestIterator.php | 2 +- 3 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 Tests/Framework/Constraint/CountTest.php diff --git a/PHPUnit/Framework/Constraint/Count.php b/PHPUnit/Framework/Constraint/Count.php index 976ce543496..5730033dc56 100644 --- a/PHPUnit/Framework/Constraint/Count.php +++ b/PHPUnit/Framework/Constraint/Count.php @@ -94,8 +94,20 @@ protected function getCountOf($other) } else if ($other instanceof Iterator) { - return iterator_count($other); + $key = $other->key(); + $count = iterator_count($other); + + // manually rewind $other to previous key, since iterator_count moves pointer + if ($key !== null) { + $other->rewind(); + while ($key !== $other->key()) { + $other->next(); + } + } + + return $count; } + } diff --git a/Tests/Framework/Constraint/CountTest.php b/Tests/Framework/Constraint/CountTest.php new file mode 100644 index 00000000000..04f338464bd --- /dev/null +++ b/Tests/Framework/Constraint/CountTest.php @@ -0,0 +1,130 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @package PHPUnit + * @author Sebastian Bergmann + * @author Jeroen Versteeg + * @copyright 2001-2014 Sebastian Bergmann + * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License + * @link http://www.phpunit.de/ + * @since File available since Release 3.9.0 + */ + +require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'TestIterator.php'; + +class TestIterator2 implements Iterator { + + protected $data; + + public function __construct(array $array) + { + $this->data = $array; + } + + public function current() + { + return current($this->data); + } + + public function next() + { + next($this->data); + } + + public function key() + { + return key($this->data); + } + + public function valid() + { + return key($this->data) !== null; + } + + public function rewind() + { + reset($this->data); + } +} + +class CountTest extends PHPUnit_Framework_TestCase { + + public function test_Count() { + $countConstraint = new PHPUnit_Framework_Constraint_Count(3); + $this->assertTrue($countConstraint->evaluate(array(1,2,3), '', true)); + + $countConstraint = new PHPUnit_Framework_Constraint_Count(0); + $this->assertTrue($countConstraint->evaluate(array(), '', true)); + + $countConstraint = new PHPUnit_Framework_Constraint_Count(2); + $it = new TestIterator(array(1, 2)); + $this->assertTrue($countConstraint->evaluate($it, '', true)); + } + + public function test_CountDoesNotChangeIteratorKey () + { + $countConstraint = new PHPUnit_Framework_Constraint_Count(2); + + // test with 1st implementation of Iterator + $it = new TestIterator(array(1, 2)); + + $countConstraint->evaluate($it, '', true); + $this->assertEquals(1, $it->current()); + + $it->next(); + $countConstraint->evaluate($it, '', true); + $this->assertEquals(2, $it->current()); + + $it->next(); + $countConstraint->evaluate($it, '', true); + $this->assertFalse($it->valid()); + + // test with 2nd implementation of Iterator + $it = new TestIterator2(array(1, 2)); + + $countConstraint = new PHPUnit_Framework_Constraint_Count(2); + $countConstraint->evaluate($it, '', true); + $this->assertEquals(1, $it->current()); + + $it->next(); + $countConstraint->evaluate($it, '', true); + $this->assertEquals(2, $it->current()); + + $it->next(); + $countConstraint->evaluate($it, '', true); + $this->assertFalse($it->valid()); + } +} diff --git a/Tests/_files/TestIterator.php b/Tests/_files/TestIterator.php index c834efbb287..01135e3b39a 100644 --- a/Tests/_files/TestIterator.php +++ b/Tests/_files/TestIterator.php @@ -2,7 +2,7 @@ class TestIterator implements Iterator { protected $array; - protected $position; + protected $position = 0; public function __construct($array = array()) { From 2f33258fa5a0c330515b7deba2bc040fa5c3953b Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Fri, 31 Jan 2014 09:54:33 +0100 Subject: [PATCH 03/11] Prepare release --- PHPUnit/Runner/Version.php | 2 +- package.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PHPUnit/Runner/Version.php b/PHPUnit/Runner/Version.php index 20642045cde..a5c4f14b279 100644 --- a/PHPUnit/Runner/Version.php +++ b/PHPUnit/Runner/Version.php @@ -56,7 +56,7 @@ */ class PHPUnit_Runner_Version { - const VERSION = '3.7.29'; + const VERSION = '3.7.30'; protected static $version; /** diff --git a/package.xml b/package.xml index 14decb05d79..90473879e2f 100644 --- a/package.xml +++ b/package.xml @@ -17,9 +17,9 @@ sebastian@phpunit.de yes - 2014-01-15 + 2014-01-31 - 3.7.29 + 3.7.30 3.7.0 From d24e9877331039582497052cc3c4d9f465b88210 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Mon, 3 Feb 2014 08:46:27 +0100 Subject: [PATCH 04/11] Prepare release --- PHPUnit/Runner/Version.php | 2 +- package.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PHPUnit/Runner/Version.php b/PHPUnit/Runner/Version.php index a5c4f14b279..5d626669715 100644 --- a/PHPUnit/Runner/Version.php +++ b/PHPUnit/Runner/Version.php @@ -56,7 +56,7 @@ */ class PHPUnit_Runner_Version { - const VERSION = '3.7.30'; + const VERSION = '3.7.31'; protected static $version; /** diff --git a/package.xml b/package.xml index 90473879e2f..5d743d543c6 100644 --- a/package.xml +++ b/package.xml @@ -17,9 +17,9 @@ sebastian@phpunit.de yes - 2014-01-31 + 2014-02-03 - 3.7.30 + 3.7.31 3.7.0 From a0e176b7108380e32eb268bd5f31589c37786623 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sat, 15 Feb 2014 12:53:20 +0100 Subject: [PATCH 05/11] Test with PHP 5.6 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 08b3b7c425b..0c6bfe73a49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ php: - 5.3 - 5.4 - 5.5 + - 5.6 - hhvm env: From 5728eadfb7859241d7aafd26592cee0ad1876d2d Mon Sep 17 00:00:00 2001 From: Jeff Welch Date: Sat, 15 Feb 2014 17:46:11 -0500 Subject: [PATCH 06/11] Fixed annotation. --- Tests/Framework/Constraint/CountTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Framework/Constraint/CountTest.php b/Tests/Framework/Constraint/CountTest.php index 04f338464bd..714ea1b6d3d 100644 --- a/Tests/Framework/Constraint/CountTest.php +++ b/Tests/Framework/Constraint/CountTest.php @@ -40,7 +40,7 @@ * @copyright 2001-2014 Sebastian Bergmann * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License * @link http://www.phpunit.de/ - * @since File available since Release 3.9.0 + * @since File available since Release 3.7.30 */ require_once __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'TestIterator.php'; From f727e49f0f7f6db50ce134a2863cd01b6d55e640 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Mon, 24 Feb 2014 22:31:06 -0500 Subject: [PATCH 07/11] Workaround for https://github.com/composer/composer/issues/2757 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b4fc81dc4c4..c2fe3a36939 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "ext-spl": "*" }, "require-dev": { - "pear-pear/pear": "1.9.4" + "pear-pear.php.net/pear": "1.9.4" }, "repositories": [ { From 2752cbb9ea5bd84c2811b34b6953f76965ec7a2f Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Mon, 24 Feb 2014 22:47:29 -0500 Subject: [PATCH 08/11] Prepare release --- PHPUnit/Runner/Version.php | 2 +- package.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PHPUnit/Runner/Version.php b/PHPUnit/Runner/Version.php index 5d626669715..7a4b92c2bf4 100644 --- a/PHPUnit/Runner/Version.php +++ b/PHPUnit/Runner/Version.php @@ -56,7 +56,7 @@ */ class PHPUnit_Runner_Version { - const VERSION = '3.7.31'; + const VERSION = '3.7.32'; protected static $version; /** diff --git a/package.xml b/package.xml index 5d743d543c6..cc777e49c9a 100644 --- a/package.xml +++ b/package.xml @@ -17,9 +17,9 @@ sebastian@phpunit.de yes - 2014-02-03 + 2014-02-24 - 3.7.31 + 3.7.32 3.7.0 From 316a5478cc552056ccd3bd27fa0aa8645b2d0a59 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Fri, 28 Feb 2014 05:34:19 -0500 Subject: [PATCH 09/11] Use ~ operator --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index c2fe3a36939..52e8600f96f 100644 --- a/composer.json +++ b/composer.json @@ -22,10 +22,10 @@ }, "require": { "php": ">=5.3.3", - "phpunit/php-file-iterator": ">=1.3.1", - "phpunit/php-text-template": ">=1.1.1", + "phpunit/php-file-iterator": "~1.3.1", + "phpunit/php-text-template": "~1.1.1", "phpunit/php-code-coverage": "~1.2.1", - "phpunit/php-timer": ">=1.0.4", + "phpunit/php-timer": "~1.0.4", "phpunit/phpunit-mock-objects": "~1.2.0", "symfony/yaml": "~2.0", "ext-dom": "*", @@ -43,7 +43,7 @@ } ], "suggest": { - "phpunit/php-invoker": ">=1.1.0,<1.2.0", + "phpunit/php-invoker": "~1.1", "ext-json": "*", "ext-simplexml": "*", "ext-tokenizer": "*" From a0a0c59adf63f5ca24cdded0d6235db432a61c2a Mon Sep 17 00:00:00 2001 From: Jeff Welch Date: Wed, 5 Mar 2014 06:39:30 -0500 Subject: [PATCH 10/11] Fixes #1159. Relax space requirements and greediness. --- PHPUnit/Util/Test.php | 2 +- Tests/Util/TestTest.php | 1 + Tests/_files/RequirementsTest.php | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/PHPUnit/Util/Test.php b/PHPUnit/Util/Test.php index 98392a5164d..d2639df0b2e 100644 --- a/PHPUnit/Util/Test.php +++ b/PHPUnit/Util/Test.php @@ -59,7 +59,7 @@ class PHPUnit_Util_Test const REGEX_DATA_PROVIDER = '/@dataProvider\s+([a-zA-Z0-9._:-\\\\x7f-\xff]+)/'; const REGEX_EXPECTED_EXCEPTION = '(@expectedException\s+([:.\w\\\\x7f-\xff]+)(?:[\t ]+(\S*))?(?:[\t ]+(\S*))?\s*$)m'; const REGEX_REQUIRES_VERSION = '/@requires\s+(?PPHP(?:Unit)?)\s+(?P[\d\.-]+(dev|(RC|alpha|beta)[\d\.])?)[ \t]*\r?$/m'; - const REGEX_REQUIRES = '/@requires\s+(?Pfunction|extension)\s(?P([^ ]+))\r?$/m'; + const REGEX_REQUIRES = '/@requires\s+(?Pfunction|extension)\s+(?P([^ ]+?))[ \t]*\r?$/m'; const SMALL = 0; const MEDIUM = 1; diff --git a/Tests/Util/TestTest.php b/Tests/Util/TestTest.php index 75508f1fc2c..6a0d01c4163 100644 --- a/Tests/Util/TestTest.php +++ b/Tests/Util/TestTest.php @@ -136,6 +136,7 @@ public function provideRequirements() array('testEight', array('PHP' => '5.4-dev')), array('testNine', array('functions' => array('testFunc'))), array('testTen', array('extensions' => array('testExt'))), + array('testSpace', array('extensions' => array('spl'))), array( 'testAllPossibleRequirements', array( diff --git a/Tests/_files/RequirementsTest.php b/Tests/_files/RequirementsTest.php index 1ac6a06c411..62a9e88f9db 100644 --- a/Tests/_files/RequirementsTest.php +++ b/Tests/_files/RequirementsTest.php @@ -109,4 +109,11 @@ public function testAlwaysSkip() public function testAlwaysSkip2() { } + + /** + * @requires extension spl + */ + public function testSpace() + { + } } From e49cdc4c9ab6e193f7375300cef84c566d159297 Mon Sep 17 00:00:00 2001 From: Jeff Welch Date: Wed, 5 Mar 2014 07:36:00 -0500 Subject: [PATCH 11/11] Refs #1159. Sync a0a0c59. --- src/Util/Test.php | 2 +- tests/Util/TestTest.php | 8 +++++++- tests/_files/RequirementsTest.php | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Util/Test.php b/src/Util/Test.php index 83acdc566b7..366d4027c59 100644 --- a/src/Util/Test.php +++ b/src/Util/Test.php @@ -66,7 +66,7 @@ class PHPUnit_Util_Test const REGEX_DATA_PROVIDER = '/@dataProvider\s+([a-zA-Z0-9._:-\\\\x7f-\xff]+)/'; const REGEX_EXPECTED_EXCEPTION = '(@expectedException\s+([:.\w\\\\x7f-\xff]+)(?:[\t ]+(\S*))?(?:[\t ]+(\S*))?\s*$)m'; const REGEX_REQUIRES_VERSION = '/@requires\s+(?PPHP(?:Unit)?)\s+(?P[\d\.-]+(dev|(RC|alpha|beta)[\d\.])?)[ \t]*\r?$/m'; - const REGEX_REQUIRES_OS = '/@requires\s+OS\s+(?P.+)\r?$/m'; + const REGEX_REQUIRES_OS = '/@requires\s+OS\s+(?P.+?)[ \t]*\r?$/m'; const REGEX_REQUIRES = '/@requires\s+(?Pfunction|extension)\s+(?P([^ ]+?))[ \t]*\r?$/m'; const SMALL = 0; diff --git a/tests/Util/TestTest.php b/tests/Util/TestTest.php index 90e2c6243b3..0a2fcc69660 100644 --- a/tests/Util/TestTest.php +++ b/tests/Util/TestTest.php @@ -139,8 +139,14 @@ public function provideRequirements() array('testEight', array('PHP' => '5.4-dev')), array('testNine', array('functions' => array('testFunc'))), array('testTen', array('extensions' => array('testExt'))), - array('testSpace', array('extensions' => array('spl'))), array('testEleven', array('OS' => '/Linux/i')), + array( + 'testSpace', + array( + 'extensions' => array('spl'), + 'OS' => '/.*/i' + ) + ), array( 'testAllPossibleRequirements', array( diff --git a/tests/_files/RequirementsTest.php b/tests/_files/RequirementsTest.php index b04883d7e45..76355c27949 100644 --- a/tests/_files/RequirementsTest.php +++ b/tests/_files/RequirementsTest.php @@ -134,6 +134,7 @@ public function testAlwaysSkip3() /** * @requires extension spl + * @requires OS .* */ public function testSpace() {