-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29c159e
commit 9b18bb3
Showing
4 changed files
with
101 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Tests\Setup; | ||
|
||
use App\Project; | ||
use App\Task; | ||
use App\User; | ||
|
||
class ProjectFactory | ||
{ | ||
/** | ||
* The number of tasks for the project. | ||
* | ||
* @var int | ||
*/ | ||
protected $tasksCount = 0; | ||
|
||
/** | ||
* The owner of the project. | ||
* | ||
* @var User | ||
*/ | ||
protected $user; | ||
|
||
/** | ||
* Set the number of tasks to create for the project. | ||
* | ||
* @param int $count | ||
* @return $this | ||
*/ | ||
public function withTasks($count) | ||
{ | ||
$this->tasksCount = $count; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Set the owner of the new project. | ||
* | ||
* @param User $user | ||
* @return $this | ||
*/ | ||
public function ownedBy($user) | ||
{ | ||
$this->user = $user; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Arrange the world. | ||
* | ||
* @return Project | ||
*/ | ||
public function create() | ||
{ | ||
$project = factory(Project::class)->create([ | ||
'owner_id' => $this->user ?? factory(User::class) | ||
]); | ||
|
||
factory(Task::class, $this->tasksCount)->create([ | ||
'project_id' => $project | ||
]); | ||
|
||
return $project; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters