How can I Mock the UploadedFile class?

386 views
Skip to first unread message

Alejandro Hernández

unread,
Mar 18, 2014, 4:55:05 PM3/18/14
to phpsp...@googlegroups.com
Hello,

I started to use phpspec recently in every new development I'm doing an I got an error, I don't quite understand. I'm trying to mock the class UploadedFile from the Symfony HttpFoundation component.

This is the code I have in my specifications:

class FileManagerSpec extends ObjectBehavior
{
    function let(UploadedFile $file)
    {
        $file->willBeConstructedWith(array('path', 'originalName'));
    }

    function it_saves_an_uploaded_file(UploadedFile $file)
    {
        $this->saveFile($file);
    }
}

And this is the output of the phpspec run command

FileManager
  17  ! it saves an uploaded file
      warning: Missing argument 2 for Symfony\Component\HttpFoundation\File\UploadedFile::__construct(), called in
      /var/www/spec-uploadedfile/vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(48) : eval()'d code
      on line 6 and defined in
      /var/www/spec-uploadedfile/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/File/UploadedFile.php line 92

I have created a repository with this code at https://github.com/aleherse/spec-uploadedfile

Thank you in advance for your help!


Regards,
Alex.
Reply all
Reply to author
Forward
0 new messages