Completed
Push — develop ( 782b4e...557e80 )
by Adrien
43:38
created

providerExtractAllCellReferencesInRange()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Cell;
4
5
use PhpOffice\PhpSpreadsheet\Cell\Cell;
6
use PhpOffice\PhpSpreadsheet\Exception;
7
use PHPUnit_Framework_TestCase;
8
9
class CellTest extends PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @dataProvider providerColumnString
13
     *
14
     * @param mixed $expectedResult
15
     */
16
    public function testColumnIndexFromString($expectedResult, ...$args)
17
    {
18
        $result = Cell::columnIndexFromString(...$args);
0 ignored issues
show
Documentation introduced by
$args is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
19
        self::assertEquals($expectedResult, $result);
20
    }
21
22
    public function providerColumnString()
23
    {
24
        return require 'data/ColumnString.php';
25
    }
26
27 View Code Duplication
    public function testColumnIndexFromStringTooLong()
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...
28
    {
29
        $cellAddress = 'ABCD';
30
31
        try {
32
            Cell::columnIndexFromString($cellAddress);
33
        } catch (\Exception $e) {
34
            self::assertInstanceOf(Exception::class, $e);
35
            self::assertEquals($e->getMessage(), 'Column string index can not be longer than 3 characters');
36
37
            return;
38
        }
39
        $this->fail('An expected exception has not been raised.');
40
    }
41
42 View Code Duplication
    public function testColumnIndexFromStringTooShort()
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...
43
    {
44
        $cellAddress = '';
45
46
        try {
47
            Cell::columnIndexFromString($cellAddress);
48
        } catch (\Exception $e) {
49
            self::assertInstanceOf(Exception::class, $e);
50
            self::assertEquals($e->getMessage(), 'Column string index can not be empty');
51
52
            return;
53
        }
54
        $this->fail('An expected exception has not been raised.');
55
    }
56
57
    /**
58
     * @dataProvider providerColumnIndex
59
     *
60
     * @param mixed $expectedResult
61
     */
62
    public function testStringFromColumnIndex($expectedResult, ...$args)
63
    {
64
        $result = Cell::stringFromColumnIndex(...$args);
0 ignored issues
show
Documentation introduced by
$args is of type array<integer,?>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65
        self::assertEquals($expectedResult, $result);
66
    }
67
68
    public function providerColumnIndex()
69
    {
70
        return require 'data/ColumnIndex.php';
71
    }
72
73
    /**
74
     * @dataProvider providerCoordinates
75
     *
76
     * @param mixed $expectedResult
77
     */
78
    public function testCoordinateFromString($expectedResult, ...$args)
79
    {
80
        $result = Cell::coordinateFromString(...$args);
0 ignored issues
show
Documentation introduced by
$args is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
81
        self::assertEquals($expectedResult, $result);
82
    }
83
84
    public function providerCoordinates()
85
    {
86
        return require 'data/CellCoordinates.php';
87
    }
88
89 View Code Duplication
    public function testCoordinateFromStringWithRangeAddress()
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...
90
    {
91
        $cellAddress = 'A1:AI2012';
92
93
        try {
94
            Cell::coordinateFromString($cellAddress);
95
        } catch (\Exception $e) {
96
            self::assertInstanceOf(Exception::class, $e);
97
            self::assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
98
99
            return;
100
        }
101
        $this->fail('An expected exception has not been raised.');
102
    }
103
104 View Code Duplication
    public function testCoordinateFromStringWithEmptyAddress()
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...
105
    {
106
        $cellAddress = '';
107
108
        try {
109
            Cell::coordinateFromString($cellAddress);
110
        } catch (\Exception $e) {
111
            self::assertInstanceOf(Exception::class, $e);
112
            self::assertEquals($e->getMessage(), 'Cell coordinate can not be zero-length string');
113
114
            return;
115
        }
116
        $this->fail('An expected exception has not been raised.');
117
    }
118
119 View Code Duplication
    public function testCoordinateFromStringWithInvalidAddress()
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...
120
    {
121
        $cellAddress = 'AI';
122
123
        try {
124
            Cell::coordinateFromString($cellAddress);
125
        } catch (\Exception $e) {
126
            self::assertInstanceOf(Exception::class, $e);
127
            self::assertEquals($e->getMessage(), 'Invalid cell coordinate ' . $cellAddress);
128
129
            return;
130
        }
131
        $this->fail('An expected exception has not been raised.');
132
    }
133
134
    /**
135
     * @dataProvider providerAbsoluteCoordinates
136
     *
137
     * @param mixed $expectedResult
138
     */
139
    public function testAbsoluteCoordinateFromString($expectedResult, ...$args)
140
    {
141
        $result = Cell::absoluteCoordinate(...$args);
0 ignored issues
show
Documentation introduced by
$args is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
142
        self::assertEquals($expectedResult, $result);
143
    }
144
145
    public function providerAbsoluteCoordinates()
146
    {
147
        return require 'data/CellAbsoluteCoordinate.php';
148
    }
149
150 View Code Duplication
    public function testAbsoluteCoordinateFromStringWithRangeAddress()
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...
151
    {
152
        $cellAddress = 'A1:AI2012';
153
154
        try {
155
            Cell::absoluteCoordinate($cellAddress);
156
        } catch (\Exception $e) {
157
            self::assertInstanceOf(Exception::class, $e);
158
            self::assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
159
160
            return;
161
        }
162
        $this->fail('An expected exception has not been raised.');
163
    }
164
165
    /**
166
     * @dataProvider providerAbsoluteReferences
167
     *
168
     * @param mixed $expectedResult
169
     */
170
    public function testAbsoluteReferenceFromString($expectedResult, ...$args)
171
    {
172
        $result = Cell::absoluteReference(...$args);
0 ignored issues
show
Documentation introduced by
$args is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
173
        self::assertEquals($expectedResult, $result);
174
    }
175
176
    public function providerAbsoluteReferences()
177
    {
178
        return require 'data/CellAbsoluteReference.php';
179
    }
180
181 View Code Duplication
    public function testAbsoluteReferenceFromStringWithRangeAddress()
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...
182
    {
183
        $cellAddress = 'A1:AI2012';
184
185
        try {
186
            Cell::absoluteReference($cellAddress);
187
        } catch (\Exception $e) {
188
            self::assertInstanceOf(Exception::class, $e);
189
            self::assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
190
191
            return;
192
        }
193
        $this->fail('An expected exception has not been raised.');
194
    }
195
196
    /**
197
     * @dataProvider providerSplitRange
198
     *
199
     * @param mixed $expectedResult
200
     */
201
    public function testSplitRange($expectedResult, ...$args)
202
    {
203
        $result = Cell::splitRange(...$args);
0 ignored issues
show
Documentation introduced by
$args is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
204
        foreach ($result as $key => $split) {
205
            if (!is_array($expectedResult[$key])) {
206
                self::assertEquals($expectedResult[$key], $split[0]);
207
            } else {
208
                self::assertEquals($expectedResult[$key], $split);
209
            }
210
        }
211
    }
212
213
    public function providerSplitRange()
214
    {
215
        return require 'data/CellSplitRange.php';
216
    }
217
218
    /**
219
     * @dataProvider providerBuildRange
220
     *
221
     * @param mixed $expectedResult
222
     */
223
    public function testBuildRange($expectedResult, ...$args)
224
    {
225
        $result = Cell::buildRange(...$args);
226
        self::assertEquals($expectedResult, $result);
227
    }
228
229
    public function providerBuildRange()
230
    {
231
        return require 'data/CellBuildRange.php';
232
    }
233
234
    /**
235
     * @expectedException \TypeError
236
     */
237
    public function testBuildRangeInvalid()
238
    {
239
        if (PHP_MAJOR_VERSION < 7) {
240
            $this->markTestSkipped('Cannot catch type hinting error with PHP 5.6');
241
        }
242
243
        $cellRange = '';
244
        Cell::buildRange($cellRange);
0 ignored issues
show
Documentation introduced by
$cellRange is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
245
    }
246
247
    /**
248
     * @dataProvider providerRangeBoundaries
249
     *
250
     * @param mixed $expectedResult
251
     */
252
    public function testRangeBoundaries($expectedResult, ...$args)
253
    {
254
        $result = Cell::rangeBoundaries(...$args);
0 ignored issues
show
Documentation introduced by
$args is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
255
        self::assertEquals($expectedResult, $result);
256
    }
257
258
    public function providerRangeBoundaries()
259
    {
260
        return require 'data/CellRangeBoundaries.php';
261
    }
262
263
    /**
264
     * @dataProvider providerRangeDimension
265
     *
266
     * @param mixed $expectedResult
267
     */
268
    public function testRangeDimension($expectedResult, ...$args)
269
    {
270
        $result = Cell::rangeDimension(...$args);
0 ignored issues
show
Documentation introduced by
$args is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
271
        self::assertEquals($expectedResult, $result);
272
    }
273
274
    public function providerRangeDimension()
275
    {
276
        return require 'data/CellRangeDimension.php';
277
    }
278
279
    /**
280
     * @dataProvider providerGetRangeBoundaries
281
     *
282
     * @param mixed $expectedResult
283
     */
284
    public function testGetRangeBoundaries($expectedResult, ...$args)
285
    {
286
        $result = Cell::getRangeBoundaries(...$args);
0 ignored issues
show
Documentation introduced by
$args is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
287
        self::assertEquals($expectedResult, $result);
288
    }
289
290
    public function providerGetRangeBoundaries()
291
    {
292
        return require 'data/CellGetRangeBoundaries.php';
293
    }
294
295
    /**
296
     * @dataProvider providerExtractAllCellReferencesInRange
297
     *
298
     * @param mixed $expectedResult
299
     */
300
    public function testExtractAllCellReferencesInRange($expectedResult, ...$args)
301
    {
302
        $result = Cell::extractAllCellReferencesInRange(...$args);
0 ignored issues
show
Documentation introduced by
$args is of type array<integer,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
303
        self::assertEquals($expectedResult, $result);
304
    }
305
306
    public function providerExtractAllCellReferencesInRange()
307
    {
308
        return require 'data/CellExtractAllCellReferencesInRange.php';
309
    }
310
311
    /**
312
     * @dataProvider providerMergeRangesInCollection
313
     *
314
     * @param mixed $expectedResult
315
     */
316
    public function testMergeRangesInCollection($expectedResult, ...$args)
317
    {
318
        $result = Cell::mergeRangesInCollection(...$args);
319
        self::assertEquals($expectedResult, $result);
320
    }
321
322
    public function providerMergeRangesInCollection()
323
    {
324
        return require 'data/CellMergeRangesInCollection.php';
325
    }
326
}
327