I install Symfony 4 and then API Platform.
Then I create Test class like this
class UserFunctionalTest extends WebTestCase { /** @var string */ protected $host = "https://wikaunting-api.local"; /** @var KernelBrowser */ protected $client; protected function setUp() { $this->client = static::createClient(); } public function testCreateUser() { $response = $this->client->request('POST', $this->host . '/api/users.json', [ 'json' => [ 'username' => 'jamielann1', 'email' => '[email protected]', 'password' => 'jamielann1', ], ]); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); } } When I run ./bin/phpunit, I got error message
Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException: "The content-type "application/x-www-form-urlencoded" is not supported. Supported MIME types are "application/ld+json", "application/json", "text/html"." at /home/vagrant/Code/testcode/vendor/api-platform/core/src/EventListener/DeserializeListener.php line 130 My question is, why it is not received as application/json? What is the proper way?
client bundled with Symfony?application/json. Thank you for mentioning the second part.