Created
November 20, 2021 10:28
-
-
Save ismail1432/e9e52c0d7e3346db46d6c0e61e9e7d3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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