Completed
Push — feature/policy_unit_tests ( 0c0d69...c4da13 )
by Grant
27:23 queued 19:01
created

BasePolicyTest::makeManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\Unit;
4
5
use Tests\TestCase;
6
use Illuminate\Foundation\Testing\WithFaker;
7
use Illuminate\Foundation\Testing\RefreshDatabase;
8
9
use App\Models\User;
10
use App\Models\Applicant;
11
use App\Models\Manager;
12
use App\Models\UserRole;
13
use App\Policies\ManagerPolicy;
14
15
/**
16
 * A base class for Policy tests
17
 */
18
abstract class BasePolicyTest extends TestCase
19
{
20
21
    protected $nextId = 1;
22
23
    protected function makeId() {
24
        $id = $this->nextId;
25
        $this->nextId = $this->nextId + 1;
26
        return $id;
27
    }
28
29
    protected function makeApplicant() {
30
        //New applicants get a new user
31
        $user =  User::make();
32
        $user->id = $this->makeId();
33
        // Make user an Applicant
34
        $user->user_role()->associate(
35
            UserRole::where('name', 'applicant')->firstOrFail());
36
37
        $userApplicant = new Applicant();
38
        $userApplicant->id = $this->makeId();
39
        $userApplicant->user()->associate($user);
40
41
        return $userApplicant;
42
    }
43
44
    protected function makeManager() {
45
        //New managers get a new user
46
        $user =  User::make();
47
        $user->id = $this->makeId();
48
        // Make user a manager
49
        $user->user_role()->associate(
50
            UserRole::where('name', 'manager')->firstOrFail());
51
52
        $userManager = new Manager();
53
        $userManager->id = $this->makeId();
54
        $userManager->user()->associate($user);
55
56
        return $userManager;
57
    }
58
59
    //makeManager(), comes with a user
60
61
    //makeJob($manager) {}
62
63
    //makeApplication($applicant, $job) {}
64
}
65