Please, I am trying to create a unit test on API platform endpoint as follow. I configured a test environment and doctrine.yml
namespace App\Tests\Api;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;
class ProfileApiTest extends ApiTestCase
{
public function testGetCollection(): void
{
$client = static::createClient();
$client->request('GET', '/api/profile');
$this->assertJsonContains([
'profile' => [
'name' => 'James Bond',
'sex' => 'Male',
'color' => 'blue',
],
]);
$data = $client->getResponse()->toArray();
$this->assertArrayNotHasKey('_links', $data);
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('content-type', 'application/ld json; charset=utf-8');
}
}
This is my doctrine.yml
doctrine:
dbal:
url:'%env(resolve:DATABASE_URL)%'
I created env.test.local as follows
DATABASE_URL_TEST=postgresql://postgres:ojpuddy1!2@sql:5432/school_test?serverVersion=12.3
I have tried several steps with the test file but I see it is not the problem. I have searched everywhere for the solution. I have gone through symfony/api-platform documentations but couldn't find any tangible.
Symfony\Component\Config\Definition\Exception\InvalidTypeException: Invalid type for path "doctrine.dbal". Expected "array", but got "string"
CodePudding user response:
In your doctrine.yaml
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL_TEST)%'
also not that in your env.test.local, DATABASE_URL_TEST
DATABASE_URL_TEST=postgresql://postgres:ojpuddy1!2@sql:5432/school_test?serverVersion=12.3
You need to add a space between url: and '%env(resolve:DATABASE_URL)%'.
