Skip to content

Commit 176c2d4

Browse files
committed
Add FakesData trait to tests
This will allow us to easily use mocked data in our tests.
1 parent 8b741ba commit 176c2d4

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

tests/FakesData.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Faker\Factory;
6+
7+
trait FakesData
8+
{
9+
/**
10+
* @var \Faker\Generator
11+
*/
12+
public $faker;
13+
14+
/**
15+
* @before
16+
*/
17+
public function setupFaker()
18+
{
19+
$this->faker = Factory::create();
20+
}
21+
22+
/**
23+
* @after
24+
*/
25+
public function unsetFaker()
26+
{
27+
$this->faker = null;
28+
}
29+
}

tests/Feature/SubscriptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function users_receive_notifications_for_new_replies_to_threads_where_the
2525
factory(Subscription::class)->create(['user_id' => $userOne->id(), 'subscriptionable_id' => $thread->id()]);
2626
factory(Subscription::class)->create(['user_id' => $userTwo->id(), 'subscriptionable_id' => $thread->id()]);
2727

28-
$this->dispatch(new CreateReply('Foo', 'Bar', $author, $thread));
28+
$this->dispatch(new CreateReply($this->faker->text, $this->faker->ipv4, $author, $thread));
2929

3030
Notification::assertSentTo([$userOne, $userTwo], NewReply::class);
3131
}

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
abstract class TestCase extends IlluminateTestCase
88
{
9-
use CreatesApplication, CreatesUsers, HttpAssertions;
9+
use CreatesApplication, CreatesUsers, FakesData, HttpAssertions;
1010

1111
protected function dispatch($job)
1212
{

0 commit comments

Comments
 (0)