constructormockingphpunitmockery

PHPUnit - disable original constructor in Mockery


I want use Mockery and change this:

$mockFoo = $this->getMockBuilder('Foo')
        ->disableOriginalConstructor()
        ->getMock();

to this:

$mockFoo = m::mock('Foo');

But I don't know how disable original constructor in Mockery. Please help me if You can. :-)


Solution

  • Mockery does not call constructor if no parameters are specified:

    \Mockery::mock('MyClass');
    

    UPDATE: The answer above was relevant for earlier versions of Mockery. With the current version one must use partial test doubles:

    $mock = \Mockery::mock('MyClass')->makePartial();
    $mock->shouldReceive('foo');
    

    See official documentation for more info. Credits go to northerner