psalm / psalm-plugin-phpunit

A PHPUnit plugin for Psalm
77 stars 33 forks source link

InvocationMocker::method has been marked as internal #69

Open JoshuaBehrens opened 4 years ago

JoshuaBehrens commented 4 years ago

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 commented 4 years ago

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

JoshuaBehrens commented 4 years ago

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 commented 4 years ago

No, that should be enough.

micheh commented 4 years ago

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

https://github.com/sebastianbergmann/phpunit/pull/4310