From f5fe6edc1bfb8ad4bd8a25df3cb7dc029fdcd592 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 17 Feb 2017 17:23:45 +0100 Subject: php-hamcrest: add PHP 7 patch --- composer.json | 32 +++++++++++++++++++++ php-hamcrest-upstream.patch | 69 +++++++++++++++++++++++++++++++++++++++++++++ php-hamcrest.spec | 25 +++++++++++++--- 3 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 composer.json create mode 100644 php-hamcrest-upstream.patch diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a1b48c1 --- /dev/null +++ b/composer.json @@ -0,0 +1,32 @@ +{ + "name": "hamcrest/hamcrest-php", + "type": "library", + "description": "This is the PHP port of Hamcrest Matchers", + "keywords": ["test"], + "license": "BSD", + "authors": [ + ], + + "autoload": { + "classmap": ["hamcrest"], + "files": ["hamcrest/Hamcrest.php"] + }, + "autoload-dev": { + "classmap": ["tests", "generator"] + }, + + "require": { + "php": ">=5.3.2" + }, + + "require-dev": { + "satooshi/php-coveralls": "dev-master", + "phpunit/php-file-iterator": "1.3.3" + }, + + "replace": { + "kodova/hamcrest-php": "*", + "davedevelopment/hamcrest-php": "*", + "cordoval/hamcrest-php": "*" + } +} diff --git a/php-hamcrest-upstream.patch b/php-hamcrest-upstream.patch new file mode 100644 index 0000000..65c3ec6 --- /dev/null +++ b/php-hamcrest-upstream.patch @@ -0,0 +1,69 @@ +From c2aecc2127c92e5e6a77b9b23bf3f409ffd56e4a Mon Sep 17 00:00:00 2001 +From: mikeSimonson +Date: Wed, 6 Jan 2016 22:26:02 +0100 +Subject: [PATCH] Removing php 7 from the allowed failure + +Fixing the backward incompatible change of PHP 7 and adding tests for it. +--- + .travis.yml | 1 - + hamcrest/Hamcrest/Type/IsNumeric.php | 20 ++++++++++++++++++++ + tests/Hamcrest/Type/IsNumericTest.php | 4 ++++ + 3 files changed, 24 insertions(+), 1 deletion(-) + +diff --git a/hamcrest/Hamcrest/Type/IsNumeric.php b/hamcrest/Hamcrest/Type/IsNumeric.php +index 9fe8a7a..bc74405 100644 +--- a/hamcrest/Hamcrest/Type/IsNumeric.php ++++ b/hamcrest/Hamcrest/Type/IsNumeric.php +@@ -19,10 +19,30 @@ public function __construct() + + public function matches($item) + { ++ if ($this->isHexadecimal($item)) { ++ return true; ++ } ++ + return is_numeric($item); + } + + /** ++ * Return if the string passed is a valid hexadecimal number. ++ * This check is necessary because PHP 7 doesn't recognize hexadecimal string as numeric anymore. ++ * ++ * @param mixed $item ++ * @return boolean ++ */ ++ private function isHexadecimal($item) ++ { ++ if (is_string($item) && preg_match('/^0x(.*)$/', $item, $matches)) { ++ return ctype_xdigit($matches[1]); ++ } ++ ++ return false; ++ } ++ ++ /** + * Is the value a numeric? + * + * @factory +diff --git a/tests/Hamcrest/Type/IsNumericTest.php b/tests/Hamcrest/Type/IsNumericTest.php +index e718485..1fd83ef 100644 +--- a/tests/Hamcrest/Type/IsNumericTest.php ++++ b/tests/Hamcrest/Type/IsNumericTest.php +@@ -25,6 +25,7 @@ public function testEvaluatesToTrueIfArgumentMatchesType() + assertThat('0.053e-2', numericValue()); + assertThat('-53.253e+25', numericValue()); + assertThat('+53.253e+25', numericValue()); ++ assertThat(0x4F2a04, numericValue()); + assertThat('0x4F2a04', numericValue()); + } + +@@ -34,6 +35,9 @@ public function testEvaluatesToFalseIfArgumentDoesntMatchType() + assertThat('foo', not(numericValue())); + assertThat('foo5', not(numericValue())); + assertThat('5foo', not(numericValue())); ++ assertThat('0x42A04G', not(numericValue())); // G is not in the hexadecimal range. ++ assertThat('1x42A04', not(numericValue())); // 1x is not a valid hexadecimal sequence. ++ assertThat('0x', not(numericValue())); + } + + public function testHasAReadableDescription() diff --git a/php-hamcrest.spec b/php-hamcrest.spec index 673893b..3742c53 100644 --- a/php-hamcrest.spec +++ b/php-hamcrest.spec @@ -14,7 +14,7 @@ Name: php-hamcrest Version: 1.2.2 -Release: 1%{?dist} +Release: 4%{?dist} Summary: PHP port of Hamcrest Matchers Group: Development/Libraries @@ -24,10 +24,12 @@ Source0: https://github.com/%{gh_owner}/%{gh_project}/archive/%{gh_commit # Use generated autoloader instead of composer one Patch0: bootstrap-autoload.patch +# Upstream patch for PHP 7+ +Patch1: %{name}-upstream.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildArch: noarch -BuildRequires: php-composer(theseer/autoload) +BuildRequires: php-fedora-autoloader-devel %if %{with_tests} BuildRequires: php-composer(phpunit/phpunit) # composer.json @@ -44,6 +46,8 @@ Requires: php(language) >= 5.3.2 Requires: php-dom Requires: php-pcre Requires: php-spl +# Autoloader +Requires: php-composer(fedora/autoloader) Provides: php-composer(hamcrest/hamcrest-php) = %{version} @@ -64,6 +68,8 @@ To use this library, you just have to add, in your project: %setup -q -n %{gh_project}-%{gh_commit} %patch0 -p0 -b .rpm +%patch1 -p1 -b .upstream +find . -name \*.upstream -exec rm {} \; # Move to Library tree mv hamcrest/Hamcrest.php hamcrest/Hamcrest/Hamcrest.php @@ -72,6 +78,7 @@ mv hamcrest/Hamcrest.php hamcrest/Hamcrest/Hamcrest.php %build # Library autoloader %{_bindir}/phpab \ + --template fedora \ --output hamcrest/Hamcrest/autoload.php \ hamcrest/Hamcrest @@ -97,7 +104,13 @@ cp -pr hamcrest/* %{buildroot}%{_datadir}/php %check %if %{with_tests} cd tests -%{_bindir}/phpunit --verbose +ret=0 +for cmd in php56 php70 php71 php; do + if which $cmd; then + $cmd %{_bindir}/phpunit --verbose || ret=1 + fi +done +exit $ret %else : Test suite disabled %endif @@ -117,8 +130,12 @@ rm -rf %{buildroot} %changelog +* Fri Feb 17 2017 Remi Collet - 1.2.2-4 +- add upstream patch for PHP 7, fix FTBFS +- switch to fedora/autoloader + * Thu Oct 15 2015 Remi Collet - 1.2.2-1 - update to 1.2.2 * Mon Jan 5 2015 Remi Collet - 1.2.0-1 -- initial package \ No newline at end of file +- initial package -- cgit