You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class StaticClass
{
public static function foo()
{
return "foo";
}
public static function bar()
{
return "bar";
}
}
My Test
/**
* Test mocking static methods
*
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @return void
*/
public function testMockStaticMethods()
{
$staticClassMock = Mockery::mock('alias:' . StaticClass::class)->makePartial();
$staticClassMock->shouldReceive('foo')->andReturn("mockedFoo");
//passed
self::assertEquals("mockedFoo", StaticClass::foo());
//throws an error
self::assertEquals("bar", StaticClass::bar());
}
Currently this throws an error saying "Static method App\Models\StaticClass::bar() does not exist on this mock object"
I believe partial mocking on aliased classes is not currently supported. Is this due to a design limitation, or has there not been any resources to implement this feature? My main use case for this feature would be mocking Eloquent models. I'd like to mock MyModel::find() while keeping functions like MyModel::make.
The text was updated successfully, but these errors were encountered:
Unfortunately, there had not been enough resources to implement this and a few other features. Hoping to fix that. I was able to reproduce the test case you provided.
My static class
My Test
Currently this throws an error saying "Static method App\Models\StaticClass::bar() does not exist on this mock object"
I believe partial mocking on aliased classes is not currently supported. Is this due to a design limitation, or has there not been any resources to implement this feature? My main use case for this feature would be mocking Eloquent models. I'd like to mock MyModel::find() while keeping functions like MyModel::make.
The text was updated successfully, but these errors were encountered: