2
2
3
3
namespace tests \integration \App \Controller ;
4
4
5
+ use Symfony \Component \HttpFoundation \Response ;
5
6
use tests \integration \App \WebTestCase ;
6
7
7
8
/**
@@ -18,5 +19,63 @@ public function testGetUsers()
18
19
$ this ->assertTrue ($ client ->getResponse ()->isOk ());
19
20
$ this ->assertJson ($ client ->getResponse ()->getContent ());
20
21
$ 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 ());
21
80
}
22
81
}
0 commit comments