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

InvocationMocker::method has been marked as internal #69

Open
JoshuaBehrens opened this issue May 3, 2020 · 4 comments
Open

InvocationMocker::method has been marked as internal #69

JoshuaBehrens opened this issue May 3, 2020 · 4 comments

Comments

@JoshuaBehrens
Copy link

I am unsure whether this is right here. I am using psalm, phpunit and this plugin together. PHPUnit\Framework\MockObject\Builder\InvocationMocker is marked as internal but it is the way to mock objects. So when I combine them I have to start mocking everything manually?

@weirdan
Copy link
Member

weirdan commented May 4, 2020

Hey @JoshuaBehrens, can you provide the failing test case?

@weirdan weirdan added the more info needed There's no enough information provided to address the issue label May 4, 2020
@JoshuaBehrens
Copy link
Author

Yeah sure I can provide a sample:

<?php declare(strict_types=1);

namespace App\Test;

use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

class LoggerTest extends TestCase
{
    public function testLogging(): void
    {
        $logger = $this->createMock(LoggerInterface::class);
        $logger->expects($this->atLeastOnce())
            ->method('critical')
            ->with('oh noez');
        $logger->critical('oh noez');
    }
}

Results in:

ERROR: InternalMethod - test/LoggerTest.php:14:15 - The method PHPUnit\Framework\MockObject\Builder\InvocationMocker::method has been marked as internal (see https://psalm.dev/175)
            ->method('critical')
ERROR: InternalMethod - test/LoggerTest.php:15:15 - The method PHPUnit\Framework\MockObject\Builder\InvocationMocker::with has been marked as internal (see https://psalm.dev/175)
            ->with('oh noez');

I currently by-pass it with whitelisting these in my psalm.xml like this:

<?xml version="1.0"?>
<psalm
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="https://getpsalm.org/schema/config"
    xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
    <issueHandlers>
        <InternalMethod>
            <errorLevel type="info">
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::after"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::canDefineParameters"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::id"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::method"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::will"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturn"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturn"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturnArgument"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturnCallback"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturnMap"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturnOnConsecutiveCalls"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturnReference"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturnSelf"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willThrowException"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::with"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::withAnyParameters"/>
                <referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::withConsecutive"/>
            </errorLevel>
        </InternalMethod>
    </issueHandlers>

    <plugins>
        <pluginClass class="Psalm\PhpUnitPlugin\Plugin" />
    </plugins>
</psalm>

As you can see the phpunit plugin is enabled and psalm-plugin sees it the same:

$ vendor/bin/psalm-plugin

Enabled
-------

 ---------------------- ---------------------------- 
  Package                Class                       
 ---------------------- ---------------------------- 
  psalm/plugin-phpunit   Psalm\PhpUnitPlugin\Plugin  
 ---------------------- ---------------------------- 

Do you need any more info?

@weirdan weirdan removed the more info needed There's no enough information provided to address the issue label May 4, 2020
@weirdan
Copy link
Member

weirdan commented May 4, 2020

No, that should be enough.

@micheh
Copy link

micheh commented Jul 2, 2020

This should be fixed in the next release of PHPUnit (8.5.9).

sebastianbergmann/phpunit#4310

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

3 participants