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

ReservationTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 19.67 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 12
loc 61
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getModel() 0 4 1
A testGetHash() 0 9 1
A testGetNumber() 0 9 1
A getTestingReservationData() 12 12 1
A testScopeNotCancelled() 0 15 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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