|
2 | 2 |
|
3 | 3 | namespace App\Tests\Users;
|
4 | 4 |
|
5 |
| -use App\DataFixtures\UserSeeder; |
6 |
| -use App\Entity\User; |
7 |
| -use App\Entity\UserAddress; |
8 |
| -use App\Repository\UserRepository; |
9 | 5 | use App\Tests\EtuUTTApiTestCase;
|
10 |
| -use DateTimeInterface; |
11 |
| -use Faker\Provider\Address; |
12 | 6 | use Faker\Provider\Uuid;
|
13 | 7 | use Symfony\Component\HttpFoundation\Response;
|
14 | 8 |
|
15 |
| -class UpdateUser extends EtuUTTApiTestCase |
| 9 | +/** |
| 10 | + * @internal |
| 11 | + * |
| 12 | + * @coversNothing |
| 13 | + */ |
| 14 | +final class UpdateUser extends EtuUTTApiTestCase |
16 | 15 | {
|
17 |
| - |
18 |
| - public function testNormal() : void |
| 16 | + public function testNormal(): void |
19 | 17 | {
|
20 | 18 | $client = static::createClient();
|
21 |
| - $client->setDefaultOptions([ 'headers' => [ 'CAS-LOGIN' => 'test', 'Content-Type' => 'application/merge-patch+json' ]]); |
| 19 | + $client->setDefaultOptions(['headers' => ['CAS-LOGIN' => 'test', 'Content-Type' => 'application/merge-patch+json']]); |
22 | 20 | $testUser = $this->createUser('Foo', 'Bar', 'foobar');
|
23 | 21 | $testUserId = $testUser->getId();
|
24 | 22 | $testUserStudentId = $testUser->getStudentId();
|
25 | 23 | $testUserNationality = $testUser->getInfos()->getNationality();
|
26 |
| - $testUserBirthday = $testUser->getInfos()->getBirthday()->format(DateTimeInterface::RFC3339); |
| 24 | + $testUserBirthday = $testUser->getInfos()->getBirthday()->format(\DateTimeInterface::RFC3339); |
27 | 25 | $testUserAvatar = $testUser->getInfos()->getAvatar();
|
28 |
| - $crawler = $client->request('PATCH', '/users/'.$testUser->getId(), [ 'body' => json_encode([ |
| 26 | + $crawler = $client->request('PATCH', '/users/'.$testUser->getId(), ['body' => json_encode([ |
29 | 27 | 'socialNetwork' => [
|
30 | 28 | 'facebook' => 'https://facebook.com/foobar',
|
31 | 29 | 'twitter' => 'https://twitter.com/foobar',
|
@@ -61,97 +59,96 @@ public function testNormal() : void
|
61 | 59 | 'mailsPhones' => [
|
62 | 60 | 'mailPersonal' => '[email protected]',
|
63 | 61 | 'phoneNumber' => '01 23 45 67 89',
|
64 |
| - ] |
| 62 | + ], |
65 | 63 | ])]);
|
66 | 64 | $this->assertResponseStatusCodeSame(Response::HTTP_OK);
|
67 | 65 | $response = json_decode($crawler->getContent());
|
68 | 66 | // User checks
|
69 |
| - $this->assertEquals($testUserId->jsonSerialize(), $response->{'id'}); |
70 |
| - $this->assertEquals('foobar', $response->{'login'}); |
71 |
| - $this->assertEquals($testUserStudentId, $response->{'studentId'}); |
72 |
| - $this->assertEquals('Foo', $response->{'firstName'}); |
73 |
| - $this->assertEquals('Bar', $response->{'lastName'}); |
| 67 | + static::assertSame($testUserId->jsonSerialize(), $response->{'id'}); |
| 68 | + static::assertSame('foobar', $response->{'login'}); |
| 69 | + static::assertSame($testUserStudentId, $response->{'studentId'}); |
| 70 | + static::assertSame('Foo', $response->{'firstName'}); |
| 71 | + static::assertSame('Bar', $response->{'lastName'}); |
74 | 72 | // socialNetwork checks
|
75 |
| - $this->assertEquals('https://facebook.com/foobar', $response->{'socialNetwork'}->{'facebook'}); |
76 |
| - $this->assertEquals('https://twitter.com/foobar', $response->{'socialNetwork'}->{'twitter'}); |
77 |
| - $this->assertEquals('https://instagram.com/foobar', $response->{'socialNetwork'}->{'instagram'}); |
78 |
| - $this->assertEquals('https://linkedin.com/foobar', $response->{'socialNetwork'}->{'linkedin'}); |
79 |
| - $this->assertEquals('FooBar', $response->{'socialNetwork'}->{'pseudoDiscord'}); |
80 |
| - $this->assertEquals(true, $response->{'socialNetwork'}->{'wantDiscordUTT'}); |
| 73 | + static::assertSame('https://facebook.com/foobar', $response->{'socialNetwork'}->{'facebook'}); |
| 74 | + static::assertSame('https://twitter.com/foobar', $response->{'socialNetwork'}->{'twitter'}); |
| 75 | + static::assertSame('https://instagram.com/foobar', $response->{'socialNetwork'}->{'instagram'}); |
| 76 | + static::assertSame('https://linkedin.com/foobar', $response->{'socialNetwork'}->{'linkedin'}); |
| 77 | + static::assertSame('FooBar', $response->{'socialNetwork'}->{'pseudoDiscord'}); |
| 78 | + static::assertTrue($response->{'socialNetwork'}->{'wantDiscordUTT'}); |
81 | 79 | // infos checks
|
82 |
| - $this->assertEquals('Féminin', $response->{'infos'}->{'sex'}); |
83 |
| - $this->assertEquals($testUserNationality, $response->{'infos'}->{'nationality'}); |
84 |
| - $this->assertEquals($testUserBirthday, $response->{'infos'}->{'birthday'}); |
85 |
| - $this->assertEquals($testUserAvatar, $response->{'infos'}->{'avatar'}); |
86 |
| - $this->assertEquals('foobar', $response->{'infos'}->{'nickname'}); |
87 |
| - $this->assertEquals('I don\'t have passions :(', $response->{'infos'}->{'passions'}); |
88 |
| - $this->assertEquals('https://foobar.com', $response->{'infos'}->{'website'}); |
| 80 | + static::assertSame('Féminin', $response->{'infos'}->{'sex'}); |
| 81 | + static::assertSame($testUserNationality, $response->{'infos'}->{'nationality'}); |
| 82 | + static::assertSame($testUserBirthday, $response->{'infos'}->{'birthday'}); |
| 83 | + static::assertSame($testUserAvatar, $response->{'infos'}->{'avatar'}); |
| 84 | + static::assertSame('foobar', $response->{'infos'}->{'nickname'}); |
| 85 | + static::assertSame('I don\'t have passions :(', $response->{'infos'}->{'passions'}); |
| 86 | + static::assertSame('https://foobar.com', $response->{'infos'}->{'website'}); |
89 | 87 | // addresses checks
|
90 |
| - $this->assertCount(1, $response->{'addresses'}); |
91 |
| - $this->assertEquals('Foobar Avenue', $response->{'addresses'}[0]->{'street'}); |
92 |
| - $this->assertEquals('00 000', $response->{'addresses'}[0]->{'postalCode'}); |
93 |
| - $this->assertEquals('Foobar City', $response->{'addresses'}[0]->{'city'}); |
94 |
| - $this->assertEquals('United States of Foobar', $response->{'addresses'}[0]->{'country'}); |
| 88 | + static::assertCount(1, $response->{'addresses'}); |
| 89 | + static::assertSame('Foobar Avenue', $response->{'addresses'}[0]->{'street'}); |
| 90 | + static::assertSame('00 000', $response->{'addresses'}[0]->{'postalCode'}); |
| 91 | + static::assertSame('Foobar City', $response->{'addresses'}[0]->{'city'}); |
| 92 | + static::assertSame('United States of Foobar', $response->{'addresses'}[0]->{'country'}); |
95 | 93 | // mailsPhones checks
|
96 |
| - $this->assertEquals( '[email protected]', $response->{ 'mailsPhones'}->{ 'mailPersonal'}); |
97 |
| - $this->assertEquals('01 23 45 67 89', $response->{'mailsPhones'}->{'phoneNumber'}); |
| 94 | + static::assertSame( '[email protected]', $response->{ 'mailsPhones'}->{ 'mailPersonal'}); |
| 95 | + static::assertSame('01 23 45 67 89', $response->{'mailsPhones'}->{'phoneNumber'}); |
98 | 96 | }
|
99 | 97 |
|
100 |
| - public function testNotConnected() : void |
| 98 | + public function testNotConnected(): void |
101 | 99 | {
|
102 | 100 | $client = static::createClient();
|
103 |
| - $client->setDefaultOptions([ 'headers' => ['Content-Type' => 'application/merge-patch+json' ]]); |
104 |
| - $client->request('PATCH', '/users/'.$this->user->getId(), [ 'body' => []]); |
| 101 | + $client->setDefaultOptions(['headers' => ['Content-Type' => 'application/merge-patch+json']]); |
| 102 | + $client->request('PATCH', '/users/'.$this->user->getId(), ['body' => []]); |
105 | 103 | $this->assertResponseStatusCodeSame(Response::HTTP_UNAUTHORIZED);
|
106 |
| - $client->request('PATCH', '/users/'.Uuid::uuid(), [ 'body' => []]); |
| 104 | + $client->request('PATCH', '/users/'.Uuid::uuid(), ['body' => []]); |
107 | 105 | // Strange this returns a 404, but it does not change much about security issues
|
108 | 106 | $this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
|
109 | 107 | }
|
110 | 108 |
|
111 |
| - public function testNonExistingUser() : void |
| 109 | + public function testNonExistingUser(): void |
112 | 110 | {
|
113 | 111 | $client = static::createClient();
|
114 |
| - $client->setDefaultOptions([ 'headers' => [ 'CAS-LOGIN' => 'test', 'Content-Type' => 'application/merge-patch+json' ]]); |
115 |
| - $client->request('PATCH', '/users/'.Uuid::uuid(), [ 'body' => []]); |
| 112 | + $client->setDefaultOptions(['headers' => ['CAS-LOGIN' => 'test', 'Content-Type' => 'application/merge-patch+json']]); |
| 113 | + $client->request('PATCH', '/users/'.Uuid::uuid(), ['body' => []]); |
116 | 114 | $this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
|
117 | 115 | }
|
118 | 116 |
|
119 |
| - public function testNoParameter() : void |
| 117 | + public function testNoParameter(): void |
120 | 118 | {
|
121 | 119 | $client = static::createClient();
|
122 |
| - $client->setDefaultOptions([ 'headers' => [ 'CAS-LOGIN' => 'test', 'Content-Type' => 'application/merge-patch+json' ]]); |
| 120 | + $client->setDefaultOptions(['headers' => ['CAS-LOGIN' => 'test', 'Content-Type' => 'application/merge-patch+json']]); |
123 | 121 | $client->request('PATCH', '/users/'.$this->user->getId());
|
124 | 122 | $this->assertResponseStatusCodeSame(Response::HTTP_BAD_REQUEST);
|
125 | 123 | }
|
126 | 124 |
|
127 |
| - public function testSQLInjection() : void |
| 125 | + public function testSQLInjection(): void |
128 | 126 | {
|
129 | 127 | $client = static::createClient();
|
130 |
| - $client->setDefaultOptions([ 'headers' => [ 'CAS-LOGIN' => 'test', 'Content-Type' => 'application/merge-patch+json' ]]); |
| 128 | + $client->setDefaultOptions(['headers' => ['CAS-LOGIN' => 'test', 'Content-Type' => 'application/merge-patch+json']]); |
131 | 129 | $testUser = $this->createUser('foo', 'bar', 'foobar');
|
132 |
| - $client->request('PATCH', '/users/\'', [ 'body' => [] ]); |
| 130 | + $client->request('PATCH', '/users/\'', ['body' => []]); |
133 | 131 | $this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
|
134 |
| - $client->request('PATCH', '/users/"', [ 'body' => [] ]); |
| 132 | + $client->request('PATCH', '/users/"', ['body' => []]); |
135 | 133 | $this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
|
136 |
| - $client->request('PATCH', '/users/'.$testUser->getId(), [ 'body' => [ 'socialNetwork' => ['facebook' => '\''] ]]); |
| 134 | + $client->request('PATCH', '/users/'.$testUser->getId(), ['body' => ['socialNetwork' => ['facebook' => '\'']]]); |
137 | 135 | $this->assertResponseStatusCodeSame(Response::HTTP_UNSUPPORTED_MEDIA_TYPE);
|
138 |
| - $client->request('PATCH', '/users/'.$testUser->getId(), [ 'body' => [ 'socialNetwork' => ['facebook' => '"'] ]]); |
| 136 | + $client->request('PATCH', '/users/'.$testUser->getId(), ['body' => ['socialNetwork' => ['facebook' => '"']]]); |
139 | 137 | $this->assertResponseStatusCodeSame(Response::HTTP_UNSUPPORTED_MEDIA_TYPE);
|
140 | 138 | }
|
141 | 139 |
|
142 |
| - public function testInvalidFieldContent() : void |
| 140 | + public function testInvalidFieldContent(): void |
143 | 141 | {
|
144 | 142 | $client = static::createClient();
|
145 |
| - $client->setDefaultOptions([ 'headers' => [ 'CAS-LOGIN' => 'test', 'Content-Type' => 'application/merge-patch+json' ]]); |
| 143 | + $client->setDefaultOptions(['headers' => ['CAS-LOGIN' => 'test', 'Content-Type' => 'application/merge-patch+json']]); |
146 | 144 | $testUser = $this->createUser('foo', 'bar', 'foobar');
|
147 |
| - $client->request('PATCH', '/users/\'', [ 'body' => [] ]); |
| 145 | + $client->request('PATCH', '/users/\'', ['body' => []]); |
148 | 146 | $this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
|
149 |
| - $client->request('PATCH', '/users/"', [ 'body' => [] ]); |
| 147 | + $client->request('PATCH', '/users/"', ['body' => []]); |
150 | 148 | $this->assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
|
151 |
| - $client->request('PATCH', '/users/'.$testUser->getId(), [ 'body' => [ 'socialNetwork' => ['facebook' => '\''] ]]); |
| 149 | + $client->request('PATCH', '/users/'.$testUser->getId(), ['body' => ['socialNetwork' => ['facebook' => '\'']]]); |
152 | 150 | $this->assertResponseStatusCodeSame(Response::HTTP_UNSUPPORTED_MEDIA_TYPE);
|
153 |
| - $client->request('PATCH', '/users/'.$testUser->getId(), [ 'body' => [ 'socialNetwork' => ['facebook' => '"'] ]]); |
| 151 | + $client->request('PATCH', '/users/'.$testUser->getId(), ['body' => ['socialNetwork' => ['facebook' => '"']]]); |
154 | 152 | $this->assertResponseStatusCodeSame(Response::HTTP_UNSUPPORTED_MEDIA_TYPE);
|
155 | 153 | }
|
156 |
| - |
157 | 154 | }
|
0 commit comments