Completed
Push — master ( fb8886...624979 )
by Matthew
9s
created

testRoundTimeSecondsArePositiveNumbers()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 18

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
dl 24
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
namespace PhpDraft\Test;
3
4
use PHPUnit\Framework\TestCase;
5
use \PhpDraft\Domain\Entities\RoundTime;
6
use PhpDraft\Domain\Validators\RoundTimeValidator;
7
use PhpDraft\Domain\Models\RoundTimeCreateModel;
8
9
class RoundTimeValidatorTest extends TestCase {
10
  function setUp() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
11
    $this->app = require dirname(__FILE__).'/../../../../api/config/_app.php';
0 ignored issues
show
Bug introduced by
The property app does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
12
    $this->roundTimeCreateModel = new RoundTimeCreateModel();
0 ignored issues
show
Bug introduced by
The property roundTimeCreateModel does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
13
    $this->sut = new RoundTimeValidator($this->app);
0 ignored issues
show
Bug introduced by
The property sut does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
14
  }
15
16
  public function testPassesValidationIfTimersAreDisabled() {
17
    $this->roundTimeCreateModel->isRoundTimesEnabled = false;
18
19
    $result = $this->sut->AreRoundTimesValid($this->roundTimeCreateModel);
20
21
    $this->assertTrue($result->success);
22
  }
23
24
  public function testDraftIdAndSecondsArePresent() {
25
    $this->roundTimeCreateModel->isRoundTimesEnabled = true;
26
27
    $roundTime1 = new RoundTime();
28
    $roundTime1->draft_id = 1;
29
    $roundTime1->is_static_time = false;
30
    $roundTime1->draft_round = 1;
31
32
    $roundTime2 = new RoundTime();
33
    $roundTime2->round_time_seconds = 7;
34
    $roundTime2->is_static_time = false;
35
    $roundTime2->draft_round = 1;
36
37
    $this->roundTimeCreateModel->roundTimes[] = $roundTime1;
38
    $this->roundTimeCreateModel->roundTimes[] = $roundTime2;
39
40
    $result = $this->sut->AreRoundTimesValid($this->roundTimeCreateModel);
41
42
    $this->assertFalse($result->success);
43
    $this->assertContains("Round time #2 has one or more missing fields.", $result->errors);
44
    $this->assertContains("Round time #1 has one or more missing fields.", $result->errors);
45
  }
46
47 View Code Duplication
  public function testRoundTimeSecondsArePositiveNumbers() {
0 ignored issues
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...
48
    $this->roundTimeCreateModel->isRoundTimesEnabled = true;
49
50
    $roundTime1 = new RoundTime();
51
    $roundTime1->draft_id = 1;
52
    $roundTime1->round_time_seconds = -5;
53
    $roundTime1->is_static_time = false;
54
    $roundTime1->draft_round = 1;
55
56
    $roundTime2 = new RoundTime();
57
    $roundTime2->draft_id = 1;
58
    $roundTime2->round_time_seconds = "q";
0 ignored issues
show
Documentation Bug introduced by
The property $round_time_seconds was declared of type integer, but 'q' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
59
    $roundTime2->is_static_time = false;
60
    $roundTime2->draft_round = 1;
61
62
    $this->roundTimeCreateModel->roundTimes[] = $roundTime1;
63
    $this->roundTimeCreateModel->roundTimes[] = $roundTime2;
64
65
    $result = $this->sut->AreRoundTimesValid($this->roundTimeCreateModel);
66
67
    $this->assertFalse($result->success);
68
    $this->assertContains("Round time #1 must have 1 or more seconds specified.", $result->errors);
69
    $this->assertContains("Round time #2 must have 1 or more seconds specified.", $result->errors);
70
  }
71
72 View Code Duplication
  public function testEnsureRoundNumberIsCorrect() {
0 ignored issues
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...
73
    $this->roundTimeCreateModel->isRoundTimesEnabled = true;
74
75
    $roundTime1 = new RoundTime();
76
    $roundTime1->draft_id = 1;
77
    $roundTime1->round_time_seconds = -5;
78
    $roundTime1->is_static_time = false;
79
    $roundTime1->draft_round = 0;
80
81
    $roundTime2 = new RoundTime();
82
    $roundTime2->draft_id = 1;
83
    $roundTime2->round_time_seconds = "q";
0 ignored issues
show
Documentation Bug introduced by
The property $round_time_seconds was declared of type integer, but 'q' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
84
    $roundTime2->is_static_time = false;
85
    $roundTime2->draft_round = 31;
86
87
    $this->roundTimeCreateModel->roundTimes[] = $roundTime1;
88
    $this->roundTimeCreateModel->roundTimes[] = $roundTime2;
89
90
    $result = $this->sut->AreRoundTimesValid($this->roundTimeCreateModel);
91
92
    $this->assertFalse($result->success);
93
    $this->assertContains("Round time #1 cannot have a round less than 1 or greater than 30.", $result->errors);
94
    $this->assertContains("Round time #2 cannot have a round less than 1 or greater than 30.", $result->errors);
95
  }
96
}