mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-18 14:06:34 +00:00
e9cf27354d
Successor to PR #3523. There are 494 single-line changes (`public function provider` to `public static function provider`) in this PR. None of these were made manually; they were all created with the following script (adapted from https://stackoverflow.com/questions/25909820/how-to-recursively-iterate-through-files-in-php): ```php $dir = 'C:/git/unit10prep2/tests/PhpSpreadsheetTests'; $it = new RecursiveDirectoryIterator($dir); // Loop through files foreach(new RecursiveIteratorIterator($it) as $file) { if ($file->getExtension() === 'php') { $contents = file_get_contents($file); $new = preg_replace('/public function (\\w*)([Pp])rovider/', 'public static function $1$2rovider', $contents); if ($new !== $contents) { echo "changing $file\n"; file_put_contents($file, $new); } } } ``` After this PR, there will be one more, with a small number of test changes, and enabling PhpUnit 10 for Php 8.1+.
160 lines
4.8 KiB
PHP
160 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Cell;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\AddressHelper;
|
|
use PhpOffice\PhpSpreadsheet\Exception;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class AddressHelperTest extends TestCase
|
|
{
|
|
/**
|
|
* @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';
|
|
}
|
|
|
|
/**
|
|
* @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';
|
|
}
|
|
|
|
/**
|
|
* @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';
|
|
}
|
|
|
|
/**
|
|
* @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';
|
|
}
|
|
|
|
/**
|
|
* @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';
|
|
}
|
|
|
|
/**
|
|
* @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';
|
|
}
|
|
|
|
/**
|
|
* @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';
|
|
}
|
|
|
|
/**
|
|
* @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';
|
|
}
|
|
|
|
/**
|
|
* @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';
|
|
}
|
|
}
|