Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Tests\AppBundle\Controller;
- use Tests\ApiTestCaseBase;
- class AuthControllerTest extends ApiTestCaseBase
- {
- public function testPostRegsiterNewUser()
- {
- $data = [
- 'username' => 'test_login',
- 'email' => 'test@gmail.com',
- 'plainPassword' => [
- 'first' => 'test123', 'second' => 'test123'
- ]
- ];
- $this->makePOSTRequest($data);
- $this->assertEquals(201, $this->client->getResponse()->getStatusCode());
- }
- public function testPostRegsiterNewUserWithInvalidEmail()
- {
- $data = [
- 'username' => 'test_login',
- 'email' => 'testgmail.com',
- 'plainPassword' => [
- 'first' => 'test123', 'second' => 'test123'
- ]
- ];
- $this->makePOSTRequest($data);
- $this->assertEquals(400, $this->client->getResponse()->getStatusCode());
- }
- public function testPOSTLoginUser()
- {
- $userName = "test_login";
- $password = "test_login_2017";
- $user = $this->createUser($userName, $password);
- $this->client->request(
- 'POST', '/auth/login', [], [], [
- 'CONTENT_TYPE' => 'application/json',
- 'PHP_AUTH_USER' => $userName,
- 'PHP_AUTH_PW' => $password,
- ]
- );
- $responseArr = json_decode($this->client->getResponse()->getContent(), true);
- $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
- $this->assertArrayHasKey('token', $responseArr);
- }
- private function makePOSTRequest($data)
- {
- $this->client->request(
- 'POST',
- '/auth/register',
- [],
- [],
- ['CONTENT_TYPE' => 'application/json'],
- json_encode($data)
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement