Upgrade framework

This commit is contained in:
2023-11-14 16:54:35 +01:00
parent 1648a5cd42
commit 4fcf6fffcc
10548 changed files with 693138 additions and 466698 deletions

View File

@@ -0,0 +1,38 @@
name: tests
on:
push:
pull_request:
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
name: PHP ${{ matrix.php }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl
tools: composer:v2
coverage: none
- name: Install PHP 7 dependencies
run: composer update --prefer-dist --no-interaction --no-progress
if: "matrix.php != '8.0'"
- name: Install PHP 8 dependencies
run: composer update --prefer-dist --no-interaction --no-progress --ignore-platform-reqs
if: "matrix.php == '8.0'"
- name: Execute tests
run: vendor/bin/phpunit -c tests/phpunit.xml.dist

View File

@@ -1,2 +1,2 @@
vendor
composer.lock
vendor

View File

@@ -1,18 +1,23 @@
language: php
php:
- 5.4
- 5.3
dist: trusty
matrix:
include:
- name: PHP 5.3
php: 5.3
dist: precise
- name: PHP 5.4
php: 5.4
- name: PHP 5.5
php: 5.5
- name: PHP 5.6
php: 5.6
- name: HHVM 3.18
php: hhvm-3.18
install:
- composer install
- travis_retry composer update --prefer-dist --no-progress
script:
- mkdir -p build/logs
- cd tests
- phpunit --coverage-clover=../build/logs/clover.xml .
- cd ../
after_script:
- php vendor/bin/coveralls -v
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
- vendor/bin/phpunit -c tests/phpunit.xml.dist

View File

@@ -1,3 +1,13 @@
== Version 2.0.1: Released Jul 09 2020 ==
* Added support for PHP 8
== Version 2.0: Released Feb 26 2016 ==
* Removed automatic loading of global functions
== Version 1.1.0: Released Feb 2 2012 ==
Issues Fixed: 121, 138, 147

View File

@@ -1,9 +1,7 @@
This is the PHP port of Hamcrest Matchers
=========================================
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/hamcrest/hamcrest-php/badges/quality-score.png?s=754f5c0556419fc6204917ca9a9dcf2fa2b45ed0)](https://scrutinizer-ci.com/g/hamcrest/hamcrest-php/)
[![Build Status](https://travis-ci.org/hamcrest/hamcrest-php.png?branch=master)](https://travis-ci.org/hamcrest/hamcrest-php)
[![Coverage Status](https://coveralls.io/repos/hamcrest/hamcrest-php/badge.png)](https://coveralls.io/r/hamcrest/hamcrest-php)
Hamcrest is a matching library originally written for Java, but
subsequently ported to many other languages. hamcrest-php is the
@@ -37,6 +35,12 @@ Exceptions, mostly down to PHP language barriers:
conventions between Java's Arrays, Collections, Sets and Maps compared
with PHP's Arrays.
---
** [Unless we consider POPO's (Plain Old PHP Objects) akin to JavaBeans]
- The POPO thing is a joke. Java devs coin the term POJO's (Plain Old
Java Objects).
Usage
-----
@@ -46,6 +50,439 @@ Hamcrest matchers are easy to use as:
Hamcrest_MatcherAssert::assertThat('a', Hamcrest_Matchers::equalToIgnoringCase('A'));
```
** [Unless we consider POPO's (Plain Old PHP Objects) akin to JavaBeans]
- The POPO thing is a joke. Java devs coin the term POJO's (Plain Old
Java Objects).
Alternatively, you can use the global proxy-functions:
```php
$result = true;
// with an identifier
assertThat("result should be true", $result, equalTo(true));
// without an identifier
assertThat($result, equalTo(true));
// evaluate a boolean expression
assertThat($result === true);
// with syntactic sugar is()
assertThat(true, is(true));
```
:warning: **NOTE:** the global proxy-functions aren't autoloaded by default, so you will need to load them first:
```php
\Hamcrest\Util::registerGlobalFunctions();
```
For brevity, all of the examples below use the proxy-functions.
Documentation
-------------
A tutorial can be found on the [Hamcrest site](https://code.google.com/archive/p/hamcrest/wikis/TutorialPHP.wiki).
Available Matchers
------------------
* [Array](../master/README.md#array)
* [Collection](../master/README.md#collection)
* [Object](../master/README.md#object)
* [Numbers](../master/README.md#numbers)
* [Type checking](../master/README.md#type-checking)
* [XML](../master/README.md#xml)
### Array
* `anArray` - evaluates an array
```php
assertThat([], anArray());
```
* `hasItemInArray` - check if item exists in array
```php
$list = range(2, 7, 2);
$item = 4;
assertThat($list, hasItemInArray($item));
```
* `hasValue` - alias of hasItemInArray
* `arrayContainingInAnyOrder` - check if array contains elements in any order
```php
assertThat([2, 4, 6], arrayContainingInAnyOrder([6, 4, 2]));
assertThat([2, 4, 6], arrayContainingInAnyOrder([4, 2, 6]));
```
* `containsInAnyOrder` - alias of arrayContainingInAnyOrder
* `arrayContaining` - An array with elements that match the given matchers in the same order.
```php
assertThat([2, 4, 6], arrayContaining([2, 4, 6]));
assertthat([2, 4, 6], not(arrayContaining([6, 4, 2])));
```
* `contains` - check array in same order
```php
assertThat([2, 4, 6], contains([2, 4, 6]));
```
* `hasKeyInArray` - check if array has given key
```php
assertThat(['name'=> 'foobar'], hasKeyInArray('name'));
```
* `hasKey` - alias of hasKeyInArray
* `hasKeyValuePair` - check if arary has given key, value pair
```php
assertThat(['name'=> 'foobar'], hasKeyValuePair('name', 'foobar'));
```
* `hasEntry` - same as hasKeyValuePair
* `arrayWithSize` - check array has given size
```php
assertthat([2, 4, 6], arrayWithSize(3));
```
* `emptyArray` - check if array is emtpy
```php
assertThat([], emptyArray());
```
* `nonEmptyArray`
```php
assertThat([1], nonEmptyArray());
```
### Collection
* `emptyTraversable` - check if traversable is empty
```php
$empty_it = new EmptyIterator;
assertThat($empty_it, emptyTraversable());
```
* `nonEmptyTraversable` - check if traversable isn't empty
```php
$non_empty_it = new ArrayIterator(range(1, 10));
assertThat($non_empty_it, nonEmptyTraversable());
a
```
* `traversableWithSize`
```php
$non_empty_it = new ArrayIterator(range(1, 10));
assertThat($non_empty_it, traversableWithSize(count(range(1, 10))));
`
```
### Core
* `allOf` - Evaluates to true only if ALL of the passed in matchers evaluate to true.
```php
assertThat([2,4,6], allOf(hasValue(2), arrayWithSize(3)));
```
* `anyOf` - Evaluates to true if ANY of the passed in matchers evaluate to true.
```php
assertThat([2, 4, 6], anyOf(hasValue(8), hasValue(2)));
```
* `noneOf` - Evaluates to false if ANY of the passed in matchers evaluate to true.
```php
assertThat([2, 4, 6], noneOf(hasValue(1), hasValue(3)));
```
* `both` + `andAlso` - This is useful for fluently combining matchers that must both pass.
```php
assertThat([2, 4, 6], both(hasValue(2))->andAlso(hasValue(4)));
```
* `either` + `orElse` - This is useful for fluently combining matchers where either may pass,
```php
assertThat([2, 4, 6], either(hasValue(2))->orElse(hasValue(4)));
```
* `describedAs` - Wraps an existing matcher and overrides the description when it fails.
```php
$expected = "Dog";
$found = null;
// this assertion would result error message as Expected: is not null but: was null
//assertThat("Expected {$expected}, got {$found}", $found, is(notNullValue()));
// and this assertion would result error message as Expected: Dog but: was null
//assertThat($found, describedAs($expected, notNullValue()));
```
* `everyItem` - A matcher to apply to every element in an array.
```php
assertThat([2, 4, 6], everyItem(notNullValue()));
```
* `hasItem` - check array has given item, it can take a matcher argument
```php
assertThat([2, 4, 6], hasItem(equalTo(2)));
```
* `hasItems` - check array has givem items, it can take multiple matcher as arguments
```php
assertThat([1, 3, 5], hasItems(equalTo(1), equalTo(3)));
```
### Object
* `hasToString` - check `__toString` or `toString` method
```php
class Foo {
public $name = null;
public function __toString() {
return "[Foo]Instance";
}
}
$foo = new Foo;
assertThat($foo, hasToString(equalTo("[Foo]Instance")));
```
* `equalTo` - compares two instances using comparison operator '=='
```php
$foo = new Foo;
$foo2 = new Foo;
assertThat($foo, equalTo($foo2));
```
* `identicalTo` - compares two instances using identity operator '==='
```php
assertThat($foo, is(not(identicalTo($foo2))));
```
* `anInstanceOf` - check instance is an instance|sub-class of given class
```php
assertThat($foo, anInstanceOf(Foo::class));
```
* `any` - alias of `anInstanceOf`
* `nullValue` check null
```php
assertThat(null, is(nullValue()));
```
* `notNullValue` check not null
```php
assertThat("", notNullValue());
```
* `sameInstance` - check for same instance
```php
assertThat($foo, is(not(sameInstance($foo2))));
assertThat($foo, is(sameInstance($foo)));
```
* `typeOf`- check type
```php
assertThat(1, typeOf("integer"));
```
* `notSet` - check if instance property is not set
```php
assertThat($foo, notSet("name"));
```
* `set` - check if instance property is set
```php
$foo->name = "bar";
assertThat($foo, set("name"));
```
### Numbers
* `closeTo` - check value close to a range
```php
assertThat(3, closeTo(3, 0.5));
```
* `comparesEqualTo` - check with '=='
```php
assertThat(2, comparesEqualTo(2));
```
* `greaterThan` - check '>'
```
assertThat(2, greaterThan(1));
```
* `greaterThanOrEqualTo`
```php
assertThat(2, greaterThanOrEqualTo(2));
```
* `atLeast` - The value is >= given value
```php
assertThat(3, atLeast(2));
```
* `lessThan`
```php
assertThat(2, lessThan(3));
```
* `lessThanOrEqualTo`
```php
assertThat(2, lessThanOrEqualTo(3));
```
* `atMost` - The value is <= given value
```php
assertThat(2, atMost(3));
```
### String
* `emptyString` - check for empty string
```php
assertThat("", emptyString());
```
* `isEmptyOrNullString`
```php
assertThat(null, isEmptyOrNullString());
```
* `nullOrEmptyString`
```php
assertThat("", nullOrEmptyString());
```
* `isNonEmptyString`
```php
assertThat("foo", isNonEmptyString());
```
* `nonEmptyString`
```php
assertThat("foo", nonEmptyString());
```
* `equalToIgnoringCase`
```php
assertThat("Foo", equalToIgnoringCase("foo"));
```
* `equalToIgnoringWhiteSpace`
```php
assertThat(" Foo ", equalToIgnoringWhiteSpace("Foo"));
```
* `matchesPattern` - matches with regex pattern
```php
assertThat("foobarbaz", matchesPattern('/(foo)(bar)(baz)/'));
```
* `containsString` - check for substring
```php
assertThat("foobar", containsString("foo"));
```
* `containsStringIgnoringCase`
```php
assertThat("fooBar", containsStringIgnoringCase("bar"));
```
* `stringContainsInOrder`
```php
assertThat("foo", stringContainsInOrder("foo"));
```
* `endsWith` - check string that ends with given value
```php
assertThat("foo", endsWith("oo"));
```
* `startsWith` - check string that starts with given value
```php
assertThat("bar", startsWith("ba"));
```
### Type-checking
* `arrayValue` - check array type
```php
assertThat([], arrayValue());
```
* `booleanValue`
```php
assertThat(true, booleanValue());
```
* `boolValue` - alias of booleanValue
* `callableValue` - check if value is callable
```php
$func = function () {};
assertThat($func, callableValue());
```
* `doubleValue`
```php
assertThat(3.14, doubleValue());
```
* `floatValue`
```php
assertThat(3.14, floatValue());
```
* `integerValue`
```php
assertThat(1, integerValue());
```
* `intValue` - alias of `integerValue`
* `numericValue` - check if value is numeric
```php
assertThat("123", numericValue());
```
* `objectValue` - check for object
```php
$obj = new stdClass;
assertThat($obj, objectValue());
```
* `anObject`
```php
assertThat($obj, anObject());
```
* `resourceValue` - check resource type
```php
$fp = fopen("/tmp/foo", "w+");
assertThat($fp, resourceValue());
```
* `scalarValue` - check for scaler value
```php
assertThat(1, scalarValue());
```
* `stringValue`
```php
assertThat("", stringValue());
```
### XML
* `hasXPath` - check xml with a xpath
```php
$xml = <<<XML
<books>
<book>
<isbn>1</isbn>
</book>
<book>
<isbn>2</isbn>
</book>
</books>
XML;
$doc = new DOMDocument;
$doc->loadXML($xml);
assertThat($doc, hasXPath("book", 2));
```

View File

@@ -1,22 +0,0 @@
Still TODO Before Complete for PHP
----------------------------------
Port:
- Hamcrest_Collection_*
- IsCollectionWithSize
- IsEmptyCollection
- IsIn
- IsTraversableContainingInAnyOrder
- IsTraversableContainingInOrder
- IsMapContaining (aliases)
Aliasing/Deprecation (questionable):
- Find and fix any factory methods that start with "is".
Namespaces:
- Investigate adding PHP 5.3+ namespace support in a way that still permits
use in PHP 5.2.
- Other than a parallel codebase, I don't see how this could be possible.

View File

@@ -3,30 +3,35 @@
"type": "library",
"description": "This is the PHP port of Hamcrest Matchers",
"keywords": ["test"],
"license": "BSD",
"license": "BSD-3-Clause",
"authors": [
],
"autoload": {
"classmap": ["hamcrest"],
"files": ["hamcrest/Hamcrest.php"]
"classmap": ["hamcrest"]
},
"autoload-dev": {
"classmap": ["tests", "generator"]
},
"require": {
"php": ">=5.3.2"
"php": "^5.3|^7.0|^8.0"
},
"require-dev": {
"satooshi/php-coveralls": "dev-master",
"phpunit/php-file-iterator": "1.3.3"
"phpunit/php-file-iterator": "^1.4 || ^2.0",
"phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0"
},
"replace": {
"kodova/hamcrest-php": "*",
"davedevelopment/hamcrest-php": "*",
"cordoval/hamcrest-php": "*"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
}
}

View File

@@ -33,7 +33,6 @@ class FactoryClass
$this->methods = array();
foreach ($this->getPublicStaticMethods() as $method) {
if ($method->isFactory()) {
// echo $this->getName() . '::' . $method->getName() . ' : ' . count($method->getCalls()) . PHP_EOL;
$this->methods[] = $method;
}
}

View File

@@ -53,9 +53,8 @@ abstract class FactoryFile
public function generateFactoryCall(FactoryCall $call)
{
$method = $call->getMethod();
$code = $method->getComment($this->indent) . PHP_EOL;
$code = $method->getComment($this->indent) . "\n";
$code .= $this->generateDeclaration($call->getName(), $method);
// $code .= $this->generateImport($method);
$code .= $this->generateCall($method);
$code .= $this->generateClosing();
return $code;
@@ -66,7 +65,7 @@ abstract class FactoryFile
$code = $this->indent . $this->getDeclarationModifiers()
. 'function ' . $name . '('
. $this->generateDeclarationArguments($method)
. ')' . PHP_EOL . $this->indent . '{' . PHP_EOL;
. ')' . "\n" . $this->indent . '{' . "\n";
return $code;
}
@@ -86,25 +85,25 @@ abstract class FactoryFile
public function generateImport(FactoryMethod $method)
{
return $this->indent . self::INDENT . "require_once '" . $method->getClass()->getFile() . "';" . PHP_EOL;
return $this->indent . self::INDENT . "require_once '" . $method->getClass()->getFile() . "';" . "\n";
}
public function generateCall(FactoryMethod $method)
{
$code = '';
if ($method->acceptsVariableArguments()) {
$code .= $this->indent . self::INDENT . '$args = func_get_args();' . PHP_EOL;
$code .= $this->indent . self::INDENT . '$args = func_get_args();' . "\n";
}
$code .= $this->indent . self::INDENT . 'return ';
if ($method->acceptsVariableArguments()) {
$code .= 'call_user_func_array(array(\''
. '\\' . $method->getClassName() . '\', \''
. $method->getName() . '\'), $args);' . PHP_EOL;
. $method->getName() . '\'), $args);' . "\n";
} else {
$code .= '\\' . $method->getClassName() . '::'
. $method->getName() . '('
. $method->getParameterInvocations() . ');' . PHP_EOL;
. $method->getParameterInvocations() . ');' . "\n";
}
return $code;
@@ -112,7 +111,7 @@ abstract class FactoryFile
public function generateClosing()
{
return $this->indent . '}' . PHP_EOL;
return $this->indent . '}' . "\n";
}
public function write()

View File

@@ -73,7 +73,7 @@ class FactoryGenerator
public function getSortedFiles()
{
$iter = \File_Iterator_Factory::getFileIterator($this->path, '.php');
$iter = $this->getFileIterator();
$files = array();
foreach ($iter as $file) {
$files[] = $file;
@@ -83,6 +83,15 @@ class FactoryGenerator
return $files;
}
private function getFileIterator()
{
$factoryClass = class_exists('File_Iterator_Factory') ? 'File_Iterator_Factory' : 'SebastianBergmann\FileIterator\Factory';
$factory = new $factoryClass();
return $factory->getFileIterator($this->path, '.php');
}
public function getFactoryClass($file)
{
$name = $this->getFactoryClassName($file);

View File

@@ -216,16 +216,16 @@ class FactoryMethod
public function getCommentText()
{
return implode(PHP_EOL, $this->comment);
return implode("\n", $this->comment);
}
public function getComment($indent = '')
{
$comment = $indent . '/**';
foreach ($this->comment as $line) {
$comment .= PHP_EOL . rtrim($indent . ' * ' . $line);
$comment .= "\n" . rtrim($indent . ' * ' . $line);
}
$comment .= PHP_EOL . $indent . ' */';
$comment .= "\n" . $indent . ' */';
return $comment;
}
}

View File

@@ -22,19 +22,15 @@ class FactoryParameter
$this->reflector = $reflector;
}
/**
* Compute the declaration code.
*
* @return string
*/
public function getDeclaration()
{
if ($this->reflector->isArray()) {
$code = 'array ';
} else {
$class = $this->reflector->getClass();
if ($class !== null) {
$code = '\\' . $class->name . ' ';
} else {
$code = '';
}
}
$code .= '$' . $this->reflector->name;
$code = $this->getTypeCode() . $this->getInvocation();
if ($this->reflector->isOptional()) {
$default = $this->reflector->getDefaultValue();
if (is_null($default)) {
@@ -48,7 +44,7 @@ class FactoryParameter
} elseif (is_array($default)) {
$default = 'array()';
} else {
echo 'Warning: unknown default type for ' . $this->getMethod()->getFullName() . PHP_EOL;
echo 'Warning: unknown default type for ' . $this->getMethod()->getFullName() . "\n";
var_dump($default);
$default = 'null';
}
@@ -57,11 +53,77 @@ class FactoryParameter
return $code;
}
public function getInvocation()
/**
* Compute the type code for the paramater.
*
* @return string
*/
private function getTypeCode()
{
return '$' . $this->reflector->name;
// Handle PHP 5 separately
if (PHP_VERSION_ID < 70000) {
if ($this->reflector->isArray()) {
return 'array';
}
$class = $this->reflector->getClass();
return $class ? sprintf('\\%s ', $class->getName()) : '';
}
if (!$this->reflector->hasType()) {
return '';
}
$type = $this->reflector->getType();
$name = self::getQualifiedName($type);
// PHP 7.1+ supports nullable types via a leading question mark
return (PHP_VERSION_ID >= 70100 && $type->allowsNull()) ? sprintf('?%s ', $name) : sprintf('%s ', $name);
}
/**
* Compute qualified name for the given type.
*
* This function knows how to prefix class names with a leading slash and
* also how to handle PHP 8's union types.
*
* @param ReflectionType $type
*
* @return string
*/
private static function getQualifiedName(ReflectionType $type)
{
// PHP 8 union types can be recursively processed
if ($type instanceof ReflectionUnionType) {
return implode('|', array_map(function (ReflectionType $type) {
// The "self::" call within a Closure is fine here because this
// code will only ever be executed on PHP 7.0+
return self::getQualifiedName($type);
}, $type->getTypes()));
}
// PHP 7.0 doesn't have named types, but 7.1+ does
$name = $type instanceof ReflectionNamedType ? $type->getName() : (string) $type;
return $type->isBuiltin() ? $name : sprintf('\\%s', $name);
}
/**
* Compute the invocation code.
*
* @return string
*/
public function getInvocation()
{
return sprintf('$%s', $this->reflector->getName());
}
/**
* Compute the method name.
*
* @return string
*/
public function getMethod()
{
return $this->method;

View File

@@ -19,7 +19,7 @@ class GlobalFunctionFile extends FactoryFile
public function addCall(FactoryCall $call)
{
$this->functions .= PHP_EOL . $this->generateFactoryCall($call);
$this->functions .= "\n" . $this->generateFactoryCall($call);
}
public function build()
@@ -33,7 +33,7 @@ class GlobalFunctionFile extends FactoryFile
public function generateFactoryCall(FactoryCall $call)
{
$code = "if (!function_exists('{$call->getName()}')) {";
$code = "if (!function_exists('{$call->getName()}')) {\n";
$code.= parent::generateFactoryCall($call);
$code.= "}\n";

View File

@@ -30,7 +30,8 @@ if (!function_exists('assertThat')) {
}
}
if (!function_exists('anArray')) { /**
if (!function_exists('anArray')) {
/**
* Evaluates to true only if each $matcher[$i] is satisfied by $array[$i].
*/
function anArray(/* args... */)
@@ -40,7 +41,8 @@ if (!function_exists('anArray')) { /**
}
}
if (!function_exists('hasItemInArray')) { /**
if (!function_exists('hasItemInArray')) {
/**
* Evaluates to true if any item in an array satisfies the given matcher.
*
* @param mixed $item as a {@link Hamcrest\Matcher} or a value.
@@ -53,7 +55,8 @@ if (!function_exists('hasItemInArray')) { /**
}
}
if (!function_exists('hasValue')) { /**
if (!function_exists('hasValue')) {
/**
* Evaluates to true if any item in an array satisfies the given matcher.
*
* @param mixed $item as a {@link Hamcrest\Matcher} or a value.
@@ -66,7 +69,8 @@ if (!function_exists('hasValue')) { /**
}
}
if (!function_exists('arrayContainingInAnyOrder')) { /**
if (!function_exists('arrayContainingInAnyOrder')) {
/**
* An array with elements that match the given matchers.
*/
function arrayContainingInAnyOrder(/* args... */)
@@ -76,7 +80,8 @@ if (!function_exists('arrayContainingInAnyOrder')) { /**
}
}
if (!function_exists('containsInAnyOrder')) { /**
if (!function_exists('containsInAnyOrder')) {
/**
* An array with elements that match the given matchers.
*/
function containsInAnyOrder(/* args... */)
@@ -86,7 +91,8 @@ if (!function_exists('containsInAnyOrder')) { /**
}
}
if (!function_exists('arrayContaining')) { /**
if (!function_exists('arrayContaining')) {
/**
* An array with elements that match the given matchers in the same order.
*/
function arrayContaining(/* args... */)
@@ -96,7 +102,8 @@ if (!function_exists('arrayContaining')) { /**
}
}
if (!function_exists('contains')) { /**
if (!function_exists('contains')) {
/**
* An array with elements that match the given matchers in the same order.
*/
function contains(/* args... */)
@@ -106,7 +113,8 @@ if (!function_exists('contains')) { /**
}
}
if (!function_exists('hasKeyInArray')) { /**
if (!function_exists('hasKeyInArray')) {
/**
* Evaluates to true if any key in an array matches the given matcher.
*
* @param mixed $key as a {@link Hamcrest\Matcher} or a value.
@@ -119,7 +127,8 @@ if (!function_exists('hasKeyInArray')) { /**
}
}
if (!function_exists('hasKey')) { /**
if (!function_exists('hasKey')) {
/**
* Evaluates to true if any key in an array matches the given matcher.
*
* @param mixed $key as a {@link Hamcrest\Matcher} or a value.
@@ -132,7 +141,8 @@ if (!function_exists('hasKey')) { /**
}
}
if (!function_exists('hasKeyValuePair')) { /**
if (!function_exists('hasKeyValuePair')) {
/**
* Test if an array has both an key and value in parity with each other.
*/
function hasKeyValuePair($key, $value)
@@ -141,7 +151,8 @@ if (!function_exists('hasKeyValuePair')) { /**
}
}
if (!function_exists('hasEntry')) { /**
if (!function_exists('hasEntry')) {
/**
* Test if an array has both an key and value in parity with each other.
*/
function hasEntry($key, $value)
@@ -150,7 +161,8 @@ if (!function_exists('hasEntry')) { /**
}
}
if (!function_exists('arrayWithSize')) { /**
if (!function_exists('arrayWithSize')) {
/**
* Does array size satisfy a given matcher?
*
* @param \Hamcrest\Matcher|int $size as a {@link Hamcrest\Matcher} or a value.
@@ -163,7 +175,8 @@ if (!function_exists('arrayWithSize')) { /**
}
}
if (!function_exists('emptyArray')) { /**
if (!function_exists('emptyArray')) {
/**
* Matches an empty array.
*/
function emptyArray()
@@ -172,7 +185,8 @@ if (!function_exists('emptyArray')) { /**
}
}
if (!function_exists('nonEmptyArray')) { /**
if (!function_exists('nonEmptyArray')) {
/**
* Matches an empty array.
*/
function nonEmptyArray()
@@ -181,7 +195,8 @@ if (!function_exists('nonEmptyArray')) { /**
}
}
if (!function_exists('emptyTraversable')) { /**
if (!function_exists('emptyTraversable')) {
/**
* Returns true if traversable is empty.
*/
function emptyTraversable()
@@ -190,7 +205,8 @@ if (!function_exists('emptyTraversable')) { /**
}
}
if (!function_exists('nonEmptyTraversable')) { /**
if (!function_exists('nonEmptyTraversable')) {
/**
* Returns true if traversable is not empty.
*/
function nonEmptyTraversable()
@@ -199,7 +215,8 @@ if (!function_exists('nonEmptyTraversable')) { /**
}
}
if (!function_exists('traversableWithSize')) { /**
if (!function_exists('traversableWithSize')) {
/**
* Does traversable size satisfy a given matcher?
*/
function traversableWithSize($size)
@@ -208,7 +225,8 @@ if (!function_exists('traversableWithSize')) { /**
}
}
if (!function_exists('allOf')) { /**
if (!function_exists('allOf')) {
/**
* Evaluates to true only if ALL of the passed in matchers evaluate to true.
*/
function allOf(/* args... */)
@@ -218,7 +236,8 @@ if (!function_exists('allOf')) { /**
}
}
if (!function_exists('anyOf')) { /**
if (!function_exists('anyOf')) {
/**
* Evaluates to true if ANY of the passed in matchers evaluate to true.
*/
function anyOf(/* args... */)
@@ -228,7 +247,8 @@ if (!function_exists('anyOf')) { /**
}
}
if (!function_exists('noneOf')) { /**
if (!function_exists('noneOf')) {
/**
* Evaluates to false if ANY of the passed in matchers evaluate to true.
*/
function noneOf(/* args... */)
@@ -238,7 +258,8 @@ if (!function_exists('noneOf')) { /**
}
}
if (!function_exists('both')) { /**
if (!function_exists('both')) {
/**
* This is useful for fluently combining matchers that must both pass.
* For example:
* <pre>
@@ -251,7 +272,8 @@ if (!function_exists('both')) { /**
}
}
if (!function_exists('either')) { /**
if (!function_exists('either')) {
/**
* This is useful for fluently combining matchers where either may pass,
* for example:
* <pre>
@@ -264,7 +286,8 @@ if (!function_exists('either')) { /**
}
}
if (!function_exists('describedAs')) { /**
if (!function_exists('describedAs')) {
/**
* Wraps an existing matcher and overrides the description when it fails.
*/
function describedAs(/* args... */)
@@ -274,7 +297,8 @@ if (!function_exists('describedAs')) { /**
}
}
if (!function_exists('everyItem')) { /**
if (!function_exists('everyItem')) {
/**
* @param Matcher $itemMatcher
* A matcher to apply to every element in an array.
*
@@ -287,7 +311,8 @@ if (!function_exists('everyItem')) { /**
}
}
if (!function_exists('hasToString')) { /**
if (!function_exists('hasToString')) {
/**
* Does array size satisfy a given matcher?
*/
function hasToString($matcher)
@@ -296,7 +321,8 @@ if (!function_exists('hasToString')) { /**
}
}
if (!function_exists('is')) { /**
if (!function_exists('is')) {
/**
* Decorates another Matcher, retaining the behavior but allowing tests
* to be slightly more expressive.
*
@@ -309,7 +335,8 @@ if (!function_exists('is')) { /**
}
}
if (!function_exists('anything')) { /**
if (!function_exists('anything')) {
/**
* This matcher always evaluates to true.
*
* @param string $description A meaningful string used when describing itself.
@@ -322,7 +349,8 @@ if (!function_exists('anything')) { /**
}
}
if (!function_exists('hasItem')) { /**
if (!function_exists('hasItem')) {
/**
* Test if the value is an array containing this matcher.
*
* Example:
@@ -339,7 +367,8 @@ if (!function_exists('hasItem')) { /**
}
}
if (!function_exists('hasItems')) { /**
if (!function_exists('hasItems')) {
/**
* Test if the value is an array containing elements that match all of these
* matchers.
*
@@ -355,7 +384,8 @@ if (!function_exists('hasItems')) { /**
}
}
if (!function_exists('equalTo')) { /**
if (!function_exists('equalTo')) {
/**
* Is the value equal to another value, as tested by the use of the "=="
* comparison operator?
*/
@@ -365,7 +395,8 @@ if (!function_exists('equalTo')) { /**
}
}
if (!function_exists('identicalTo')) { /**
if (!function_exists('identicalTo')) {
/**
* Tests of the value is identical to $value as tested by the "===" operator.
*/
function identicalTo($value)
@@ -374,7 +405,8 @@ if (!function_exists('identicalTo')) { /**
}
}
if (!function_exists('anInstanceOf')) { /**
if (!function_exists('anInstanceOf')) {
/**
* Is the value an instance of a particular type?
* This version assumes no relationship between the required type and
* the signature of the method that sets it up, for example in
@@ -386,7 +418,8 @@ if (!function_exists('anInstanceOf')) { /**
}
}
if (!function_exists('any')) { /**
if (!function_exists('any')) {
/**
* Is the value an instance of a particular type?
* This version assumes no relationship between the required type and
* the signature of the method that sets it up, for example in
@@ -398,7 +431,8 @@ if (!function_exists('any')) { /**
}
}
if (!function_exists('not')) { /**
if (!function_exists('not')) {
/**
* Matches if value does not match $value.
*/
function not($value)
@@ -407,7 +441,8 @@ if (!function_exists('not')) { /**
}
}
if (!function_exists('nullValue')) { /**
if (!function_exists('nullValue')) {
/**
* Matches if value is null.
*/
function nullValue()
@@ -416,7 +451,8 @@ if (!function_exists('nullValue')) { /**
}
}
if (!function_exists('notNullValue')) { /**
if (!function_exists('notNullValue')) {
/**
* Matches if value is not null.
*/
function notNullValue()
@@ -425,7 +461,8 @@ if (!function_exists('notNullValue')) { /**
}
}
if (!function_exists('sameInstance')) { /**
if (!function_exists('sameInstance')) {
/**
* Creates a new instance of IsSame.
*
* @param mixed $object
@@ -440,7 +477,8 @@ if (!function_exists('sameInstance')) { /**
}
}
if (!function_exists('typeOf')) { /**
if (!function_exists('typeOf')) {
/**
* Is the value a particular built-in type?
*/
function typeOf($theType)
@@ -449,7 +487,8 @@ if (!function_exists('typeOf')) { /**
}
}
if (!function_exists('set')) { /**
if (!function_exists('set')) {
/**
* Matches if value (class, object, or array) has named $property.
*/
function set($property)
@@ -458,7 +497,8 @@ if (!function_exists('set')) { /**
}
}
if (!function_exists('notSet')) { /**
if (!function_exists('notSet')) {
/**
* Matches if value (class, object, or array) does not have named $property.
*/
function notSet($property)
@@ -467,7 +507,8 @@ if (!function_exists('notSet')) { /**
}
}
if (!function_exists('closeTo')) { /**
if (!function_exists('closeTo')) {
/**
* Matches if value is a number equal to $value within some range of
* acceptable error $delta.
*/
@@ -477,7 +518,8 @@ if (!function_exists('closeTo')) { /**
}
}
if (!function_exists('comparesEqualTo')) { /**
if (!function_exists('comparesEqualTo')) {
/**
* The value is not > $value, nor < $value.
*/
function comparesEqualTo($value)
@@ -486,7 +528,8 @@ if (!function_exists('comparesEqualTo')) { /**
}
}
if (!function_exists('greaterThan')) { /**
if (!function_exists('greaterThan')) {
/**
* The value is > $value.
*/
function greaterThan($value)
@@ -495,7 +538,8 @@ if (!function_exists('greaterThan')) { /**
}
}
if (!function_exists('greaterThanOrEqualTo')) { /**
if (!function_exists('greaterThanOrEqualTo')) {
/**
* The value is >= $value.
*/
function greaterThanOrEqualTo($value)
@@ -504,7 +548,8 @@ if (!function_exists('greaterThanOrEqualTo')) { /**
}
}
if (!function_exists('atLeast')) { /**
if (!function_exists('atLeast')) {
/**
* The value is >= $value.
*/
function atLeast($value)
@@ -513,7 +558,8 @@ if (!function_exists('atLeast')) { /**
}
}
if (!function_exists('lessThan')) { /**
if (!function_exists('lessThan')) {
/**
* The value is < $value.
*/
function lessThan($value)
@@ -522,7 +568,8 @@ if (!function_exists('lessThan')) { /**
}
}
if (!function_exists('lessThanOrEqualTo')) { /**
if (!function_exists('lessThanOrEqualTo')) {
/**
* The value is <= $value.
*/
function lessThanOrEqualTo($value)
@@ -531,7 +578,8 @@ if (!function_exists('lessThanOrEqualTo')) { /**
}
}
if (!function_exists('atMost')) { /**
if (!function_exists('atMost')) {
/**
* The value is <= $value.
*/
function atMost($value)
@@ -540,7 +588,8 @@ if (!function_exists('atMost')) { /**
}
}
if (!function_exists('isEmptyString')) { /**
if (!function_exists('isEmptyString')) {
/**
* Matches if value is a zero-length string.
*/
function isEmptyString()
@@ -549,7 +598,8 @@ if (!function_exists('isEmptyString')) { /**
}
}
if (!function_exists('emptyString')) { /**
if (!function_exists('emptyString')) {
/**
* Matches if value is a zero-length string.
*/
function emptyString()
@@ -558,7 +608,8 @@ if (!function_exists('emptyString')) { /**
}
}
if (!function_exists('isEmptyOrNullString')) { /**
if (!function_exists('isEmptyOrNullString')) {
/**
* Matches if value is null or a zero-length string.
*/
function isEmptyOrNullString()
@@ -567,7 +618,8 @@ if (!function_exists('isEmptyOrNullString')) { /**
}
}
if (!function_exists('nullOrEmptyString')) { /**
if (!function_exists('nullOrEmptyString')) {
/**
* Matches if value is null or a zero-length string.
*/
function nullOrEmptyString()
@@ -576,7 +628,8 @@ if (!function_exists('nullOrEmptyString')) { /**
}
}
if (!function_exists('isNonEmptyString')) { /**
if (!function_exists('isNonEmptyString')) {
/**
* Matches if value is a non-zero-length string.
*/
function isNonEmptyString()
@@ -585,7 +638,8 @@ if (!function_exists('isNonEmptyString')) { /**
}
}
if (!function_exists('nonEmptyString')) { /**
if (!function_exists('nonEmptyString')) {
/**
* Matches if value is a non-zero-length string.
*/
function nonEmptyString()
@@ -594,7 +648,8 @@ if (!function_exists('nonEmptyString')) { /**
}
}
if (!function_exists('equalToIgnoringCase')) { /**
if (!function_exists('equalToIgnoringCase')) {
/**
* Matches if value is a string equal to $string, regardless of the case.
*/
function equalToIgnoringCase($string)
@@ -603,7 +658,8 @@ if (!function_exists('equalToIgnoringCase')) { /**
}
}
if (!function_exists('equalToIgnoringWhiteSpace')) { /**
if (!function_exists('equalToIgnoringWhiteSpace')) {
/**
* Matches if value is a string equal to $string, regardless of whitespace.
*/
function equalToIgnoringWhiteSpace($string)
@@ -612,7 +668,8 @@ if (!function_exists('equalToIgnoringWhiteSpace')) { /**
}
}
if (!function_exists('matchesPattern')) { /**
if (!function_exists('matchesPattern')) {
/**
* Matches if value is a string that matches regular expression $pattern.
*/
function matchesPattern($pattern)
@@ -621,7 +678,8 @@ if (!function_exists('matchesPattern')) { /**
}
}
if (!function_exists('containsString')) { /**
if (!function_exists('containsString')) {
/**
* Matches if value is a string that contains $substring.
*/
function containsString($substring)
@@ -630,7 +688,8 @@ if (!function_exists('containsString')) { /**
}
}
if (!function_exists('containsStringIgnoringCase')) { /**
if (!function_exists('containsStringIgnoringCase')) {
/**
* Matches if value is a string that contains $substring regardless of the case.
*/
function containsStringIgnoringCase($substring)
@@ -639,7 +698,8 @@ if (!function_exists('containsStringIgnoringCase')) { /**
}
}
if (!function_exists('stringContainsInOrder')) { /**
if (!function_exists('stringContainsInOrder')) {
/**
* Matches if value contains $substrings in a constrained order.
*/
function stringContainsInOrder(/* args... */)
@@ -649,7 +709,8 @@ if (!function_exists('stringContainsInOrder')) { /**
}
}
if (!function_exists('endsWith')) { /**
if (!function_exists('endsWith')) {
/**
* Matches if value is a string that ends with $substring.
*/
function endsWith($substring)
@@ -658,7 +719,8 @@ if (!function_exists('endsWith')) { /**
}
}
if (!function_exists('startsWith')) { /**
if (!function_exists('startsWith')) {
/**
* Matches if value is a string that starts with $substring.
*/
function startsWith($substring)
@@ -667,7 +729,8 @@ if (!function_exists('startsWith')) { /**
}
}
if (!function_exists('arrayValue')) { /**
if (!function_exists('arrayValue')) {
/**
* Is the value an array?
*/
function arrayValue()
@@ -676,7 +739,8 @@ if (!function_exists('arrayValue')) { /**
}
}
if (!function_exists('booleanValue')) { /**
if (!function_exists('booleanValue')) {
/**
* Is the value a boolean?
*/
function booleanValue()
@@ -685,7 +749,8 @@ if (!function_exists('booleanValue')) { /**
}
}
if (!function_exists('boolValue')) { /**
if (!function_exists('boolValue')) {
/**
* Is the value a boolean?
*/
function boolValue()
@@ -694,7 +759,8 @@ if (!function_exists('boolValue')) { /**
}
}
if (!function_exists('callableValue')) { /**
if (!function_exists('callableValue')) {
/**
* Is the value callable?
*/
function callableValue()
@@ -703,7 +769,8 @@ if (!function_exists('callableValue')) { /**
}
}
if (!function_exists('doubleValue')) { /**
if (!function_exists('doubleValue')) {
/**
* Is the value a float/double?
*/
function doubleValue()
@@ -712,7 +779,8 @@ if (!function_exists('doubleValue')) { /**
}
}
if (!function_exists('floatValue')) { /**
if (!function_exists('floatValue')) {
/**
* Is the value a float/double?
*/
function floatValue()
@@ -721,7 +789,8 @@ if (!function_exists('floatValue')) { /**
}
}
if (!function_exists('integerValue')) { /**
if (!function_exists('integerValue')) {
/**
* Is the value an integer?
*/
function integerValue()
@@ -730,7 +799,8 @@ if (!function_exists('integerValue')) { /**
}
}
if (!function_exists('intValue')) { /**
if (!function_exists('intValue')) {
/**
* Is the value an integer?
*/
function intValue()
@@ -739,7 +809,8 @@ if (!function_exists('intValue')) { /**
}
}
if (!function_exists('numericValue')) { /**
if (!function_exists('numericValue')) {
/**
* Is the value a numeric?
*/
function numericValue()
@@ -748,7 +819,8 @@ if (!function_exists('numericValue')) { /**
}
}
if (!function_exists('objectValue')) { /**
if (!function_exists('objectValue')) {
/**
* Is the value an object?
*/
function objectValue()
@@ -757,7 +829,8 @@ if (!function_exists('objectValue')) { /**
}
}
if (!function_exists('anObject')) { /**
if (!function_exists('anObject')) {
/**
* Is the value an object?
*/
function anObject()
@@ -766,7 +839,8 @@ if (!function_exists('anObject')) { /**
}
}
if (!function_exists('resourceValue')) { /**
if (!function_exists('resourceValue')) {
/**
* Is the value a resource?
*/
function resourceValue()
@@ -775,7 +849,8 @@ if (!function_exists('resourceValue')) { /**
}
}
if (!function_exists('scalarValue')) { /**
if (!function_exists('scalarValue')) {
/**
* Is the value a scalar (boolean, integer, double, or string)?
*/
function scalarValue()
@@ -784,7 +859,8 @@ if (!function_exists('scalarValue')) { /**
}
}
if (!function_exists('stringValue')) { /**
if (!function_exists('stringValue')) {
/**
* Is the value a string?
*/
function stringValue()
@@ -793,7 +869,8 @@ if (!function_exists('stringValue')) { /**
}
}
if (!function_exists('hasXPath')) { /**
if (!function_exists('hasXPath')) {
/**
* Wraps <code>$matcher</code> with {@link Hamcrest\Core\IsEqual)
* if it's not a matcher and the XPath in <code>count()</code>
* if it's an integer.

View File

@@ -22,4 +22,9 @@ abstract class BaseMatcher implements Matcher
{
return StringDescription::toString($this);
}
public function __invoke()
{
return call_user_func_array(array($this, 'matches'), func_get_args());
}
}

View File

@@ -19,9 +19,29 @@ class IsNumeric extends IsTypeOf
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?
*

View File

@@ -12,6 +12,10 @@ namespace Hamcrest;
*/
class Util
{
public static function registerGlobalFunctions()
{
require_once __DIR__.'/../Hamcrest.php';
}
/**
* Wraps the item with an IsEqual matcher if it isn't a matcher already.

View File

@@ -1,10 +1,12 @@
<?php
namespace Hamcrest;
use PHPUnit\Framework\TestCase;
class UnknownType {
}
abstract class AbstractMatcherTest extends \PHPUnit_Framework_TestCase
abstract class AbstractMatcherTest extends TestCase
{
const ARGUMENT_IGNORED = "ignored";

View File

@@ -34,6 +34,10 @@ class IsArrayContainingInOrderTest extends AbstractMatcherTest
public function testMismatchesItemsInAnyOrder()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Broken on HHVM.');
}
$matcher = arrayContaining(array(1, 2, 3));
$this->assertMismatchDescription('was null', $matcher, null);
$this->assertMismatchDescription('No item matched: <1>', $matcher, array());

View File

@@ -7,7 +7,7 @@ class CombinableMatcherTest extends \Hamcrest\AbstractMatcherTest
private $_either_3_or_4;
private $_not_3_and_not_4;
public function setUp()
protected function setUp()
{
$this->_either_3_or_4 = \Hamcrest\Core\CombinableMatcher::either(equalTo(3))->orElse(equalTo(4));
$this->_not_3_and_not_4 = \Hamcrest\Core\CombinableMatcher::both(not(equalTo(3)))->andAlso(not(equalTo(4)));

View File

@@ -7,7 +7,7 @@ class IsInstanceOfTest extends \Hamcrest\AbstractMatcherTest
private $_baseClassInstance;
private $_subClassInstance;
public function setUp()
protected function setUp()
{
$this->_baseClassInstance = new \Hamcrest\Core\SampleBaseClass('good');
$this->_subClassInstance = new \Hamcrest\Core\SampleSubClass('good');

View File

@@ -34,7 +34,7 @@ class FeatureMatcherTest extends \Hamcrest\AbstractMatcherTest
private $_resultMatcher;
public function setUp()
protected function setUp()
{
$this->_resultMatcher = $this->_resultMatcher();
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Hamcrest;
use PHPUnit\Framework\TestCase;
class SampleInvokeMatcher extends BaseMatcherTest
{
private $matchAgainst;
public function __construct($matchAgainst)
{
$this->matchAgainst = $matchAgainst;
}
public function matches($item)
{
return $item == $this->matchAgainst;
}
}
class InvokedMatcherTest extends TestCase
{
public function testInvokedMatchersCallMatches()
{
$sampleMatcher = new SampleInvokeMatcher('foo');
$this->assertTrue($sampleMatcher('foo'));
$this->assertFalse($sampleMatcher('bar'));
}
}

View File

@@ -1,7 +1,9 @@
<?php
namespace Hamcrest;
class MatcherAssertTest extends \PhpUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;
class MatcherAssertTest extends TestCase
{
protected function setUp()

View File

@@ -1,6 +1,8 @@
<?php
namespace Hamcrest;
use PHPUnit\Framework\TestCase;
class SampleSelfDescriber implements \Hamcrest\SelfDescribing
{
private $_text;
@@ -16,12 +18,12 @@ class SampleSelfDescriber implements \Hamcrest\SelfDescribing
}
}
class StringDescriptionTest extends \PhpUnit_Framework_TestCase
class StringDescriptionTest extends TestCase
{
private $_description;
public function setUp()
protected function setUp()
{
$this->_description = new \Hamcrest\StringDescription();
}

View File

@@ -6,7 +6,7 @@ class IsEqualIgnoringWhiteSpaceTest extends \Hamcrest\AbstractMatcherTest
private $_matcher;
public function setUp()
protected function setUp()
{
$this->_matcher = \Hamcrest\Text\IsEqualIgnoringWhiteSpace::equalToIgnoringWhiteSpace(
"Hello World how\n are we? "

View File

@@ -8,7 +8,7 @@ class StringContainsIgnoringCaseTest extends \Hamcrest\AbstractMatcherTest
private $_stringContains;
public function setUp()
protected function setUp()
{
$this->_stringContains = \Hamcrest\Text\StringContainsIgnoringCase::containsStringIgnoringCase(
strtolower(self::EXCERPT)

View File

@@ -6,7 +6,7 @@ class StringContainsInOrderTest extends \Hamcrest\AbstractMatcherTest
private $_m;
public function setUp()
protected function setUp()
{
$this->_m = \Hamcrest\Text\StringContainsInOrder::stringContainsInOrder(array('a', 'b', 'c'));
}

View File

@@ -8,7 +8,7 @@ class StringContainsTest extends \Hamcrest\AbstractMatcherTest
private $_stringContains;
public function setUp()
protected function setUp()
{
$this->_stringContains = \Hamcrest\Text\StringContains::containsString(self::EXCERPT);
}

View File

@@ -8,7 +8,7 @@ class StringEndsWithTest extends \Hamcrest\AbstractMatcherTest
private $_stringEndsWith;
public function setUp()
protected function setUp()
{
$this->_stringEndsWith = \Hamcrest\Text\StringEndsWith::endsWith(self::EXCERPT);
}

View File

@@ -8,7 +8,7 @@ class StringStartsWithTest extends \Hamcrest\AbstractMatcherTest
private $_stringStartsWith;
public function setUp()
protected function setUp()
{
$this->_stringStartsWith = \Hamcrest\Text\StringStartsWith::startsWith(self::EXCERPT);
}

View File

@@ -25,6 +25,7 @@ class IsNumericTest extends \Hamcrest\AbstractMatcherTest
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 @@ class IsNumericTest extends \Hamcrest\AbstractMatcherTest
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()

View File

@@ -1,7 +1,9 @@
<?php
namespace Hamcrest;
class UtilTest extends \PhpUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;
class UtilTest extends TestCase
{
public function testWrapValueWithIsEqualLeavesMatchersUntouched()

View File

@@ -1,18 +1,11 @@
<?php
error_reporting(E_ALL | E_STRICT);
require __DIR__ . '/../vendor/autoload.php';
if (defined('E_DEPRECATED')) {
error_reporting(error_reporting() | E_DEPRECATED);
}
define('HAMCREST_TEST_BASE', realpath(dirname(__FILE__)));
define('HAMCREST_BASE', realpath(dirname(dirname(__FILE__))));
set_include_path(implode(PATH_SEPARATOR, array(
HAMCREST_TEST_BASE,
HAMCREST_BASE . '/hamcrest',
get_include_path()
)));
require_once 'Hamcrest.php';
Hamcrest\Util::registerGlobalFunctions();

View File

@@ -6,8 +6,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
stopOnFailure="false">
<testsuites>
<testsuite name="hamcrest-php">
<directory suffix="Test.php">.</directory>