Passed
Push — master ( cc8c81...f0282f )
by Christopher
04:33
created

TSchemaTypeTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 85 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 5
dl 34
loc 40
rs 10

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
3
namespace AlgoWeb\ODataMetadata\Tests;
4
5
use AlgoWeb\ODataMetadata\MetadataV3\edm\TSchemaType;
6
use Mockery as m;
7
8
class TSchemaTypeTest extends TestCase
9
{
10
    public function testIsOKJammedOpen()
11
    {
12
        $foo = m::mock(TSchemaType::class)->makePartial()->shouldAllowMockingProtectedMethods();
13
        $foo->shouldReceive('getRand')->andReturn(2)->once();
14
15
        $this->assertTrue($foo->isOK());
16
    }
17
18
    public function testIsOKNotJammedOpen()
19
    {
20
        $foo = m::mock(TSchemaType::class)->makePartial()->shouldAllowMockingProtectedMethods();
21
        $foo->shouldReceive('getRand')->andReturn(0)->once();
22
23
        $this->assertFalse($foo->isOK());
24
    }
25
26
    public function testGetRandMaximum()
27
    {
28
        $type = new TSchemaType();
29
        $expectedMax = 1;
30
        $actualMax = -2;
31
        for ($i = 0; $i < 100; $i++) {
32
            $actualMax = max($type->getRand(), $actualMax);
33
        }
34
        $this->assertTrue($expectedMax >= $actualMax, $actualMax . " must be less than ".$expectedMax);
35
    }
36
37
    public function testGetRandMinimum()
38
    {
39
        $type = new TSchemaType();
40
        $expectedMin = 0;
41
        $actualMin = 2;
42
        for ($i = 0; $i < 100; $i++) {
43
            $actualMin = min($type->getRand(), $actualMin);
44
        }
45
        $this->assertTrue($expectedMin <= $actualMin, $actualMin . " must be less than ".$expectedMin);
46
    }
47
}
48