Failed Conditions
Pull Request — master (#3962)
by Owen
17:41 queued 07:20
created

ConcatTest::testCONCAT()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 14
rs 9.9
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
6
7
use PhpOffice\PhpSpreadsheet\Spreadsheet;
8
9
class ConcatTest extends AllSetupTeardown
10
{
11
    /**
12
     * @dataProvider providerCONCAT
13
     */
14
    public function testCONCAT(mixed $expectedResult, mixed ...$args): void
15
    {
16
        $this->mightHaveException($expectedResult);
17
        $sheet = $this->getSheet();
18
        $finalArg = '';
19
        $row = 0;
20
        foreach ($args as $arg) {
21
            ++$row;
22
            $this->setCell("A$row", $arg);
23
            $finalArg = "A1:A$row";
24
        }
25
        $this->setCell('B1', "=CONCAT($finalArg)");
26
        $result = $sheet->getCell('B1')->getCalculatedValue();
27
        self::assertEquals($expectedResult, $result);
28
    }
29
30
    public static function providerCONCAT(): array
31
    {
32
        return require 'tests/data/Calculation/TextData/CONCAT.php';
33
    }
34
35
    public function testConcatWithIndexMatch(): void
36
    {
37
        $spreadsheet = new Spreadsheet();
38
        $sheet1 = $spreadsheet->getActiveSheet();
39
        $sheet1->setTitle('Formula');
40
        $sheet1->fromArray(
41
            [
42
                ['Number', 'Formula'],
43
                [52101293, '=CONCAT(INDEX(Lookup!B2, MATCH(A2, Lookup!A2, 0)))'],
44
            ]
45
        );
46
        $sheet2 = $spreadsheet->createSheet();
47
        $sheet2->setTitle('Lookup');
48
        $sheet2->fromArray(
49
            [
50
                ['Lookup', 'Match'],
51
                [52101293, 'PHP'],
52
            ]
53
        );
54
        self::assertSame('PHP', $sheet1->getCell('B2')->getCalculatedValue());
55
        $spreadsheet->disconnectWorksheets();
56
    }
57
}
58