phpsymfonyprophecy

Disabling constructor in Prophecy


I have a Symfony class I am trying to mock using Prophecy. However, when I reveal the class it executes the constructor. Below is example code:

$mock = $this->prophesize('Symfony\Component\HttpFoundation\File\UploadedFile');
$mock->reveal();

which returns the exception

Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException

which doesn't make sense to me as Prophecy is supposed to automatically disable the constructor?


Solution

  • I had the same problem and had to mock without prophecy:

    $uploadedFile = $this->getMockBuilder(UploadedFile::class)->disableOriginalC‌​onstructor()->getMoc‌​k();
    

    Probably related https://github.com/phpspec/prophecy/issues/58