Test Setup Failed
Pull Request — master (#42)
by Matthew
03:35
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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A testEnsuresSportIsNotEmpty() 13 13 1
A testDraftIdAndSecondsArePresent() 0 17 1
A testValidateSportValues() 13 13 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
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() {
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...
10
    $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...
11
    $draftDataRepository = new DraftDataRepository($this->app);
12
    $this->sut = new ProPlayerValidator($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...
13
    $this->app['phpdraft.DraftDataRepository'] = $draftDataRepository;
14
15
    $this->uploadedFileClass = 'Symfony\Component\HttpFoundation\File\UploadedFile';
0 ignored issues
show
Bug introduced by
The property uploadedFileClass 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...
16
  }
17
18 View Code Duplication
  public function testEnsuresSportIsNotEmpty() {
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...
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 View Code Duplication
  public function testValidateSportValues() {
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...
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
}