Created
March 17, 2018 03:42
-
-
Save harshpatel991/2d773126a92cfdfb857ba3f52f506522 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This class creates a custom Hamcrest matcher to match on the attributes of a laravel model | |
// Can be used with mockery in order to verify that the expected model is used with calling a function | |
// | |
// | |
// Usage: | |
// | |
// ClassYouWantToTest::shouldReceive('functionToTest') | |
// ->withArgs([laravelModelEquals($laravelModelToVerify)]) | |
// ->times(1); | |
namespace Tests; | |
use Hamcrest\BaseMatcher; | |
use Hamcrest\Description; | |
class LaravelModelMatcher extends BaseMatcher | |
{ | |
private $value; | |
public function __construct($value) { | |
$this->value = $value; | |
} | |
public function matches($actualModel) { | |
return $this->value->is($actualModel); | |
} | |
public function describeTo(Description $description) { | |
$description->appendText('same laravel model'); | |
} | |
} | |
function laravelModelEquals($expectedValue) { | |
return new LaravelModelMatcher($expectedValue); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment