Slamdunk / phpstan-laminas-framework

Laminas Framework 3 extensions for PHPStan
MIT License
16 stars 10 forks source link

Additional errors when using this plugin #25

Closed mimmi20 closed 3 years ago

mimmi20 commented 3 years ago

I tried to use this plugin, but got the following errors.

My Tests including the ServiceManager are configured like this:

use Laminas\ServiceManager\Exception\ContainerModificationsNotAllowedException;
use Laminas\ServiceManager\Factory\InvokableFactory;
use Laminas\ServiceManager\ServiceManager;
use Laminas\View\Helper\HelperInterface;
use Laminas\View\HelperPluginManager;
use Mezzio\BootstrapForm\LaminasView\View\Helper\ConfigProvider;
use Mezzio\Helper\ServerUrlHelper as BaseServerUrlHelper;
use Mezzio\LaminasView\HelperPluginManagerFactory;
use Mezzio\LaminasView\LaminasViewRenderer;
use Mezzio\LaminasView\LaminasViewRendererFactory;
use Mezzio\LaminasViewHelper\Helper\PluginManager as LvhPluginManager;
use Mezzio\LaminasViewHelper\Helper\PluginManagerFactory as LvhPluginManagerFactory;
use PHPUnit\Framework\Exception;
use PHPUnit\Framework\TestCase;
use SebastianBergmann\RecursionContext\InvalidArgumentException;

use function file_get_contents;
use function sprintf;
use function str_replace;

use const PHP_EOL;

/**
 * Base class for navigation view helper tests
 */
abstract class AbstractTest extends TestCase
{
    protected ServiceManager $serviceManager;

    /**
     * Path to files needed for test
     */
    protected string $files;

    /**
     * Class name for view helper to test
     */
    protected string $helperName;

    /**
     * View helper
     */
    protected HelperInterface $helper;

    /**
     * Prepares the environment before running a test
     *
     * @throws ContainerModificationsNotAllowedException
     */
    protected function setUp(): void
    {
        $cwd = __DIR__;

        // read navigation config
        $this->files = $cwd . '/_files';

        $sm = $this->serviceManager = new ServiceManager();
        $sm->setAllowOverride(true);

        $sm->setFactory(HelperPluginManager::class, HelperPluginManagerFactory::class);
        $sm->setFactory(LvhPluginManager::class, LvhPluginManagerFactory::class);

        $sm->setFactory(
            'config',
            static fn (): array => [
                'view_helpers' => (new ConfigProvider())->getViewHelperConfig(),
            ]
        );
        $sm->setFactory(LaminasViewRenderer::class, LaminasViewRendererFactory::class);
        $sm->setFactory(BaseServerUrlHelper::class, InvokableFactory::class);

        $sm->setAllowOverride(false);
    }
...

Without this plugin these errors dont occur.

Slamdunk commented 3 years ago

This should have been fixed in https://github.com/Slamdunk/phpstan-laminas-framework/pull/22, released in v0.12.5 six days ago, which version do you use?

mimmi20 commented 3 years ago

This should have been fixed in #22, released in v0.12.5 six days ago, which version do you use?

0.12.6

Slamdunk commented 3 years ago

May I ask you if you provided to PHPStan your ServiceManager as described here https://github.com/Slamdunk/phpstan-laminas-framework#configuration ?

mimmi20 commented 3 years ago

May I ask you if you provided to PHPStan your ServiceManager as described here

No, I have not. I only have a ConfigProvider. The ServiceManager is configured during in the setup method of all tests. The Project I tried to use this, is a library only, not an application.

mimmi20 commented 3 years ago

Maybe this extension is not usable for my projects.