Completed
Pull Request — master (#6)
by
unknown
05:22
created

BuiltInFunctionsExtensionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 96
Duplicated Lines 52.08 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 6
Bugs 1 Features 3
Metric Value
wmc 4
c 6
b 1
f 3
lcom 1
cbo 3
dl 50
loc 96
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testNow() 0 23 1
B testStartOfDay() 25 25 1
B testEndOfDay() 25 25 1
A getExtension() 0 11 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 Netdudes\DataSourceryBundle\Tests\Extension;
3
4
use Netdudes\DataSourceryBundle\Extension\BuiltInFunctionsExtension;
5
use Netdudes\DataSourceryBundle\Util\CurrentDateTimeProvider;
6
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
7
8
class BuiltInFunctionsExtensionTest extends \PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * This is just used to manually test the function
12
     */
13
    public function testNow()
14
    {
15
        $extension = $this->getExtension();
16
17
        $todayResult = $extension->now(null);
18
        $this->assertSame("2012-06-03T22:22:22+0200", $todayResult, 'The today function result did not produce the expected  with no offset');
19
20
        $offset = "+5 days";
21
        $todayResult = $extension->now($offset);
22
        $this->assertSame("2012-06-08T22:22:22+0200", $todayResult, 'The today function result did not produce the expected result with ofset ' . $offset);
23
24
        $offset = "-3 days";
25
        $todayResult = $extension->now($offset);
26
        $this->assertSame("2012-05-31T22:22:22+0200", $todayResult, 'The today function result did not produce the expected result with ofset ' . $offset);
27
28
        $offset = "-6 days - 3 minutes";
29
        $todayResult = $extension->now($offset);
30
        $this->assertSame("2012-05-28T22:19:22+0200", $todayResult, 'The today function result did not produce the expected result with ofset ' . $offset);
31
32
        $offset = "-30 minutes";
33
        $todayResult = $extension->now($offset);
34
        $this->assertSame("2012-06-03T21:52:22+0200", $todayResult, 'The today function result did not produce the expected result with ofset ' . $offset);
35
    }
36
37 View Code Duplication
    public function testStartOfDay()
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...
38
    {
39
        $extension = $this->getExtension();
40
41
        $startOfDayResult = $extension->startOfDay();
42
        $this->assertSame('2012-06-03T00:00:00+0200', $startOfDayResult, 'The startOfDay function result did not produce the expected result');
43
44
        $startOfDayResult = $extension->startOfDay('+2 hours');
45
        $this->assertSame('2012-06-04T00:00:00+0200', $startOfDayResult, 'The startOfDay function result did not produce the expected result');
46
47
        $startOfDayResult = $extension->startOfDay('-5 days');
48
        $this->assertSame('2012-05-29T00:00:00+0200', $startOfDayResult, 'The startOfDay function result did not produce the expected result');
49
50
        $startOfDayResult = $extension->startOfDay('+1 month');
51
        $this->assertSame('2012-07-03T00:00:00+0200', $startOfDayResult, 'The startOfDay function result did not produce the expected result');
52
53
        $startOfDayResult = $extension->startOfDay('15-05-2012');
54
        $this->assertSame('2012-05-15T00:00:00+0200', $startOfDayResult, 'The startOfDay function result did not produce the expected result');
55
56
        $startOfDayResult = $extension->startOfDay('2012-05-15');
57
        $this->assertSame('2012-05-15T00:00:00+0200', $startOfDayResult, 'The startOfDay function result did not produce the expected result');
58
59
        $startOfDayResult = $extension->startOfDay('15.05.2012');
60
        $this->assertSame('2012-05-15T00:00:00+0200', $startOfDayResult, 'The startOfDay function result did not produce the expected result');
61
    }
62
63 View Code Duplication
    public function testEndOfDay()
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...
64
    {
65
        $extension = $this->getExtension();
66
67
        $endOfDayResult = $extension->endOfDay();
68
        $this->assertSame('2012-06-03T23:59:59+0200', $endOfDayResult, 'The endOfDay function result did not produce the expected result');
69
70
        $endOfDayResult = $extension->endOfDay('+2 hours');
71
        $this->assertSame('2012-06-04T23:59:59+0200', $endOfDayResult, 'The endOfDay function result did not produce the expected result');
72
73
        $endOfDayResult = $extension->endOfDay('-5 days');
74
        $this->assertSame('2012-05-29T23:59:59+0200', $endOfDayResult, 'The endOfDay function result did not produce the expected result');
75
76
        $endOfDayResult = $extension->endOfDay('+1 month');
77
        $this->assertSame('2012-07-03T23:59:59+0200', $endOfDayResult, 'The endOfDay function result did not produce the expected result');
78
79
        $endOfDayResult = $extension->endOfDay('15-05-2012');
80
        $this->assertSame('2012-05-15T23:59:59+0200', $endOfDayResult, 'The endOfDay function result did not produce the expected result');
81
82
        $endOfDayResult = $extension->endOfDay('2012-05-15');
83
        $this->assertSame('2012-05-15T23:59:59+0200', $endOfDayResult, 'The endOfDay function result did not produce the expected result');
84
85
        $endOfDayResult = $extension->endOfDay('15.05.2012');
86
        $this->assertSame('2012-05-15T23:59:59+0200', $endOfDayResult, 'The endOfDay function result did not produce the expected result');
87
    }
88
89
    /**
90
     * @return BuiltInFunctionsExtension
91
     */
92
    private function getExtension()
93
    {
94
        $now = new \DateTime("2012-06-03T22:22:22+0200");
95
96
        $tokenStorage = $this->prophesize(TokenStorageInterface::class);
97
        $provider = $this->prophesize(CurrentDateTimeProvider::class);
98
        $provider->get()->willReturn($now);
99
        $extension = new BuiltInFunctionsExtension($tokenStorage->reveal(), $provider->reveal());
100
101
        return $extension;
102
    }
103
}
104