Completed
Push — master ( 1a7130...134289 )
by Bernhard
05:31 queued 04:05
created

FunctionalTest::fileStorageTaskClippingProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.8571
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
/**
4
 * \Wicked\Timely\FunctionalTest
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Bernhard Wick <[email protected]>
15
 * @copyright 2016 Bernhard Wick
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/wick-ed/timely
18
 */
19
20
namespace Wicked\Timely;
21
22
use Wicked\Timely\Entities\TaskFactory;
23
24
/**
25
 * Functional tests
26
 *
27
 * @author    Bernhard Wick <[email protected]>
28
 * @copyright 2016 Bernhard Wick
29
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
 * @link      https://github.com/wick-ed/timely
31
 */
32
class FunctionalTest extends \PHPUnit_Framework_TestCase {
33
34
    public function fileStorageTaskGenerationProvider() {
35
        return array(
36
            array('2016-07-26 18:38:16 | --ps-- | break;
37
            2016-07-26 17:57:36 | TEST-10 | work;
38
            2016-07-26 17:57:35 | --pe-- | ;
39
            2016-07-26 17:34:52 | --ps-- | break;
40
            2016-07-26 17:33:46 | TEST-9 | work;
41
            2016-07-26 15:18:38 | TEST-8 | work;
42
            2016-07-26 14:40:15 | --pe-- | ;
43
            2016-07-26 14:29:27 | --ps-- | break;
44
            2016-07-26 14:24:25 | TEST-7 | work;
45
            2016-07-26 12:32:38 | --pe-- | ;
46
            2016-07-26 12:09:41 | --ps-- | break;
47
            2016-07-26 12:05:25 | TEST-6 | work;
48
            2016-07-26 10:59:29 | TEST-5 | work;
49
            2016-07-26 10:12:26 | TEST-4 | work;
50
            2016-07-26 10:00:26 | TEST-3 | work;
51
            2016-07-26 09:55:58 | TEST-2 | work;
52
            2016-07-26 09:53:48 | --pe-- | ;
53
            2016-07-25 17:43:43 | --ps-- | break;
54
            2016-07-25 12:44:48 | TEST-1 | work;',
55
                10,
56
                array(
57
                    'TEST-1' => 18065, // 4h 58m 55s + 2m 10s
58
                    'TEST-2' => 268, // 4m 28s
59
                    'TEST-3' => 720, // 12m
60
                    'TEST-4' => 2823, // 47m 3s
61
                    'TEST-5' => 3956, // 1h 5m 56s
62
                    'TEST-6' => 6963, // 4m 16s + 1h 51m 47s
63
                    'TEST-7' => 2605, // 5m 2s + 38m 23s
64
                    'TEST-8' => 8108, // 2h 15m 8s
65
                    'TEST-9' => 67, // 1m 6s + 1s
66
                    'TEST-10' => 2440 // 40m 40s
67
                )),
68
            array('2016-07-26 13:41:49 | --ps-- | break;
69
            2016-07-26 10:38:17 | TEST-3 | work;
70
            2016-07-26 10:18:45 | TEST-2 | work;
71
            2016-07-26 08:37:56 | --pe-- | ;
72
            2016-07-25 18:48:48 | --ps-- | break;
73
            2016-07-25 16:13:53 | --pe-- | ;
74
            2016-07-25 16:00:58 | --ps-- | break;
75
            2016-07-25 14:20:57 | --pe-- | ;
76
            2016-07-25 13:42:35 | --ps-- | break;
77
            2016-07-25 10:18:04 | --pe-- | ;
78
            2016-07-23 18:10:08 | --ps-- | break;
79
            2016-07-23 13:00:02 | --pe-- | ;
80
            2016-07-23 12:30:24 | --ps-- | break;
81
            2016-07-23 10:29:55 | TEST-1 | work;',
82
                3,
83
                array(
84
                    'TEST-1' => 59451, // 2h 29s + 5h 10m 6s + 3h 24m 31s + 1h 40m 1s + 2h 34m 55s + 1h 40m 49s
85
                    'TEST-2' => 1172, // 19m 32s
86
                    'TEST-3' => 11012 // 3h 3m 32s
87
                )
88
            )
89
        );
90
    }
91
92
    /**
93
     *
94
     * @return type
95
     */
96
    public function fileStorageTaskClippingProvider() {
97
        return array(
98
            array(1469491200,
99
                '2016-07-26 18:38:16 | --ps-- | break;
100
            2016-07-26 17:57:36 | TEST-3 | work;
101
            2016-07-26 13:55:58 | TEST-2 | work;
102
            2016-07-26 09:53:48 | --pe-- | ;
103
            2016-07-25 17:43:43 | --ps-- | break;
104
            2016-07-25 12:44:48 | TEST-1 | work;',
105
                array(
106
                    'TEST-1' => 14530, // 4h 2m 10s
107
                    'TEST-2' => 14498, // 4h 1m 38s
108
                    'TEST-3' => 2440 // 40m 40s
109
                )),
110
            array(1469491200,
111
                '2016-07-26 18:38:16 | --ps-- | break;
112
            2016-07-26 13:55:58 | TEST-2 | work;
113
            2016-07-26 09:53:48 | --pe-- | ;
114
            2016-07-23 17:43:43 | --ps-- | break;
115
            2016-07-23 12:44:48 | TEST-1 | work;',
116
                array(
117
                    'TEST-1' => 14530, // 4h 2m 10s
118
                    'TEST-2' => 16938, // 4h 42m 18s
119
                ))
120
        );
121
    }
122
123
    /**
124
     * @dataProvider fileStorageTaskGenerationProvider
125
     */
126
    public function testFileStorageTaskGeneration($testContent, $taskCount, $expectedDurations) {
127
        // get us a mocked file storage with our content
128
        $classToMock = '\Wicked\Timely\Storage\File';
129
        /** @var \Wicked\Timely\Storage\File $mockFileStorage */
130
        $mockFileStorage = $this->getMockBuilder($classToMock)
131
                ->setMethods(array('getStorageContent'))
132
                ->getMock();
133
        $mockFileStorage->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Wicked\Timely\Storage\File>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
134
                ->method('getStorageContent')
135
                ->will($this->returnValue($testContent));
136
137
        // generate the tasks
138
        $bookings = $mockFileStorage->retrieve();
139
        $tasks = TaskFactory::getTasksFromBookings($bookings);
140
141
        // first test: count the tasks
142
        $this->assertCount($taskCount, $tasks);
143
144
        // the expected tasks
145
        $expectedTicketIds = array_keys($expectedDurations);
146
        // iterate the tasks and check their ticketIds
147
        foreach ($tasks as $task) {
148
            $this->assertContains($task->getStartBooking()->getTicketId(), $expectedTicketIds);
149
        }
150
151
        // iterate the tasks and check their duration
152
        foreach ($tasks as $task) {
153
            $this->assertEquals($expectedDurations[$task->getStartBooking()->getTicketId()], $task->getDuration());
154
        }
155
    }
156
157
    /**
158
     * @dataProvider fileStorageTaskClippingProvider
159
     */
160
    public function testTaskRetrievalWithLeadingClipping($clippingFromDate, $testContent, $expectedDurations) {
161
        // get us a mocked file storage with our content
162
        $classToMock = '\Wicked\Timely\Storage\File';
163
        /** @var \Wicked\Timely\Storage\File $mockFileStorage */
164
        $mockFileStorage = $this->getMockBuilder($classToMock)
165
                ->setMethods(array('getStorageContent'))
166
                ->getMock();
167
        $mockFileStorage->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Wicked\Timely\Storage\File>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
168
                ->method('getStorageContent')
169
                ->will($this->returnValue($testContent));
170
171
        // generate the tasks
172
        $bookings = $mockFileStorage->retrieve($pattern = null, $toDate = null, $clippingFromDate);
173
        $tasks = TaskFactory::getTasksFromBookings($bookings);
174
175
        // iterate the tasks and check their duration
176
        foreach ($tasks as $task) {
177
            $this->assertEquals($expectedDurations[$task->getStartBooking()->getTicketId()], $task->getDuration());
178
        }
179
    }
180
181
}
182