Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.idea
/composer.lock
/vendor
6 changes: 4 additions & 2 deletions HamcrestTypeBridge.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

use Hamcrest\Matcher;

class HamcrestTypeBridge {
/**
* Creates a special mock of $type which wraps the given $matcher.
*
* @param string $type Name of the class to subtype
* @param Hamcrest_Matcher $matcher The matcher to proxy
* @param Matcher $matcher The matcher to proxy
* @return Object A special mock of type $type that wraps $matcher, circumventing type issues.
*/
public static function argOfTypeThat($type, Hamcrest_Matcher $matcher) {
public static function argOfTypeThat($type, Matcher $matcher) {
$mockOfType = Phockito::mock($type);
$mockOfType->__phockito_matcher = $matcher;
return $mockOfType;
Expand Down
7 changes: 5 additions & 2 deletions HamcrestTypeBridge_Globals.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

use Hamcrest\Matcher;

require_once('HamcrestTypeBridge.php');

function argOfTypeThat($type, \Hamcrest_Matcher $matcher) {
HamcrestTypeBridge::argOfTypeThat($type, $matcher);
function argOfTypeThat($type, Matcher $matcher) {
return HamcrestTypeBridge::argOfTypeThat($type, $matcher);
}
16 changes: 8 additions & 8 deletions Phockito.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Hamcrest\Matcher;

/**
* Phockito - Mockito for PHP
*
Expand Down Expand Up @@ -111,10 +113,10 @@ public static function _arguments_match($mockclass, $method, $a, $b) {
$u = $a[$i]; $v = $b[$i];

// If the argument in $a is a hamcrest matcher, call match on it. WONTFIX: Can't check if function was passed a hamcrest matcher
if (interface_exists('Hamcrest_Matcher') && ($u instanceof Hamcrest_Matcher || isset($u->__phockito_matcher))) {
if (interface_exists(Matcher::class) && ($u instanceof Matcher || isset($u->__phockito_matcher))) {
// The matcher can either be passed directly, or wrapped in a mock (for type safety reasons)
$matcher = null;
if ($u instanceof Hamcrest_Matcher) {
if ($u instanceof Matcher) {
$matcher = $u;
} elseif (isset($u->__phockito_matcher)) {
$matcher = $u->__phockito_matcher;
Expand Down Expand Up @@ -506,16 +508,14 @@ static function reset($mock, $method = null) {
/**
* Includes the Hamcrest matchers. You don't have to, but if you don't you can't to nice generic stubbing and verification
* @static
* @param bool $as_globals - When true (the default) the hamcrest matchers are available as global functions. If false, they're only available as static methods on Hamcrest_Matchers
* @param bool $as_globals - When true (the default) the hamcrest matchers are available as global functions. If false, they're only available as static methods on the Hamcrest Matchers class
*/
static function include_hamcrest($include_globals = true) {
set_include_path(get_include_path().PATH_SEPARATOR.dirname(__FILE__).'/hamcrest-php/hamcrest');

if ($include_globals) {
require_once('Hamcrest.php');
if ($include_globals) {
require_once('vendor/hamcrest/hamcrest-php/hamcrest/Hamcrest.php');
require_once('HamcrestTypeBridge_Globals.php');
} else {
require_once('Hamcrest/Matchers.php');
require_once('vendor/hamcrest/hamcrest-php/hamcrest/Hamcrest/Matchers.php');
require_once('HamcrestTypeBridge.php');
}
}
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ $mock->Bar(1, 3); // Returns null, since no stubbed return value matches
Mockito returns a type-compatible false, based on the declared return type. We don't have defined type values in
PHP, so we always return null. TODO: Support using phpdoc @return when declared.

## Pronunciation

Mockito has [answered this here](https://github.com/mockito/mockito/issues/889). Based on that, Phockito would be similar to [/pˈɒkitoʊ/](http://ipa-reader.xyz/)

## TODO

- Mockito-specific hamcrest matchers (anyString, etc)
Expand Down
12 changes: 11 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@
{
"name": "Hamish Friedlander",
"email": "hamish@silverstripe.com"
},
{
"name": "madmatt",
"email": "signups+phockito@madman.dev"
}
],
"autoload": {
"classmap": ["."]
}
},
"require": {
"hamcrest/hamcrest-php": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^5"
}
}
8 changes: 0 additions & 8 deletions hamcrest-php/.piston.yml

This file was deleted.

163 changes: 0 additions & 163 deletions hamcrest-php/CHANGES.txt

This file was deleted.

27 changes: 0 additions & 27 deletions hamcrest-php/LICENSE.txt

This file was deleted.

Loading