3

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?

Marinus
  • 521
  • 2
  • 15
  • 1
    I had the same problem and had to mock without prophecy: `$uploadedFile = $this->getMockBuilder(UploadedFile::class)->disableOriginalConstructor()->getMock();` – Renan Taranto Apr 04 '17 at 22:40
  • @RenanTaranto I'll try that out, thank you. I ended up having to wrap the class and call it from the wrapper. – Marinus May 30 '17 at 04:19
  • No problem. Creating a wrapper (adapter) may be a good idea too. Did it work for you? I will add as an answer since I believe it may help others. – Renan Taranto May 30 '17 at 12:52

1 Answers1

3

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

Renan Taranto
  • 562
  • 4
  • 8