Passed
Push — master ( 193348...182172 )
by Matthew
04:45
created

ProPlayerValidatorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 46.43 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 26
loc 56
rs 10
c 0
b 0
f 0

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
2
namespace PhpDraft\Test;
3
4
use PHPUnit\Framework\TestCase;
5
use PhpDraft\Domain\Validators\ProPlayerValidator;
6
use PhpDraft\Domain\Repositories\DraftDataRepository;
7
8
class ProPlayerValidatorTest extends TestCase {
9
  function setUp() {
10
    $this->app = require dirname(__FILE__).'/../../../../api/config/_app.php';
11
    $draftDataRepository = new DraftDataRepository($this->app);
12
    $this->sut = new ProPlayerValidator($this->app);
13
    $this->app['phpdraft.DraftDataRepository'] = $draftDataRepository;
14
15
    $this->uploadedFileClass = 'Symfony\Component\HttpFoundation\File\UploadedFile';
16
  }
17
18
  public function testEnsuresSportIsNotEmpty() {
19
    $mockFile = $this->getMockBuilder($this->uploadedFileClass)
20
                    ->enableOriginalConstructor()
21
                    ->setConstructorArgs([tempnam(sys_get_temp_dir(), ''), 'dummy'])
22
                    ->getMock();
23
24
    $sport = "";
25
26
    $result = $this->sut->IsUploadSportValid($sport, $mockFile);
27
28
    $this->assertFalse($result->success);
29
    $this->assertContains("One or more missing fields.", $result->errors);
30
  }
31
32
  public function testDraftIdAndSecondsArePresent() {
33
    $mockFile = $this->getMockBuilder($this->uploadedFileClass)
34
                    ->enableOriginalConstructor()
35
                    ->setConstructorArgs([tempnam(sys_get_temp_dir(), ''), 'dummy'])
36
                    ->getMock();
37
38
    $mockFile->expects($this->once())
39
        ->method('getError')
40
        ->will($this->returnValue(1));
41
42
    $sport = "NFL";
43
44
    $result = $this->sut->IsUploadSportValid($sport, $mockFile);
45
46
    $this->assertFalse($result->success);
47
    $this->assertContains("Upload error - 1", $result->errors);
48
  }
49
50
  public function testValidateSportValues() {
51
    $mockFile = $this->getMockBuilder($this->uploadedFileClass)
52
                    ->enableOriginalConstructor()
53
                    ->setConstructorArgs([tempnam(sys_get_temp_dir(), ''), 'dummy'])
54
                    ->getMock();
55
56
    $sport = "QVC";
57
58
    $result = $this->sut->IsUploadSportValid($sport, $mockFile);
59
60
    $this->assertFalse($result->success);
61
    $this->assertContains("Sport QVC is an invalid value.", $result->errors);
62
  }
63
}