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

Mocking multiple types reports errors with phpstan 0.12 #58

Open
Khartir opened this issue Jan 17, 2020 · 1 comment · May be fixed by #61
Open

Mocking multiple types reports errors with phpstan 0.12 #58

Khartir opened this issue Jan 17, 2020 · 1 comment · May be fixed by #61

Comments

@Khartir
Copy link

Khartir commented Jan 17, 2020

Calling createMock with multiple Types causes phpstan to report errors:

A class like

<?php declare(strict_types=1);

namespace App;

use PHPUnit\Framework\TestCase;

class Test extends TestCase
{

    public function testDummy(): void {
        $this->createMock([\DateTimeInterface::class, \ArrayAccess::class]);
    }
}

throws the following errors:

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   Test.php                                                                                                                                         
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------- 
  11     Parameter #1 $originalClassName of method PHPUnit\Framework\TestCase::createMock() expects class-string<mixed>, array<int, class-string> given.  
  11     Unable to resolve the template type T in call to method PHPUnit\Framework\TestCase::createMock()                                         
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------- 

The error also occurs, if there is only one class given, but not as a string, but as an array:
$this->createMock([\DateTimeInterface::class]); produces the same error.

This is working fine in phpstan 0.11

@ondrejmirtes
Copy link
Member

I inspected the code in 0.11 and it couldn't have worked before, you just received MockObject without intersected mocked classes. So 0.12 just surfaces that it doesn't do what you want it to do. Of course it can be fixed with a similar extension I reverted here (in favour of stubs): https://github.com/phpstan/phpstan-phpunit/blob/79d30f7074ecb773c70147a01478b31efca79023/src/Type/PHPUnit/CreateMockDynamicReturnTypeExtension.php

@Khartir Khartir linked a pull request Feb 7, 2020 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants