Completed
Pull Request — master (#13)
by Vojta
06:35
created

ReservationTest::testIsExistsInLastTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php namespace VojtaSvoboda\Reservations\Tests\Models;
2
3
use App;
4
use Config;
5
use PluginTestCase;
6
use VojtaSvoboda\Reservations\Models\Reservation;
7
use VojtaSvoboda\Reservations\Models\Status;
8
9
class ReservationTest extends PluginTestCase
10
{
11
    /**
12
     * Get tested model.
13
     *
14
     * @return Reservation
15
     */
16
    public function getModel()
17
    {
18
        return App::make(Reservation::class);
19
    }
20
21
    public function testGetHash()
22
    {
23
        $model = $this->getModel();
24
25
        $firstHash = $model->getUniqueHash();
26
        $secondHash = $model->getUniqueHash();
27
28
        $this->assertNotEquals($firstHash, $secondHash);
29
    }
30
31
    public function testGetNumber()
32
    {
33
        $model = $this->getModel();
34
35
        $firstNumber = $model->getUniqueNumber();
36
        $secondNumber = $model->getUniqueNumber();
37
38
        $this->assertNotEquals($firstNumber, $secondNumber);
39
    }
40
41
    public function testScopeNotCancelled()
42
    {
43
        $model = $this->getModel();
44
45
        // create reservation
46
        $reservation = $model->create($this->getTestingReservationData());
47
        $reservations = $model->notCancelled()->get();
48
        $this->assertNotEmpty($reservations);
49
50
        // change reservation to cancelled
51
        $reservation->status = Status::where('ident', 'cancelled')->first();
52
        $reservation->save();
53
        $reservations = $model->notCancelled()->get();
54
        $this->assertEmpty($reservations);
55
    }
56
57 View Code Duplication
    private function getTestingReservationData($statusIdent = 'received')
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        return [
60
            'date' => '2016-08-18 20:00',
61
            'email' => '[email protected]',
62
            'phone' => '777111222',
63
            'street' => 'ABCDE',
64
            'name' => 'Vojta Svoboda',
65
            'message' => 'Hello.',
66
            'status' => Status::where('ident', $statusIdent)->first(),
67
        ];
68
    }
69
}
70