Completed
Push — feature/screening-plan ( 46ccc1...3f87fd )
by Tristan
14:07 queued 07:47
created

JobPosterTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 15
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
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
10
use App\Models\JobPoster;
11
12
class JobPosterTest extends TestCase
13
{
14
    use WithFaker;
15
16
    /**
17
     * Test that JobPoster->isOpen() behaves properly
18
     *
19
     * @return void
20
     */
21
    public function testJobPosterIsOpen()
22
    {
23
        $jobPoster = factory(JobPoster::class)->states('published')->make();
24
        $this->assertTrue($jobPoster->isOpen());
0 ignored issues
show
Bug introduced by
It seems like $jobPoster->isOpen() can also be of type Illuminate\Database\Eloquent\Builder; however, parameter $condition of PHPUnit\Framework\Assert::assertTrue() does only seem to accept boolean, 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

24
        $this->assertTrue(/** @scrutinizer ignore-type */ $jobPoster->isOpen());
Loading history...
25
26
        $jobPoster->close_date_time = $this->faker->dateTimeBetween('-1 weeks', 'now');
27
        $this->assertFalse($jobPoster->isOpen());
0 ignored issues
show
Bug introduced by
It seems like $jobPoster->isOpen() can also be of type Illuminate\Database\Eloquent\Builder; however, parameter $condition of PHPUnit\Framework\Assert::assertFalse() does only seem to accept boolean, 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

27
        $this->assertFalse(/** @scrutinizer ignore-type */ $jobPoster->isOpen());
Loading history...
28
29
        $jobPoster = factory(JobPoster::class)->states('unpublished')->make();
30
        $this->assertFalse($jobPoster->isOpen());
31
    }
32
33
    /**
34
     * Test that JobPoster->timeRemaining() behaves properly
35
     *
36
     * @return void
37
     */
38
    public function testJobPosterTimeRemaining()
39
    {
40
        $jobPoster = factory(JobPoster::class)->make(
41
            [
42
                'close_date_time' => date('Y-m-d H:i:s', strtotime('-1 hour'))
43
            ]
44
        );
45
        $this->assertEquals(Lang::choice('common/time.hour', 1), $jobPoster->timeRemaining());
46
47
        $jobPoster = factory(JobPoster::class)->make(
48
            [
49
                'close_date_time' => date('Y-m-d H:i:s', strtotime('-2 days'))
50
            ]
51
        );
52
        $langString = Lang::choice('common/time.day', 2);
53
        $this->assertEquals($langString, $jobPoster->timeRemaining());
54
    }
55
}
56