LogicException: "framework.test" config is not set to true

  symfony, symfony5

I am new to symfony, any help would be appreciated. I am trying to create one sample api and then a test case for it. I have set framework.test to true in,

config/packages/test/framework.yaml

I have defined routes with api/v1/ prefix in routes.yaml file. I can make request to api/v1/test-endpoint using CURL 🙂 . But whenever I try to execute my test case using following command I receive "framework.test" config is not set to true error.

php -d pcov.enabled=1 vendor/bin/phpunit

<?php

declare(strict_types=1);

namespace AppController;

use APPErrorResponseErrorResponseAwareTrait;
use SymfonyBundleFrameworkBundleControllerAbstractController;

abstract class AbstractClientApiController extends AbstractController
{
    
    use ErrorResponseAwareTrait;
}

Sample Api for test response,

<?php

declare(strict_types=1);

namespace AppControllerApiV1;

use AppControllerAbstractClientApiController as BaseController;
use SymfonyComponentHttpFoundationJsonResponse;
use SymfonyComponentHttpFoundationResponse;

final class DefaultController extends BaseController
{
    public function index(): JsonResponse
    {
        return new JsonResponse(['result' => 'Test is successful!'], Response::HTTP_OK);
    }
}

here is my test,

<?php

declare(strict_types=1);

namespace AppTestsFunctionalControllerApiV1;

use AppTestsHelperFactoryUserFactory;
use SymfonyBundleFrameworkBundleTestWebTestCase;
use SymfonyBundleFrameworkBundleKernelBrowser;
use SymfonyComponentHttpFoundationRequest;

class DefaultControllerTest extends WebTestCase
{
    private const BASE_URI = '/api/v1';
    private const TEST_ENDPOINT = '/test-endpoint';

    protected KernelBrowser $client;

    protected function setUp(): void
    {
        parent::setUp();

        $this->client = static::createClient();
    }

    protected function tearDown(): void
    {
        parent::tearDown();
    }

    public function testRoute(): void
    {
        $this->client->request(Request::METHOD_GET, self::BASE_URI . self::TEST_ENDPOINT);
        $response = $this->client->getResponse();
        $this->assertSame(true, $response->isSuccessful());
    }
}

I am receiving following error, every-time i try to execute my test

1) AppTestsFunctionalControllerApiV1DefaultControllerTest::testRoute
LogicException: You cannot create the client used in functional tests if the "framework.test" config is not set to true.

/app/vendor/symfony/framework-bundle/Test/WebTestCase.php:52
/app/tests/Functional/Controller/Api/V1/DefaultControllerTest.php:26

Source: Symfony Questions

2 thoughts on - LogicException: "framework.test" config is not set to true

LEAVE A COMMENT