Skip to content

Commit 010dfd4

Browse files
author
Hamish Friedlander
committed
Update hamcrest-php to latest (fixes PHP 5.4 compatibility)
1 parent 5c5a292 commit 010dfd4

37 files changed

+896
-466
lines changed

hamcrest-php/.piston.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
format: 1
33
handler:
4-
piston:remote-revision: 718
4+
piston:remote-revision: 739
55
piston:uuid: 2aa0e9f1-8e24-0410-adc4-1b6a3a6e65e2
6-
lock: false
76
repository_class: Piston::Svn::Repository
87
repository_url: http://hamcrest.googlecode.com/svn/trunk/hamcrest-php
8+
lock: false

hamcrest-php/CHANGES.txt

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
1-
== Version 1.0.0: Not Released ==
1+
== Version 1.1.0: Released Feb 2 2012 ==
22

3-
Issues Fixed: 119, 136, 139, 141
3+
Issues Fixed: 121, 138, 147
44

5-
* Moved hamcrest.php into hamcrest folder and renamed to Hamcrest.php.
5+
* Added non-empty matchers to complement the emptiness-matching forms.
6+
7+
- nonEmptyString()
8+
- nonEmptyArray()
9+
- nonEmptyTraversable()
10+
11+
* Added ability to pass variable arguments to several array-based matcher
12+
factory methods so they work like allOf() et al.
13+
14+
- anArray()
15+
- arrayContainingInAnyOrder(), containsInAnyOrder()
16+
- arrayContaining(), contains()
17+
- stringContainsInOrder()
18+
19+
* Matchers that accept an array of matchers now also accept variable arguments.
20+
Any non-matcher arguments are wrapped by IsEqual.
21+
22+
* Added noneOf() as a shortcut for not(anyOf()).
23+
24+
25+
== Version 1.0.0: Released Jan 20 2012 ==
26+
27+
Issues Fixed: 119, 136, 139, 141, 148, 149, 172
28+
29+
* Moved hamcrest.php into Hamcrest folder and renamed to Hamcrest.php.
630
This is more in line with PEAR packaging standards.
731

32+
* Renamed callable() to callableValue() for compatibility with PHP 5.4.
33+
834
* Added Hamcrest_Text_StringContainsIgnoringCase to assert using stripos().
935

1036
assertThat('fOObAr', containsStringIgnoringCase('oba'));
@@ -118,6 +144,7 @@ Issues Fixed: 109, 111, 114, 115
118144
assertThat(array('SomeClass', 'SomeMethod'), callable());
119145
assertThat(array($object, 'SomeMethod'), callable());
120146
assertThat($object, callable());
147+
assertThat(function ($x, $y) { return $x + $y; }, callable());
121148

122149
* Added Hamcrest_Text_MatchesPattern for regex matching with preg_match().
123150

hamcrest-php/hamcrest/Hamcrest.php

+73-19
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ function assertThat()
3434
/**
3535
* Evaluates to true only if each $matcher[$i] is satisfied by $array[$i].
3636
*/
37-
function anArray($array)
37+
function anArray(/* args... */)
3838
{
3939
require_once 'Hamcrest/Array/IsArray.php';
40-
return Hamcrest_Array_IsArray::anArray($array);
40+
$args = func_get_args();
41+
return call_user_func_array(array('Hamcrest_Array_IsArray', 'anArray'), $args);
4142
}
4243

4344
/**
@@ -65,37 +66,41 @@ function hasValue($item)
6566
/**
6667
* An array with elements that match the given matchers.
6768
*/
68-
function arrayContainingInAnyOrder(array $items)
69+
function arrayContainingInAnyOrder(/* args... */)
6970
{
7071
require_once 'Hamcrest/Array/IsArrayContainingInAnyOrder.php';
71-
return Hamcrest_Array_IsArrayContainingInAnyOrder::arrayContainingInAnyOrder($items);
72+
$args = func_get_args();
73+
return call_user_func_array(array('Hamcrest_Array_IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args);
7274
}
7375

7476
/**
7577
* An array with elements that match the given matchers.
7678
*/
77-
function containsInAnyOrder(array $items)
79+
function containsInAnyOrder(/* args... */)
7880
{
7981
require_once 'Hamcrest/Array/IsArrayContainingInAnyOrder.php';
80-
return Hamcrest_Array_IsArrayContainingInAnyOrder::arrayContainingInAnyOrder($items);
82+
$args = func_get_args();
83+
return call_user_func_array(array('Hamcrest_Array_IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args);
8184
}
8285

8386
/**
8487
* An array with elements that match the given matchers in the same order.
8588
*/
86-
function arrayContaining(array $items)
89+
function arrayContaining(/* args... */)
8790
{
8891
require_once 'Hamcrest/Array/IsArrayContainingInOrder.php';
89-
return Hamcrest_Array_IsArrayContainingInOrder::arrayContaining($items);
92+
$args = func_get_args();
93+
return call_user_func_array(array('Hamcrest_Array_IsArrayContainingInOrder', 'arrayContaining'), $args);
9094
}
9195

9296
/**
9397
* An array with elements that match the given matchers in the same order.
9498
*/
95-
function contains(array $items)
99+
function contains(/* args... */)
96100
{
97101
require_once 'Hamcrest/Array/IsArrayContainingInOrder.php';
98-
return Hamcrest_Array_IsArrayContainingInOrder::arrayContaining($items);
102+
$args = func_get_args();
103+
return call_user_func_array(array('Hamcrest_Array_IsArrayContainingInOrder', 'arrayContaining'), $args);
99104
}
100105

101106
/**
@@ -140,6 +145,8 @@ function hasEntry($key, $value)
140145

141146
/**
142147
* Does array size satisfy a given matcher?
148+
*
149+
* @param int $size as a {@link Hamcrest_Matcher} or a value.
143150
*/
144151
function arrayWithSize($size)
145152
{
@@ -157,14 +164,32 @@ function emptyArray()
157164
}
158165

159166
/**
160-
* Is traversable empty?
167+
* Matches an empty array.
168+
*/
169+
function nonEmptyArray()
170+
{
171+
require_once 'Hamcrest/Array/IsArrayWithSize.php';
172+
return Hamcrest_Array_IsArrayWithSize::nonEmptyArray();
173+
}
174+
175+
/**
176+
* Returns true if traversable is empty.
161177
*/
162178
function emptyTraversable()
163179
{
164180
require_once 'Hamcrest/Collection/IsEmptyTraversable.php';
165181
return Hamcrest_Collection_IsEmptyTraversable::emptyTraversable();
166182
}
167183

184+
/**
185+
* Returns true if traversable is not empty.
186+
*/
187+
function nonEmptyTraversable()
188+
{
189+
require_once 'Hamcrest/Collection/IsEmptyTraversable.php';
190+
return Hamcrest_Collection_IsEmptyTraversable::nonEmptyTraversable();
191+
}
192+
168193
/**
169194
* Does traversable size satisfy a given matcher?
170195
*/
@@ -194,6 +219,16 @@ function anyOf(/* args... */)
194219
return call_user_func_array(array('Hamcrest_Core_AnyOf', 'anyOf'), $args);
195220
}
196221

222+
/**
223+
* Evaluates to false if ANY of the passed in matchers evaluate to true.
224+
*/
225+
function noneOf(/* args... */)
226+
{
227+
require_once 'Hamcrest/Core/AnyOf.php';
228+
$args = func_get_args();
229+
return call_user_func_array(array('Hamcrest_Core_AnyOf', 'noneOf'), $args);
230+
}
231+
197232
/**
198233
* This is useful for fluently combining matchers that must both pass.
199234
* For example:
@@ -493,7 +528,7 @@ function atMost($value)
493528
}
494529

495530
/**
496-
* Matches if value is zero-length string.
531+
* Matches if value is a zero-length string.
497532
*/
498533
function isEmptyString()
499534
{
@@ -502,7 +537,7 @@ function isEmptyString()
502537
}
503538

504539
/**
505-
* Matches if value is zero-length string.
540+
* Matches if value is a zero-length string.
506541
*/
507542
function emptyString()
508543
{
@@ -511,7 +546,7 @@ function emptyString()
511546
}
512547

513548
/**
514-
* Matches if value is null or zero-length string.
549+
* Matches if value is null or a zero-length string.
515550
*/
516551
function isEmptyOrNullString()
517552
{
@@ -520,14 +555,32 @@ function isEmptyOrNullString()
520555
}
521556

522557
/**
523-
* Matches if value is null or zero-length string.
558+
* Matches if value is null or a zero-length string.
524559
*/
525560
function nullOrEmptyString()
526561
{
527562
require_once 'Hamcrest/Text/IsEmptyString.php';
528563
return Hamcrest_Text_IsEmptyString::isEmptyOrNullString();
529564
}
530565

566+
/**
567+
* Matches if value is a non-zero-length string.
568+
*/
569+
function isNonEmptyString()
570+
{
571+
require_once 'Hamcrest/Text/IsEmptyString.php';
572+
return Hamcrest_Text_IsEmptyString::isNonEmptyString();
573+
}
574+
575+
/**
576+
* Matches if value is a non-zero-length string.
577+
*/
578+
function nonEmptyString()
579+
{
580+
require_once 'Hamcrest/Text/IsEmptyString.php';
581+
return Hamcrest_Text_IsEmptyString::isNonEmptyString();
582+
}
583+
531584
/**
532585
* Matches if value is a string equal to $string, regardless of the case.
533586
*/
@@ -576,10 +629,11 @@ function containsStringIgnoringCase($substring)
576629
/**
577630
* Matches if value contains $substrings in a constrained order.
578631
*/
579-
function stringContainsInOrder(array $substrings)
632+
function stringContainsInOrder(/* args... */)
580633
{
581634
require_once 'Hamcrest/Text/StringContainsInOrder.php';
582-
return Hamcrest_Text_StringContainsInOrder::stringContainsInOrder($substrings);
635+
$args = func_get_args();
636+
return call_user_func_array(array('Hamcrest_Text_StringContainsInOrder', 'stringContainsInOrder'), $args);
583637
}
584638

585639
/**
@@ -630,10 +684,10 @@ function boolValue()
630684
/**
631685
* Is the value callable?
632686
*/
633-
function callable()
687+
function callableValue()
634688
{
635689
require_once 'Hamcrest/Type/IsCallable.php';
636-
return Hamcrest_Type_IsCallable::callable();
690+
return Hamcrest_Type_IsCallable::callableValue();
637691
}
638692

639693
/**

hamcrest-php/hamcrest/Hamcrest/Array/IsArray.php

+21-18
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,36 @@
1818
*/
1919
class Hamcrest_Array_IsArray extends Hamcrest_TypeSafeMatcher
2020
{
21-
21+
2222
private $_elementMatchers;
23-
23+
2424
public function __construct(array $elementMatchers)
2525
{
2626
parent::__construct(self::TYPE_ARRAY);
27-
27+
28+
Hamcrest_Util::checkAllAreMatchers($elementMatchers);
29+
2830
$this->_elementMatchers = $elementMatchers;
2931
}
30-
32+
3133
protected function matchesSafely($array)
3234
{
3335
if (array_keys($array) != array_keys($this->_elementMatchers))
3436
{
3537
return false;
3638
}
37-
39+
3840
foreach ($this->_elementMatchers as $k => $matcher)
3941
{
4042
if (!$matcher->matches($array[$k]))
4143
{
4244
return false;
4345
}
4446
}
45-
47+
4648
return true;
4749
}
48-
50+
4951
protected function describeMismatchSafely($actual,
5052
Hamcrest_Description $mismatchDescription)
5153
{
@@ -66,7 +68,7 @@ protected function describeMismatchSafely($actual,
6668
;
6769
return;
6870
}
69-
71+
7072
foreach ($this->_elementMatchers as $k => $matcher)
7173
{
7274
if (!$matcher->matches($actual[$k]))
@@ -78,7 +80,7 @@ protected function describeMismatchSafely($actual,
7880
}
7981
}
8082
}
81-
83+
8284
public function describeTo(Hamcrest_Description $description)
8385
{
8486
$description->appendList(
@@ -88,32 +90,33 @@ public function describeTo(Hamcrest_Description $description)
8890
$this->_elementMatchers
8991
);
9092
}
91-
93+
9294
/**
9395
* Evaluates to true only if each $matcher[$i] is satisfied by $array[$i].
9496
*
95-
* @factory
97+
* @factory ...
9698
*/
97-
public static function anArray($array)
99+
public static function anArray(/* args... */)
98100
{
99-
return new self($array);
101+
$args = func_get_args();
102+
return new self(Hamcrest_Util::createMatcherArray($args));
100103
}
101-
104+
102105
// -- Protected Methods
103-
106+
104107
protected function descriptionStart()
105108
{
106109
return '[';
107110
}
108-
111+
109112
protected function descriptionSeparator()
110113
{
111114
return ', ';
112115
}
113-
116+
114117
protected function descriptionEnd()
115118
{
116119
return ']';
117120
}
118-
121+
119122
}

0 commit comments

Comments
 (0)