Skip to content

Instantly share code, notes, and snippets.

@ismail1432
Created November 20, 2021 10:28
Show Gist options
  • Save ismail1432/e9e52c0d7e3346db46d6c0e61e9e7d3b to your computer and use it in GitHub Desktop.
Save ismail1432/e9e52c0d7e3346db46d6c0e61e9e7d3b to your computer and use it in GitHub Desktop.
<?php
namespace App\Tests;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class UserActionTest extends WebTestCase
{
public function testWrongPayload(): void
{
$client = static::createClient();
// We create a wrong payload
$payload = [
"email" => "FR_fr",
"name" => null
];
// send the request
$client->request('POST', '/users', [], [], [], json_encode($payload));
// decode the response as an array
$response = json_decode($client->getResponse()->getContent(), true);
$this->assertResponseStatusCodeSame(400);
$expected = [
[
"property" => "[name]",
"message" => "This value should not be blank."
],
[
"property" => "[email]",
"message" => "This value is not a valid email address."
]
];
self::assertEquals($expected, $response);
}
public function testWrongLimitCriteria(): void
{
$client = static::createClient();
$client->request('GET', '/users?limit=-42');
$response = json_decode($client->getResponse()->getContent(), true);
$expected = [
[
"property" => "[limit]",
'message' => 'This value should be positive.'
]
];
self::assertEquals($expected, $response);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment