Passed
Push — task/change-application-deadli... ( 874c98...5f73bf )
by
unknown
07:44
created

JobPosterTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 18
dl 0
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testJobPosterApplyBy() 0 5 1
A testJobPosterIsOpen() 0 10 1
A testJobPosterTimeRemaining() 0 16 1
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
use Illuminate\Support\Facades\Lang;
9
use Jenssegers\Date\Date;
10
11
use App\Models\JobPoster;
12
use Doctrine\Common\Cache\VoidCache;
13
14
class JobPosterTest extends TestCase
15
{
16
    use WithFaker;
17
18
    /**
19
     * Test that JobPoster->isOpen() behaves properly
20
     *
21
     * @return void
22
     */
23
    public function testJobPosterIsOpen() : void
24
    {
25
        $jobPoster = factory(JobPoster::class)->states('published')->make();
26
        $this->assertTrue($jobPoster->isOpen());
27
28
        $jobPoster->close_date_time = $this->faker->dateTimeBetween('-1 weeks', 'now');
29
        $this->assertFalse($jobPoster->isOpen());
30
31
        $jobPoster = factory(JobPoster::class)->states('unpublished')->make();
32
        $this->assertFalse($jobPoster->isOpen());
33
    }
34
35
    /**
36
     * Test that JobPoster->timeRemaining() behaves properly
37
     *
38
     * @return void
39
     */
40
    public function testJobPosterTimeRemaining() : void
41
    {
42
        $jobPoster = factory(JobPoster::class)->make(
43
            [
44
                'close_date_time' => date('Y-m-d H:i:s', strtotime('-1 hour'))
45
            ]
46
        );
47
        $this->assertEquals(Lang::choice('common/time.hour', 1), $jobPoster->timeRemaining());
48
49
        $jobPoster = factory(JobPoster::class)->make(
50
            [
51
                'close_date_time' => date('Y-m-d H:i:s', strtotime('-2 days'))
52
            ]
53
        );
54
        $langString = Lang::choice('common/time.day', 2);
55
        $this->assertEquals($langString, $jobPoster->timeRemaining());
56
    }
57
58
    /**
59
     * Test that JobPoster->applyBy() behaves properly
60
     *
61
     * @return void
62
     */
63
    public function testJobPosterApplyBy() : void
64
    {
65
        $jobPoster = factory(JobPoster::class)->make();
66
        $date = new Date($jobPoster->close_date_time, JobPoster::TIMEZONE);
0 ignored issues
show
Bug introduced by
It seems like $jobPoster->close_date_time can also be of type Illuminate\Database\Eloq...uent\Relations\Relation and Illuminate\Database\Eloquent\Relations\Relation; however, parameter $time of Jenssegers\Date\Date::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
        $date = new Date(/** @scrutinizer ignore-type */ $jobPoster->close_date_time, JobPoster::TIMEZONE);
Loading history...
67
        $this->assertEquals($date->format('F jS, Y, gA T'), $jobPoster->applyBy());
68
    }
69
}
70