Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Jun 5, 2024 via composer

hamcrest/hamcrest-php v2.0.1

This is the PHP port of Hamcrest Matchers
Package summary
Share
0
issues
1
license
1
BSD-3-Clause
Package created
31 Dec 2013
Version published
9 Jul 2020
Maintainers
3
Total deps
1
Direct deps
0
License
BSD-3-Clause

Issues

0
This package has no issues

Licenses

BSD 3-Clause "New" or "Revised" License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
place-warranty
Cannot
use-trademark
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
hamcrest/hamcrest-php@v2.0.1
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of hamcrest/hamcrest-php 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does hamcrest/hamcrest-php do?

Hamcrest-PHP is a library that provides a matching mechanism for various use cases. Initially developed in Java, Hamcrest has been brought to the PHP world through this library as the PHP port of Hamcrest matchers. It is a powerful tool for carrying out assertions in testing scenarios or validations by defining expectations in a readable and reusable manner. While most of the Java features have been translated to PHP, there are some exceptions due to PHP language barriers. It allows dynamic typing for its inputs except for matchers that semantically require a specific type, such as 'stringContains()' and 'greaterThan()'.

How do you use hamcrest/hamcrest-php?

To utilize the hamcrest-php library, you have to include the Hamcrest namespace in your PHP file. A code example summarizing the usage can be found below:

require_once 'vendor/hamcrest/hamcrest-php/hamcrest/Hamcrest.php';

use Hamcrest\Matchers as Hamcrest;

//Assuming we have a variable '$value' to be tested
$value = 'A';

//Matching the $value to be equal to 'A' in a case-insensitive manner
Hamcrest_MatcherAssert::assertThat($value, Hamcrest_Matchers::equalToIgnoringCase('A'));

In another code example, you can also use the global proxy-functions. However, they are not autoloaded by default and you need to load them manually.

\Hamcrest\Util::registerGlobalFunctions();

$result = true;
//With an identifier
assertThat("Result should be true", $result, equalTo(true));
//Without an identifier
assertThat($result, equalTo(true));
//Evaluating a boolean expression
assertThat($result === true);
//With syntactic sugar is()
assertThat(true, is(true));

The Hamcrest-PHP library provides several matchers including but not limited to: Array, Collection, Object, Numbers, Type checking and XML.

Where are the hamcrest/hamcrest-php docs?

Detailed documentation of hamcrest-php, which includes details on Available Matchers and their usage, can be found at the Hamcrest site.