Skip to content

Instantly share code, notes, and snippets.

@petersuhm
Created February 19, 2013 16:23
Show Gist options
  • Save petersuhm/4987406 to your computer and use it in GitHub Desktop.
Save petersuhm/4987406 to your computer and use it in GitHub Desktop.
Simple Laravel 4 integration test, for testing a todo list application.
<?php
class TodoItemTest extends TestCase {
public function testCreateTodoItem()
{
// Visit create action and get crawler instance
$crawler = $this->client->request('GET', '/todo-items/create');
// Check that request returned 200
$this->assertTrue($this->client->getResponse()->isOk());
// Use selectButton to grap form element and fill in the task input
$form = $crawler->selectButton('submit')->form(array(
'task' => 'Test Task'
));
// Submit the form
$this->client->request(
$form->getMethod(),
$form->getUri(),
$form->getValues()
);
// Follow redirect to index action and get new crawler instance
$crawler = $this->client->followRedirect();
// Check that redirect returned 200
$this->assertTrue($this->client->getResponse()->isOk());
// Check that the new todo item is present
$this->assertCount(1, $crawler->filter('li:contains("Test Task")'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment