Permalink
Browse files

Refactor web tests too have setUp

  • Loading branch information...
1 parent fd8ce0c commit c35ee08bd0fbe49d6b4af9538273e7dc22ed3ce4 @igorw committed Apr 3, 2013
Showing with 29 additions and 32 deletions.
  1. +29 −32 tests/functional/WebTest.php
@@ -5,6 +5,8 @@
class WebTest extends WebTestCase
{
+ private $client;
+
public function createApplication()
{
$app = require __DIR__.'/../../src/app.php';
@@ -20,12 +22,17 @@ public function createApplication()
return $app;
}
- public function testRoot()
+ public function setUp()
{
- $client = $this->createClient();
+ parent::setUp();
- $client->request('GET', '/');
- $response = $client->getResponse();
+ $this->client = $this->createClient();
+ }
+
+ public function testRoot()
+ {
+ $this->client->request('GET', '/');
+ $response = $this->client->getResponse();
$this->assertTrue($response->isOk(), '/ should return ok response');
$this->assertContains('trashbin', $response->getContent());
$this->assertContains('simple pastebin', $response->getContent());
@@ -35,55 +42,49 @@ public function testRoot()
public function testCreatePaste()
{
- $client = $this->createClient();
- $client->setServerParameters(array('REQUEST_TIME' => 1337882841));
+ $this->client->setServerParameters(array('REQUEST_TIME' => 1337882841));
- $crawler = $client->request('GET', '/');
+ $crawler = $this->client->request('GET', '/');
$form = $crawler->filter('form')->form();
$form['content'] = 'foobar';
- $crawler = $client->submit($form);
- $crawler = $client->followRedirect();
+ $crawler = $this->client->submit($form);
+ $crawler = $this->client->followRedirect();
- $response = $client->getResponse();
+ $response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertContains('foobar', $response->getContent());
}
/** @test */
public function createPasteWithoutContentShouldFail()
{
- $client = $this->createClient();
-
- $crawler = $client->request('GET', '/');
+ $crawler = $this->client->request('GET', '/');
$form = $crawler->filter('form')->form();
$form['content'] = '';
- $client->submit($form);
+ $this->client->submit($form);
- $response = $client->getResponse();
+ $response = $this->client->getResponse();
$this->assertSame(400, $response->getStatusCode());
}
public function testViewPaste()
{
- $client = $this->createClient();
-
- $client->request('GET', '/abcdef12');
- $response = $client->getResponse();
+ $this->client->request('GET', '/abcdef12');
+ $response = $this->client->getResponse();
$this->assertTrue($response->isOk());
$this->assertContains('foobar', $response->getContent());
}
public function testCreatePasteWithParent()
{
- $client = $this->createClient();
- $crawler = $client->request('GET', '/abcdef12');
+ $crawler = $this->client->request('GET', '/abcdef12');
$link = $crawler->selectLink('copy')->link();
- $crawler = $client->click($link);
+ $crawler = $this->client->click($link);
$form = $crawler->filter('form')->form();
$this->assertSame('foobar', $form['content']->getValue());
@@ -95,17 +96,13 @@ public function testCreatePasteWithParent()
*/
public function testViewPasteWithInvalidId()
{
- $client = $this->createClient();
-
- $client->request('GET', '/00000000');
+ $this->client->request('GET', '/00000000');
}
public function testAbout()
{
- $client = $this->createClient();
-
- $client->request('GET', '/about');
- $response = $client->getResponse();
+ $this->client->request('GET', '/about');
+ $response = $this->client->getResponse();
$this->assertTrue($response->isOk(), '/about should return ok response');
$this->assertContains('trashbin', $response->getContent());
$this->assertContains('github', $response->getContent());
@@ -116,10 +113,10 @@ public function testErrorHandler()
{
$this->app['debug'] = false;
- $client = $this->createClient();
+ $this->client = $this->createClient();
- $client->request('GET', '/non-existent');
- $response = $client->getResponse();
+ $this->client->request('GET', '/non-existent');
+ $response = $this->client->getResponse();
$this->assertSame(404, $response->getStatusCode());
}
}

0 comments on commit c35ee08

Please sign in to comment.