Codeception / module-lumen

Codeception module for Lumen framework
MIT License
0 stars 5 forks source link

Lumen 9.0.2 - Declaration of DummyKernel must be compatible with HttpKernelInterface #22

Open blacksheep122 opened 2 years ago

blacksheep122 commented 2 years ago

What are you trying to achieve?

Run tests in general (using make).

What do you get instead?

Fatal error: Declaration of Codeception\Lib\Connector\Lumen\DummyKernel::handle(Symfony\Component\HttpFoundation\Request $request, $type = self::MASTER_REQUEST, $catch = true): void must be compatible with Symfony\Component\HttpKernel\HttpKernelInterface::handle(Symfony\Component\HttpFoundation\Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Symfony\Component\HttpFoundation\Response in /var/www/vendor/codeception/module-lumen/src/Codeception/Lib/Connector/Lumen/DummyKernel.php on line 15

FATAL ERROR. TESTS NOT FINISHED.
Declaration of Codeception\Lib\Connector\Lumen\DummyKernel::handle(Symfony\Component\HttpFoundation\Request $request, $type = self::MASTER_REQUEST, $catch = true): void must be compatible with Symfony\Component\HttpKernel\HttpKernelInterface::handle(Symfony\Component\HttpFoundation\Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Symfony\Component\HttpFoundation\Response 
in /var/www/vendor/codeception/module-lumen/src/Codeception/Lib/Connector/Lumen/DummyKernel.php:15

Details

* Suite configuration:

```yml
actor: ApiTester
suite_namespace: \Api
modules:
    enabled:
      - REST:
          url: /api/v1/
          depends: Lumen
PetrenkoAnton commented 9 months ago

Same error. Are there any fixes?

blacksheep122 commented 9 months ago

Fastest way to fix it (for my case at least):

In composer.json:

"autoload-dev": {
    "exclude-from-classmap": [
      "vendor/codeception/module-lumen/src/Codeception/Lib/Connector/Lumen/DummyKernel.php",
    ],
    "files": [
      "app/Custom/Codeception/Lib/Connector/Lumen/DummyKernel.php",
    ],

Content of "app/Custom/Codeception/Lib/Connector/Lumen/DummyKernel.php":

<?php

declare(strict_types=1);

namespace Codeception\Lib\Connector\Lumen;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;

/**
 * Dummy kernel to satisfy the parent constructor of the LumenConnector class.
 */
class DummyKernel implements HttpKernelInterface
{
    public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true): void
    {
        //
     }
}
PetrenkoAnton commented 9 months ago

@blacksheep122 , thanks!

After the fixes everything works as expected.

Below are some explanations.

tests/Support/DummyKernel.php (location in my case):

<?php

declare(strict_types=1);

namespace Codeception\Lib\Connector\Lumen;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;

/**
 * Dummy kernel to satisfy the parent constructor of the LumenConnector class.
 */
class DummyKernel implements HttpKernelInterface
{
    public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true): Response
    {
        //
    }
}

and valid json struct in composer.json:

    "autoload-dev": {
        "exclude-from-classmap": [
            "vendor/codeception/module-lumen/src/Codeception/Lib/Connector/Lumen/DummyKernel.php"
        ],
        "files": [
            "tests/Support/DummyKernel.php"
        ]
    },

And don't forget to run composer dump-autoload