Skip to content

Commit

Permalink
Use PSR7 response methods in IntegrationTestCaseTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Iandenh committed Jun 14, 2017
1 parent 5e79328 commit d8b4e0e
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions tests/TestCase/TestSuite/IntegrationTestCaseTest.php
Expand Up @@ -180,11 +180,11 @@ public function testGet()
$this->get('/request_action/test_request_action');
$this->assertNotEmpty($this->_response);
$this->assertInstanceOf('Cake\Http\Response', $this->_response);
$this->assertEquals('This is a test', $this->_response->body());
$this->assertEquals('This is a test', $this->_response->getBody());

$this->_response = null;
$this->get('/get/request_action/test_request_action');
$this->assertEquals('This is a test', $this->_response->body());
$this->assertEquals('This is a test', $this->_response->getBody());
}

/**
Expand All @@ -197,7 +197,7 @@ public function testGetSpecificRouteHttpServer()
$this->useHttpServer(true);
$this->get('/get/request_action/test_request_action');
$this->assertResponseOk();
$this->assertEquals('This is a test', $this->_response->body());
$this->assertEquals('This is a test', $this->_response->getBody());
}

/**
Expand Down Expand Up @@ -229,7 +229,7 @@ public function testGetHttpServer()
$this->get('/request_action/test_request_action');
$this->assertNotEmpty($this->_response);
$this->assertInstanceOf('Cake\Http\Response', $this->_response);
$this->assertEquals('This is a test', $this->_response->body());
$this->assertEquals('This is a test', $this->_response->getBody());
$this->assertHeader('X-Middleware', 'true');
}

Expand Down Expand Up @@ -276,7 +276,7 @@ public function testPostDataHttpServer()
$this->useHttpServer(true);

$this->post('/request_action/post_pass', ['title' => 'value']);
$data = json_decode($this->_response->body());
$data = json_decode($this->_response->getBody());
$this->assertEquals('value', $data->title);
$this->assertHeader('X-Middleware', 'true');
}
Expand All @@ -291,7 +291,10 @@ public function testInputDataHttpServer()
$this->useHttpServer(true);

$this->post('/request_action/input_test', '{"hello":"world"}');
$this->assertSame('world', $this->_response->body());
if ($this->_response->getBody()->isSeekable()) {
$this->_response->getBody()->rewind();
}
$this->assertSame('world', $this->_response->getBody()->getContents());
$this->assertHeader('X-Middleware', 'true');
}

Expand Down Expand Up @@ -627,34 +630,34 @@ public function testAssertResponseStatusCodes()
{
$this->_response = new Response();

$this->_response->statusCode(200);
$this->_response = $this->_response->withStatus(200);
$this->assertResponseOk();

$this->_response->statusCode(201);
$this->_response = $this->_response->withStatus(201);
$this->assertResponseOk();

$this->_response->statusCode(204);
$this->_response = $this->_response->withStatus(204);
$this->assertResponseOk();

$this->_response->statusCode(202);
$this->_response = $this->_response->withStatus(202);
$this->assertResponseSuccess();

$this->_response->statusCode(302);
$this->_response = $this->_response->withStatus(302);
$this->assertResponseSuccess();

$this->_response->statusCode(400);
$this->_response = $this->_response->withStatus(400);
$this->assertResponseError();

$this->_response->statusCode(417);
$this->_response = $this->_response->withStatus(417);
$this->assertResponseError();

$this->_response->statusCode(500);
$this->_response = $this->_response->withStatus(500);
$this->assertResponseFailure();

$this->_response->statusCode(505);
$this->_response = $this->_response->withStatus(505);
$this->assertResponseFailure();

$this->_response->statusCode(301);
$this->_response = $this->_response->withStatus(301);
$this->assertResponseCode(301);
}

Expand All @@ -666,7 +669,7 @@ public function testAssertResponseStatusCodes()
public function testAssertRedirect()
{
$this->_response = new Response();
$this->_response->header('Location', 'http://localhost/tasks/index');
$this->_response = $this->_response->withHeader('Location', 'http://localhost/tasks/index');

$this->assertRedirect();
$this->assertRedirect('/tasks/index');
Expand Down Expand Up @@ -709,7 +712,7 @@ public function testAssertNoRedirectFail()
public function testAssertRedirectContains()
{
$this->_response = new Response();
$this->_response->header('Location', 'http://localhost/tasks/index');
$this->_response = $this->_response->withHeader('Location', 'http://localhost/tasks/index');

$this->assertRedirectContains('/tasks/index');
}
Expand All @@ -722,7 +725,7 @@ public function testAssertRedirectContains()
public function testAssertHeader()
{
$this->_response = new Response();
$this->_response->header('Etag', 'abc123');
$this->_response = $this->_response->withHeader('Etag', 'abc123');

$this->assertHeader('Etag', 'abc123');
}
Expand All @@ -735,7 +738,7 @@ public function testAssertHeader()
public function testAssertHeaderContains()
{
$this->_response = new Response();
$this->_response->header('Etag', 'abc123');
$this->_response = $this->_response->withHeader('Etag', 'abc123');

$this->assertHeaderContains('Etag', 'abc');
}
Expand Down Expand Up @@ -775,7 +778,9 @@ public function testContentTypeInAction()
public function testAssertResponseContains()
{
$this->_response = new Response();
$this->_response->body('Some content');
$body = $this->_response->getBody();
$body->write('Some content');
$this->_response = $this->_response->withBody($body);

$this->assertResponseContains('content');
}
Expand All @@ -788,7 +793,9 @@ public function testAssertResponseContains()
public function testAssertResponseNotContains()
{
$this->_response = new Response();
$this->_response->body('Some content');
$body = $this->_response->getBody();
$body->write('Some content');
$this->_response = $this->_response->withBody($body);

$this->assertResponseNotContains('contents');
}
Expand All @@ -801,7 +808,9 @@ public function testAssertResponseNotContains()
public function testAssertResponseRegExp()
{
$this->_response = new Response();
$this->_response->body('Some content');
$body = $this->_response->getBody();
$body->write('Some content');
$this->_response = $this->_response->withBody($body);

$this->assertResponseRegExp('/cont/');
}
Expand All @@ -826,7 +835,9 @@ public function testAssertResponseRegExpNoResponse()
public function testAssertResponseNotRegExp()
{
$this->_response = new Response();
$this->_response->body('Some content');
$body = $this->_response->getBody();
$body->write('Some content');
$this->_response = $this->_response->withBody($body);

$this->assertResponseNotRegExp('/cant/');
}
Expand Down

0 comments on commit d8b4e0e

Please sign in to comment.