Completed
Push — feature/manager_localization2 ( de29b5...0f36f8 )
by Xander
16:57 queued 09:59
created

JobPolicyTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 27
c 0
b 0
f 0
dl 0
loc 84
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A policy() 0 3 1
A testManagerCanViewOwnUnpublishedJob() 0 6 1
A testAnyoneCanViewOpenJob() 0 6 1
A testNoOneCanViewUnpublishedJob() 0 6 1
A setUp() 0 8 1
A testAnyoneCanViewClosedJob() 0 6 1
1
<?php
2
3
namespace Tests\Unit\Policies;
4
5
use Tests\TestCase;
6
use Illuminate\Foundation\Testing\WithFaker;
7
use Illuminate\Foundation\Testing\RefreshDatabase;
8
9
use App\Policies\JobPolicy;
10
use App\Models\JobPoster;
11
use App\Models\User;
12
use App\Models\Applicant;
13
use App\Models\Manager;
14
15
class JobPolicyTest extends TestCase
16
{
17
18
    use RefreshDatabase;
0 ignored issues
show
introduced by
The trait Illuminate\Foundation\Testing\RefreshDatabase requires some properties which are not provided by Tests\Unit\Policies\JobPolicyTest: $connectionsToTransact, $dropViews
Loading history...
19
20
    /**
21
     * policy for use in tests
22
     *
23
     * @var \App\Models\JobPolicy
24
     */
25
    protected $policy;
26
27
    /**
28
     * Manager user for use in tests
29
     *
30
     * @var \App\Models\User
31
     */
32
    protected $manager;
33
34
    /**
35
     * Applicant user for use in tests
36
     *
37
     * @var \App\Models\User
38
     */
39
    protected $applicant;
40
41
    /**
42
     * Guest user (null) for use in test
43
     *
44
     * @var null
45
     */
46
    protected $guest;
47
48
    /**
49
     * Run parent setup and provide reusable factories.
50
     *
51
     * @return void
52
     */
53
    protected function setUp()
54
    {
55
        parent::setUp();
56
57
        $this->policy = new JobPolicy();
0 ignored issues
show
Documentation Bug introduced by
It seems like new App\Policies\JobPolicy() of type App\Policies\JobPolicy is incompatible with the declared type App\Models\JobPolicy of property $policy.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
58
        $this->manager = factory(Manager::class)->create()->user;
59
        $this->applicant = factory(Applicant::class)->create()->user;
60
        $this->guest = null;
61
    }
62
63
64
    protected function policy()
65
    {
66
        return new JobPolicy();
67
    }
68
69
    public function testAnyoneCanViewOpenJob()
70
    {
71
        $job = factory(JobPoster::class)->states('published')->make();
72
        $this->assertTrue($this->policy->view($this->guest, $job));
73
        $this->assertTrue($this->policy->view($this->applicant, $job));
74
        $this->assertTrue($this->policy->view($this->manager, $job));
75
    }
76
77
    public function testAnyoneCanViewClosedJob()
78
    {
79
        $job = factory(JobPoster::class)->states('closed')->make();
80
        $this->assertTrue($this->policy->view($this->guest, $job));
81
        $this->assertTrue($this->policy->view($this->applicant, $job));
82
        $this->assertTrue($this->policy->view($this->manager, $job));
83
    }
84
85
    public function testNoOneCanViewUnpublishedJob()
86
    {
87
        $job = factory(JobPoster::class)->states('unpublished')->make();
88
        $this->assertFalse($this->policy->view($this->guest, $job));
89
        $this->assertFalse($this->policy->view($this->applicant, $job));
90
        $this->assertFalse($this->policy->view($this->manager, $job));
91
    }
92
93
    public function testManagerCanViewOwnUnpublishedJob()
94
    {
95
        $job = factory(JobPoster::class)->states('unpublished')->make([
96
            'manager_id' => $this->manager->manager->id
97
        ]);
98
        $this->assertTrue($this->policy->view($this->manager, $job));
99
    }
100
}
101