Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot instanciate dummies of SplFileInfo subclasses without arguments #414

Open
julienfalque opened this issue Aug 29, 2018 · 6 comments
Open

Comments

@julienfalque
Copy link

julienfalque commented Aug 29, 2018

When creating a dummy of Symfony\Component\HttpFoundation\File\UploadedFile (from package symfony/http-foundation), the created class for the dummy cannot be instanciated without arguments.

This is the constructor of Symfony\Component\HttpFoundation\File\UploadedFile:

public function __construct(string $path, string $originalName, string $mimeType = null, int $size = null, int $error = null, bool $test = false)
{
    // ...
}

This is the constructor of the created class:

public function __construct(string $path = NULL, string $originalName = NULL, string $mimeType = NULL, int $size = NULL, int $error = NULL, bool $test = NULL)
{
    return parent::__construct($path, $originalName, $mimeType, $size, $error, $test);
}

If I disable SplFileInfoPatch, the constructor is the following:

public function __construct(string $path = NULL, string $originalName = NULL, string $mimeType = NULL, int $size = NULL, int $error = NULL, bool $test = NULL)
{
    if (0 < func_num_args()) {
        call_user_func_array(array('parent', '__construct'), func_get_args());
    }
}

In such case, instanciating the stub without arguments works fine.

I'm not sure whether this is the expected behavior but if not, I'd be glad to work on a fix.

@ciaranmcnulty
Copy link
Member

What error do you get when trying to use the double?

@julienfalque
Copy link
Author

TypeError : Argument 1 passed to Symfony\Component\HttpFoundation\File\UploadedFile::__construct() must be of the type string, null given, called in vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(49) : eval()'d code on line 6
vendor/symfony/http-foundation/File/UploadedFile.php:58
tests/.../MyTest.php

@ciaranmcnulty
Copy link
Member

Looks like the SplFileInfo patch doesn't look at what the constructor actually is

@DonCallisto
Copy link
Contributor

We should check for SplFileInfo here https://github.com/phpspec/prophecy/blob/master/src/Prophecy/Doubler/ClassPatch/SplFileInfoPatch.php#L62 or am I mistaken?

Not only for SF related issue, but more in general.

@julienfalque
Copy link
Author

DisableConstructorPatch overrides the constructor to make all its arguments optional and default to null, and call parent constructor only if at least one argument is actually passed.

But then SplFileInfoPatch updates the constructor to always call the parent constructor:

I'm not sure why. Can this line be removed?

@esynaps
Copy link

esynaps commented Mar 31, 2020

If I remove the line, my test works

This line comes from this old pull request : cb7eec4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants