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

PHP Fatal error: Duplicate type null is redundant #1116

Closed
foremtehan opened this issue Feb 1, 2021 · 5 comments
Closed

PHP Fatal error: Duplicate type null is redundant #1116

foremtehan opened this issue Feb 1, 2021 · 5 comments

Comments

@foremtehan
Copy link

PHP 8.0
Mockery v1.4.2

I want to mock php built-in class ZipArchive :

$zip = Mockery::mock(ZipArchive::class);

$zip->shouldReceive('open')->andReturn(true);

But i get this error:

PHP Fatal error: Duplicate type null is redundant in \vendor\mockery\mockery\library\Mockery\Loader\EvalLoader.php(34) : eval()'d code on line 1176

In EvalLoader.php(34) : eval()'d code line 1176:

@lukasyelle
Copy link

I was experiencing the same error for a custom class I am working on. It seems that my issue was related to how I had set up the following constructor that was attempting to be mocked:

public function __construct(AlpacaTrading $tradingApi, Order|array $order = null)
{
    parent::__construct($tradingApi);

    return $order ? $this->from($order) : $this;
}

It didn't like having to mock the type-hinted nullable param $order. Changing the constructor to the following alleviated the issue for me.

public function __construct(AlpacaTrading $tradingApi, array $order = null)
{
    parent::__construct($tradingApi);

    return $order ? $this->from($order) : $this;
}

@downsider
Copy link
Contributor

downsider commented Feb 5, 2021

Reckon I'm hitting this one too, with PHP8.0 and Mockery 1.4.2

Trying to mock a class with this method cause the "Duplicate type" error:

public function add(ActionableInterface $component, array|string|null $definition, ?string $type = null): void
{
    //...
}

Changing the type hint for $definition to mixed resolves the error, but is obviously not desirable.

@downsider
Copy link
Contributor

On investigation, this was fixed in #1106

Looks like it's just waiting for a new release

@davedevelopment any chance this could be released soon please?

@davedevelopment
Copy link
Collaborator

Sorry for the delay, will see if I can schedule some time this week to merge the branches and release.

@downsider
Copy link
Contributor

Thanks for the release @davedevelopment

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