PHPUnit - disable original constructor in Mockery
Asked Answered
N

1

6

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. :-)

Nipper answered 12/11, 2015 at 13:9 Comment(0)
E
8

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

Ehlke answered 12/11, 2015 at 19:12 Comment(1)
It worked in earlier versions of Mockery. In 2023 use partial doubles for that docs.mockery.io/en/latest/cookbook/…Periscope

© 2022 - 2024 — McMap. All rights reserved.