Completed
Push — feature/policy_unit_tests ( 0404ac...6499e2 )
by
unknown
07:31
created

BasePolicyTest::makeJob()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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\ApplicantPolicy;
14
use App\Policies\ManagerPolicy;
15
16
/**
17
 * A base class for Policy tests
18
 */
19
abstract class BasePolicyTest extends TestCase
20
{
21
22
    protected $nextId = 1;
23
24
    protected function makeId() {
25
        $id = $this->nextId;
26
        $this->nextId = $this->nextId + 1;
27
        return $id;
28
    }
29
30
    protected function makeApplicant() {
31
        //New applicants get a new user
32
        $user =  User::make();
33
        $user->id = $this->makeId();
34
        // Make user an Applicant
35
        $user->user_role()->associate(
36
            UserRole::where('name', 'applicant')->firstOrFail());
37
38
        $userApplicant = new Applicant();
39
        $userApplicant->id = $this->makeId();
40
        $userApplicant->user()->associate($user);
41
42
        return $userApplicant;
43
    }
44
45
    protected function makeManager() {
46
        //New managers get a new user
47
        $user = User::make();
48
        $user->id = $this->makeId();
49
        // Make user a manager
50
        $user->user_role()->associate(
51
            UserRole::where('name', 'manager')->firstOrFail());
52
53
        $userManager = new Manager();
54
        $userManager->id = $this->makeId();
55
        $userManager->user()->associate($user);
56
57
        return $userManager;
58
    }
59
60
61
62
    protected function makeJobPoster() {
63
        $jobPoster = JobPoster::make();
0 ignored issues
show
Unused Code introduced by
The assignment to $jobPoster is dead and can be removed.
Loading history...
64
    }
65
66
    //makeManager(), comes with a user
67
68
    //makeJob($manager) {} Also look to Create a job on the base policy and test to see if the user can access it. 11/27/2018
69
    protected function makeJob() {
70
        $job = Job::make();
71
        $job->id = $this->makeId();
72
        
73
        //Test to see if userApplicant can access the job
74
      
75
        $userApplicant = new Applicant();
76
        $userApplicant->id = $this->makeId();
77
        $userApplicant->user()->associate($job);
78
        
79
        return $userApplicant; 
80
    }
81
    
82
    
83
    
84
    //makeManager(), comes with a user
85
86
    //makeApplication($applicant, $job) {}
87
}
88