Last active
June 14, 2019 05:32
-
-
Save komron-m/1cd42f236bc326e592f37fb58780ce79 to your computer and use it in GitHub Desktop.
Laravel helper for mocking instances.
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 | |
namespace Tests\Unit\Core; | |
trait MockeryHelper { | |
/** | |
* @var array | |
* @key is Instance you want to mock ex: \App\Test\SomeDoer.php | |
* @value is mockery instance | |
*/ | |
public $mockedInstances = []; | |
/** | |
* @param $instance | |
* @return \Mockery\MockInterface | |
*/ | |
public function mockInstanceInContainer($instance) { | |
$mockedInstance = \Mockery::mock($instance); | |
$this->app->instance($instance, $mockedInstance); | |
$this->mockedInstances[$instance] = $mockedInstance; | |
return $mockedInstance; | |
} | |
/** | |
* @param $instance | |
* @return \Mockery\MockInterface | |
*/ | |
public function assertMockedInstance($instance) { | |
return $this->getMock($instance); | |
} | |
/** | |
* @param $instance | |
* @return \Mockery\MockInterface | |
*/ | |
public function getMock($instance) { | |
return $this->mockedInstances[$instance]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment