summaryrefslogtreecommitdiffstats
path: root/php-hamcrest-upstream.patch
blob: 65c3ec6967ac054e9b550059fe86ea5637bb4db7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
From c2aecc2127c92e5e6a77b9b23bf3f409ffd56e4a Mon Sep 17 00:00:00 2001
From: mikeSimonson <mike.simonson@gmail.com>
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()