1
|
|
|
<?php |
2
|
|
|
namespace PhpDraft\Test; |
3
|
|
|
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
use PhpDraft\Domain\Entities\Draft; |
6
|
|
|
use PhpDraft\Domain\Entities\Pick; |
7
|
|
|
use PhpDraft\Domain\Validators\PickValidator; |
8
|
|
|
use PhpDraft\Domain\Repositories\DraftDataRepository; |
9
|
|
|
use PhpDraft\Domain\Models\PhpDraftResponse; |
10
|
|
|
|
11
|
|
|
class PickValidatorTest extends TestCase { |
12
|
|
|
function setUp() { |
13
|
|
|
$this->app = require dirname(__FILE__).'/../../../../api/config/_app.php'; |
14
|
|
|
$draftDataRepository = new DraftDataRepository($this->app); |
15
|
|
|
$this->app['phpdraft.DraftDataRepository'] = $draftDataRepository; |
16
|
|
|
$this->sut = new PickValidator($this->app); |
17
|
|
|
|
18
|
|
|
$this->draft = new Draft(); |
19
|
|
|
$this->draft->draft_sport = "NFL"; |
20
|
|
|
|
21
|
|
|
$this->pick = new Pick(); |
22
|
|
|
$this->pick->first_name = "Antonio"; |
23
|
|
|
$this->pick->last_name = "Brown"; |
24
|
|
|
$this->pick->team = "PIT"; |
25
|
|
|
$this->pick->position = "WR"; |
26
|
|
|
|
27
|
|
|
//TODO: How to not re-create this simple wheel? |
28
|
|
|
$this->app['phpdraft.ResponseFactory'] = function() { |
29
|
|
|
return function($success, $errors) { |
30
|
|
|
return new PhpDraftResponse($success, $errors); |
31
|
|
|
}; |
32
|
|
|
}; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testEnsuresFieldsArentEmptyOnAdd() { |
36
|
|
|
$this->pick->first_name = ""; |
37
|
|
|
|
38
|
|
|
$result = $this->sut->IsPickValidForAdd($this->draft, $this->pick); |
39
|
|
|
|
40
|
|
|
$this->assertFalse($result->success); |
41
|
|
|
$this->assertContains("One or more missing fields.", $result->errors); |
42
|
|
|
|
43
|
|
|
$this->pick->first_name = "Antonio"; |
44
|
|
|
$this->pick->last_name = ""; |
45
|
|
|
|
46
|
|
|
$result = $this->sut->IsPickValidForAdd($this->draft, $this->pick); |
47
|
|
|
|
48
|
|
|
$this->assertFalse($result->success); |
49
|
|
|
$this->assertContains("One or more missing fields.", $result->errors); |
50
|
|
|
|
51
|
|
|
$this->pick->last_name = "Brown"; |
52
|
|
|
$this->pick->team = ""; |
53
|
|
|
|
54
|
|
|
$result = $this->sut->IsPickValidForAdd($this->draft, $this->pick); |
55
|
|
|
|
56
|
|
|
$this->assertFalse($result->success); |
57
|
|
|
$this->assertContains("One or more missing fields.", $result->errors); |
58
|
|
|
|
59
|
|
|
$this->pick->team = "PIT"; |
60
|
|
|
$this->pick->position = ""; |
61
|
|
|
|
62
|
|
|
$result = $this->sut->IsPickValidForAdd($this->draft, $this->pick); |
63
|
|
|
|
64
|
|
|
$this->assertFalse($result->success); |
65
|
|
|
$this->assertContains("One or more missing fields.", $result->errors); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testDraftIdMatchesOnAdd() { |
69
|
|
|
$this->draft->draft_id = 1; |
70
|
|
|
$this->pick->draft_id = 2; |
71
|
|
|
|
72
|
|
|
$result = $this->sut->IsPickValidForAdd($this->draft, $this->pick); |
73
|
|
|
|
74
|
|
|
$this->assertFalse($result->success); |
75
|
|
|
$this->assertContains("Pick does not belong to draft #1.", $result->errors); |
76
|
|
|
} |
77
|
|
|
} |