Skip to content

Instantly share code, notes, and snippets.

@harshpatel991
Created March 17, 2018 03:42
Show Gist options
  • Save harshpatel991/2d773126a92cfdfb857ba3f52f506522 to your computer and use it in GitHub Desktop.
Save harshpatel991/2d773126a92cfdfb857ba3f52f506522 to your computer and use it in GitHub Desktop.
<?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