Passed
Push — allow-managers-to-edit-job-pos... ( 64dabc...bb1d32 )
by
unknown
07:28
created

JobPosterTest::testJobPosterTimeRemaining()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 16
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
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(\App\Models\JobPoster::class)->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(\App\Models\JobPoster::class)->make(
30
            [
31
                'published' => false
32
            ]
33
        );
34
        $this->assertFalse($jobPoster->isOpen());
35
    }
36
37
    /**
38
     * Test that JobPoster->timeRemaining() behaves properly
39
     *
40
     * @return void
41
     */
42
    public function testJobPosterTimeRemaining()
43
    {
44
        $jobPoster = factory(\App\Models\JobPoster::class)->make(
45
            [
46
                'close_date_time' => date('Y-m-d H:i:s', strtotime('-1 hour'))
47
            ]
48
        );
49
        $this->assertEquals(Lang::choice('common/time.hour', 1), $jobPoster->timeRemaining());
50
51
        $jobPoster = factory(\App\Models\JobPoster::class)->make(
52
            [
53
                'close_date_time' => date('Y-m-d H:i:s', strtotime('-2 days'))
54
            ]
55
        );
56
        $langString = Lang::choice('common/time.day', 2);
57
        $this->assertEquals($langString, $jobPoster->timeRemaining());
58
    }
59
}
60