Skip to content

Commit 645083b

Browse files
committed
Add more tests
1 parent a851d7e commit 645083b

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/integration/App/Controller/UserControllerTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace tests\integration\App\Controller;
44

5+
use Symfony\Component\HttpFoundation\Response;
56
use tests\integration\App\WebTestCase;
67

78
/**
@@ -18,5 +19,63 @@ public function testGetUsers()
1819
$this->assertTrue($client->getResponse()->isOk());
1920
$this->assertJson($client->getResponse()->getContent());
2021
$this->assertNotEmpty($client->getResponse()->getContent());
22+
$this->assertCount(2, json_decode($client->getResponse()->getContent()));
23+
}
24+
25+
public function testGetUser()
26+
{
27+
$client = $this->createClient();
28+
$client->followRedirects(true);
29+
$client->request('GET', '/user/1');
30+
$this->assertTrue($client->getResponse()->isOk());
31+
$this->assertJson($client->getResponse()->getContent());
32+
$this->assertNotEmpty($client->getResponse()->getContent());
33+
}
34+
35+
public function testCreateUser()
36+
{
37+
$client = $this->createClient();
38+
$client->followRedirects(true);
39+
$client->request(
40+
'POST',
41+
'/user/',
42+
[],
43+
[],
44+
['CONTENT_TYPE' => 'application/json'],
45+
json_encode(['email' => 'michaelbluth@arresteddevelopment.com'])
46+
);
47+
$this->assertTrue($client->getResponse()->isOk());
48+
$this->assertNotNull($client->getResponse()->getContent());
49+
$this->assertJson($client->getResponse()->getContent());
50+
}
51+
52+
public function testUpdateUser()
53+
{
54+
$updatedUser = ['email' => 'georgemichael@arrestedevelopment.com'];
55+
$client = $this->createClient();
56+
$client->followRedirects(true);
57+
$client->request(
58+
'PUT',
59+
'/user/2',
60+
[],
61+
[],
62+
['CONTENT_TYPE' => 'application/json'],
63+
json_encode($updatedUser)
64+
);
65+
$this->assertTrue($client->getResponse()->isOk());
66+
$this->assertJson($client->getResponse()->getContent());
67+
$this->assertNotEmpty($client->getResponse()->getContent());
68+
$responseArray = json_decode($client->getResponse()->getContent(), true);
69+
$this->assertArrayHasKey('email', $responseArray);
70+
$this->assertEquals($updatedUser['email'], $updatedUser['email']);
71+
}
72+
73+
public function testDeleteUser()
74+
{
75+
$client = $this->createClient();
76+
$client->followRedirects(true);
77+
$client->request('DELETE', '/user/2');
78+
$this->assertTrue($client->getResponse()->isEmpty());
79+
$this->assertEquals(Response::HTTP_NO_CONTENT, $client->getResponse()->getStatusCode());
2180
}
2281
}

0 commit comments

Comments
 (0)