mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-31 04:28:51 +00:00
d647fe7ee7
With PhpUnit 10 came the ability to use Php attributes rather than doc-block annotations for things like "data provider". PhpUnit 11 deprecates the use of annotations, and PhpUnit 12 will not not permit their use. Since PhpUnit 11 requires Php8.2+, we cannot adopt it as long as we support Php8.1, which will continue to be the case for some time. However, there is no penalty for early adoption. Php-cs-fixer can use: ``` 'php_unit_attributes' => ['keep_annotations' => false], ``` This allows us to run `composer fix` to automate all the needed changes. No manual changes were needed for any of the test members. With this change, PhpUnit 9 can no longer be used with the test suite. File composer.json is updated to reflect that reality, and phpunit9.xml.dist, which has been supplied in case anyone needed to use PhpUnit 9, is no longer required, and is thus deleted. For now, PhpUnit 11 is not being added as a possibility. No source code is changed in this PR.
144 lines
5.0 KiB
PHP
144 lines
5.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Cell;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\AddressHelper;
|
|
use PhpOffice\PhpSpreadsheet\Exception;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class AddressHelperTest extends TestCase
|
|
{
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerR1C1ConversionToA1Absolute')]
|
|
public function testR1C1ConversionToA1Absolute(string $expectedValue, string $address): void
|
|
{
|
|
$actualValue = AddressHelper::convertToA1($address);
|
|
|
|
self::assertSame($expectedValue, $actualValue);
|
|
}
|
|
|
|
public static function providerR1C1ConversionToA1Absolute(): array
|
|
{
|
|
return require 'tests/data/Cell/R1C1ConversionToA1Absolute.php';
|
|
}
|
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerR1C1ConversionToA1Relative')]
|
|
public function testR1C1ConversionToA1Relative(
|
|
string $expectedValue,
|
|
string $address,
|
|
?int $row = null,
|
|
?int $column = null
|
|
): void {
|
|
if ($row === null) {
|
|
if ($column === null) {
|
|
$actualValue = AddressHelper::convertToA1($address);
|
|
} else {
|
|
$actualValue = AddressHelper::convertToA1($address, $column);
|
|
}
|
|
} elseif ($column === null) {
|
|
$actualValue = AddressHelper::convertToA1($address, $row);
|
|
} else {
|
|
$actualValue = AddressHelper::convertToA1($address, $row, $column);
|
|
}
|
|
|
|
self::assertSame($expectedValue, $actualValue);
|
|
}
|
|
|
|
public static function providerR1C1ConversionToA1Relative(): array
|
|
{
|
|
return require 'tests/data/Cell/R1C1ConversionToA1Relative.php';
|
|
}
|
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerR1C1ConversionToA1Exception')]
|
|
public function testR1C1ConversionToA1Exception(string $address): void
|
|
{
|
|
$this->expectException(Exception::class);
|
|
|
|
AddressHelper::convertToA1($address);
|
|
}
|
|
|
|
public static function providerR1C1ConversionToA1Exception(): array
|
|
{
|
|
return require 'tests/data/Cell/R1C1ConversionToA1Exception.php';
|
|
}
|
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerA1ConversionToR1C1Absolute')]
|
|
public function testA1ConversionToR1C1Absolute(string $expectedValue, string $address): void
|
|
{
|
|
$actualValue = AddressHelper::convertToR1C1($address);
|
|
|
|
self::assertSame($expectedValue, $actualValue);
|
|
}
|
|
|
|
public static function providerA1ConversionToR1C1Absolute(): array
|
|
{
|
|
return require 'tests/data/Cell/A1ConversionToR1C1Absolute.php';
|
|
}
|
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerA1ConversionToR1C1Relative')]
|
|
public function testA1ConversionToR1C1Relative(string $expectedValue, string $address, ?int $row = null, ?int $column = null): void
|
|
{
|
|
$actualValue = AddressHelper::convertToR1C1($address, $row, $column);
|
|
|
|
self::assertSame($expectedValue, $actualValue);
|
|
}
|
|
|
|
public static function providerA1ConversionToR1C1Relative(): array
|
|
{
|
|
return require 'tests/data/Cell/A1ConversionToR1C1Relative.php';
|
|
}
|
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerA1ConversionToR1C1Exception')]
|
|
public function testA1ConversionToR1C1Exception(string $address): void
|
|
{
|
|
$this->expectException(Exception::class);
|
|
|
|
AddressHelper::convertToR1C1($address);
|
|
}
|
|
|
|
public static function providerA1ConversionToR1C1Exception(): array
|
|
{
|
|
return require 'tests/data/Cell/A1ConversionToR1C1Exception.php';
|
|
}
|
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerConvertFormulaToA1FromSpreadsheetXml')]
|
|
public function testConvertFormulaToA1SpreadsheetXml(string $expectedValue, string $formula): void
|
|
{
|
|
$actualValue = AddressHelper::convertFormulaToA1($formula);
|
|
|
|
self::assertSame($expectedValue, $actualValue);
|
|
}
|
|
|
|
public static function providerConvertFormulaToA1FromSpreadsheetXml(): array
|
|
{
|
|
return require 'tests/data/Cell/ConvertFormulaToA1FromSpreadsheetXml.php';
|
|
}
|
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerConvertFormulaToA1FromR1C1Absolute')]
|
|
public function testConvertFormulaToA1R1C1Absolute(string $expectedValue, string $formula): void
|
|
{
|
|
$actualValue = AddressHelper::convertFormulaToA1($formula);
|
|
|
|
self::assertSame($expectedValue, $actualValue);
|
|
}
|
|
|
|
public static function providerConvertFormulaToA1FromR1C1Absolute(): array
|
|
{
|
|
return require 'tests/data/Cell/ConvertFormulaToA1FromR1C1Absolute.php';
|
|
}
|
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerConvertFormulaToA1FromR1C1Relative')]
|
|
public function testConvertFormulaToA1FromR1C1Relative(string $expectedValue, string $formula, int $row, int $column): void
|
|
{
|
|
$actualValue = AddressHelper::convertFormulaToA1($formula, $row, $column);
|
|
|
|
self::assertSame($expectedValue, $actualValue);
|
|
}
|
|
|
|
public static function providerConvertFormulaToA1FromR1C1Relative(): array
|
|
{
|
|
return require 'tests/data/Cell/ConvertFormulaToA1FromR1C1Relative.php';
|
|
}
|
|
}
|