Skip to content

Instantly share code, notes, and snippets.

@laracasts
Last active July 10, 2018 16:33
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save laracasts/8161725 to your computer and use it in GitHub Desktop.
Save laracasts/8161725 to your computer and use it in GitHub Desktop.
Transactions for functional/integration tests.
<?php
class ExampleTest extends TestCase {
public function setUp()
{
parent::setUp();
DB::beginTransaction();
}
/**
* A basic functional test example.
*
* @return void
*/
public function testShowsPosts()
{
$title = 'Yay Great Post';
// "Create" post
Post::create(compact('title'));
$crawler = $this->client->request('GET', 'posts');
$this->assertEquals(
1,
count($crawler->filter("body:contains('{$title}')")),
"Expected to see the text '{$title}' within a body element."
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment