Scrutinizer Clean Up Tests (#3061)
* Scrutinizer Clean Up Tests No source code involved. * Scrutinizer Whack-a-mole Fixed 17, added 10. Trying again. * Simplify Some Tests Eliminate some null assertions. * Dead Code Remove 2 statements.
This commit is contained in:
parent
3e8d50547c
commit
252474c1bd
|
|
@ -41,7 +41,7 @@ class DocumentGenerator
|
||||||
private static function tableRow(array $lengths, ?array $values = null): string
|
private static function tableRow(array $lengths, ?array $values = null): string
|
||||||
{
|
{
|
||||||
$result = '';
|
$result = '';
|
||||||
foreach (array_map(null, $lengths, $values ?? []) as $i => [$length, $value]) {
|
foreach (array_map(/** @scrutinizer ignore-type */ null, $lengths, $values ?? []) as $i => [$length, $value]) {
|
||||||
$pad = $value === null ? '-' : ' ';
|
$pad = $value === null ? '-' : ' ';
|
||||||
if ($i > 0) {
|
if ($i > 0) {
|
||||||
$result .= '|' . $pad;
|
$result .= '|' . $pad;
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,5 @@ $helper->log('Loading file ' . /** @scrutinizer ignore-type */ pathinfo($inputFi
|
||||||
try {
|
try {
|
||||||
$spreadsheet = IOFactory::load($inputFileName);
|
$spreadsheet = IOFactory::load($inputFileName);
|
||||||
} catch (ReaderException $e) {
|
} catch (ReaderException $e) {
|
||||||
$helper->log('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
|
$helper->log('Error loading file "' . /** @scrutinizer ignore-type */ pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -724,6 +724,19 @@ class Spreadsheet
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get sheet by name, throwing exception if not found.
|
||||||
|
*/
|
||||||
|
public function getSheetByNameOrThrow(string $worksheetName): Worksheet
|
||||||
|
{
|
||||||
|
$worksheet = $this->getSheetByName($worksheetName);
|
||||||
|
if ($worksheet === null) {
|
||||||
|
throw new Exception("Sheet $worksheetName does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $worksheet;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get index for sheet.
|
* Get index for sheet.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,15 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ParseComplexTest extends TestCase
|
class ParseComplexTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testParseComplex(): void
|
public function testParseComplex(): void
|
||||||
{
|
{
|
||||||
[$real, $imaginary, $suffix] = [1.23e-4, 5.67e+8, 'j'];
|
[$real, $imaginary, $suffix] = [1.23e-4, 5.67e+8, 'j'];
|
||||||
|
|
||||||
$result = Engineering::parseComplex('1.23e-4+5.67e+8j');
|
$result = /** @scrutinizer ignore-deprecated */ Engineering::parseComplex('1.23e-4+5.67e+8j');
|
||||||
self::assertArrayHasKey('real', $result);
|
self::assertArrayHasKey('real', $result);
|
||||||
self::assertEquals($real, $result['real']);
|
self::assertEquals($real, $result['real']);
|
||||||
self::assertArrayHasKey('imaginary', $result);
|
self::assertArrayHasKey('imaginary', $result);
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,45 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
|
class IrrTest extends AllSetupTeardown
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class IrrTest extends TestCase
|
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerIRR
|
* @dataProvider providerIRR
|
||||||
*
|
*
|
||||||
* @param mixed $expectedResult
|
* @param mixed $expectedResult
|
||||||
|
* @param mixed $values
|
||||||
*/
|
*/
|
||||||
public function testIRR($expectedResult, ...$args): void
|
public function testIRR($expectedResult, $values = null): void
|
||||||
{
|
{
|
||||||
$result = Financial::IRR(...$args);
|
$this->mightHaveException($expectedResult);
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
$sheet = $this->getSheet();
|
||||||
|
$formula = '=IRR(';
|
||||||
|
if ($values !== null) {
|
||||||
|
if (is_array($values)) {
|
||||||
|
$row = 0;
|
||||||
|
foreach ($values as $value) {
|
||||||
|
if (is_array($value)) {
|
||||||
|
foreach ($value as $arrayValue) {
|
||||||
|
++$row;
|
||||||
|
$sheet->getCell("A$row")->setValue($arrayValue);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
++$row;
|
||||||
|
$sheet->getCell("A$row")->setValue($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$formula .= "A1:A$row";
|
||||||
|
} else {
|
||||||
|
$sheet->getCell('A1')->setValue($values);
|
||||||
|
$formula .= 'A1';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$formula .= ')';
|
||||||
|
$sheet->getCell('D1')->setValue($formula);
|
||||||
|
$result = $sheet->getCell('D1')->getCalculatedValue();
|
||||||
|
$this->adjustResult($result, $expectedResult);
|
||||||
|
|
||||||
|
self::assertEqualsWithDelta($expectedResult, $result, 0.1E-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerIRR(): array
|
public function providerIRR(): array
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,11 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ColumnsTest extends TestCase
|
class ColumnsTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerCOLUMNS
|
* @dataProvider providerCOLUMNS
|
||||||
*
|
*
|
||||||
|
|
@ -21,7 +15,7 @@ class ColumnsTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testCOLUMNS($expectedResult, ...$args): void
|
public function testCOLUMNS($expectedResult, ...$args): void
|
||||||
{
|
{
|
||||||
$result = LookupRef::COLUMNS(...$args);
|
$result = LookupRef::COLUMNS(/** @scrutinizer ignore-type */ ...$args);
|
||||||
self::assertEquals($expectedResult, $result);
|
self::assertEquals($expectedResult, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,11 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class IndexTest extends TestCase
|
class IndexTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerINDEX
|
* @dataProvider providerINDEX
|
||||||
*
|
*
|
||||||
|
|
@ -21,7 +15,7 @@ class IndexTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testINDEX($expectedResult, ...$args): void
|
public function testINDEX($expectedResult, ...$args): void
|
||||||
{
|
{
|
||||||
$result = LookupRef::INDEX(...$args);
|
$result = LookupRef::INDEX(/** @scrutinizer ignore-type */ ...$args);
|
||||||
self::assertEquals($expectedResult, $result);
|
self::assertEquals($expectedResult, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,11 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class RowsTest extends TestCase
|
class RowsTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerROWS
|
* @dataProvider providerROWS
|
||||||
*
|
*
|
||||||
|
|
@ -21,7 +15,7 @@ class RowsTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testROWS($expectedResult, ...$args): void
|
public function testROWS($expectedResult, ...$args): void
|
||||||
{
|
{
|
||||||
$result = LookupRef::ROWS(...$args);
|
$result = LookupRef::ROWS(/** @scrutinizer ignore-type */ ...$args);
|
||||||
self::assertEquals($expectedResult, $result);
|
self::assertEquals($expectedResult, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class RandBetweenTest extends AllSetupTeardown
|
||||||
$formula = "=RandBetween({$argument1}, {$argument2})";
|
$formula = "=RandBetween({$argument1}, {$argument2})";
|
||||||
$result = $calculation->_calculateFormulaValue($formula);
|
$result = $calculation->_calculateFormulaValue($formula);
|
||||||
self::assertIsArray($result);
|
self::assertIsArray($result);
|
||||||
self::assertCount($expectedRows, $result);
|
self::assertCount($expectedRows, /** @scrutinizer ignore-type */ $result);
|
||||||
self::assertIsArray($result[0]);
|
self::assertIsArray($result[0]);
|
||||||
self::assertCount($expectedColumns, /** @scrutinizer ignore-type */ $result[0]);
|
self::assertCount($expectedColumns, /** @scrutinizer ignore-type */ $result[0]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ class DefinedNameTest extends TestCase
|
||||||
DefinedName::createInstance('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
DefinedName::createInstance('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addDefinedName(
|
$this->spreadsheet->addDefinedName(
|
||||||
DefinedName::createInstance('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=B1', true)
|
DefinedName::createInstance('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=B1', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
self::assertCount(2, $this->spreadsheet->getDefinedNames());
|
self::assertCount(2, $this->spreadsheet->getDefinedNames());
|
||||||
|
|
@ -66,7 +66,7 @@ class DefinedNameTest extends TestCase
|
||||||
self::assertNotNull($definedName1);
|
self::assertNotNull($definedName1);
|
||||||
self::assertSame('=A1', $definedName1->getValue());
|
self::assertSame('=A1', $definedName1->getValue());
|
||||||
|
|
||||||
$definedName2 = $this->spreadsheet->getDefinedName('foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$definedName2 = $this->spreadsheet->getDefinedName('foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
self::assertNotNull($definedName2);
|
self::assertNotNull($definedName2);
|
||||||
self::assertSame('=B1', $definedName2->getValue());
|
self::assertSame('=B1', $definedName2->getValue());
|
||||||
}
|
}
|
||||||
|
|
@ -103,13 +103,13 @@ class DefinedNameTest extends TestCase
|
||||||
DefinedName::createInstance('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
DefinedName::createInstance('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addDefinedName(
|
$this->spreadsheet->addDefinedName(
|
||||||
DefinedName::createInstance('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=B1', true)
|
DefinedName::createInstance('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=B1', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->spreadsheet->removeDefinedName('Foo', $this->spreadsheet->getActiveSheet());
|
$this->spreadsheet->removeDefinedName('Foo', $this->spreadsheet->getActiveSheet());
|
||||||
|
|
||||||
self::assertCount(1, $this->spreadsheet->getDefinedNames());
|
self::assertCount(1, $this->spreadsheet->getDefinedNames());
|
||||||
$definedName = $this->spreadsheet->getDefinedName('foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$definedName = $this->spreadsheet->getDefinedName('foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
self::assertNotNull($definedName);
|
self::assertNotNull($definedName);
|
||||||
self::assertSame('=B1', $definedName->getValue());
|
self::assertSame('=B1', $definedName->getValue());
|
||||||
}
|
}
|
||||||
|
|
@ -120,10 +120,10 @@ class DefinedNameTest extends TestCase
|
||||||
DefinedName::createInstance('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
DefinedName::createInstance('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addDefinedName(
|
$this->spreadsheet->addDefinedName(
|
||||||
DefinedName::createInstance('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=B1', true)
|
DefinedName::createInstance('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=B1', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->spreadsheet->removeDefinedName('Foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$this->spreadsheet->removeDefinedName('Foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
|
|
||||||
self::assertCount(1, $this->spreadsheet->getDefinedNames());
|
self::assertCount(1, $this->spreadsheet->getDefinedNames());
|
||||||
$definedName = $this->spreadsheet->getDefinedName('foo');
|
$definedName = $this->spreadsheet->getDefinedName('foo');
|
||||||
|
|
@ -154,10 +154,8 @@ class DefinedNameTest extends TestCase
|
||||||
|
|
||||||
public function testChangeWorksheet(): void
|
public function testChangeWorksheet(): void
|
||||||
{
|
{
|
||||||
$sheet1 = $this->spreadsheet->getSheetByName('Sheet #1');
|
$sheet1 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #1');
|
||||||
$sheet2 = $this->spreadsheet->getSheetByName('Sheet #2');
|
$sheet2 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #2');
|
||||||
self::assertNotNull($sheet1);
|
|
||||||
self::assertNotNull($sheet2);
|
|
||||||
|
|
||||||
$sheet1->getCell('A1')->setValue(1);
|
$sheet1->getCell('A1')->setValue(1);
|
||||||
$sheet2->getCell('A1')->setValue(2);
|
$sheet2->getCell('A1')->setValue(2);
|
||||||
|
|
@ -172,10 +170,8 @@ class DefinedNameTest extends TestCase
|
||||||
|
|
||||||
public function testLocalOnly(): void
|
public function testLocalOnly(): void
|
||||||
{
|
{
|
||||||
$sheet1 = $this->spreadsheet->getSheetByName('Sheet #1');
|
$sheet1 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #1');
|
||||||
$sheet2 = $this->spreadsheet->getSheetByName('Sheet #2');
|
$sheet2 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #2');
|
||||||
self::assertNotNull($sheet1);
|
|
||||||
self::assertNotNull($sheet2);
|
|
||||||
|
|
||||||
$sheet1->getCell('A1')->setValue(1);
|
$sheet1->getCell('A1')->setValue(1);
|
||||||
$sheet2->getCell('A1')->setValue(2);
|
$sheet2->getCell('A1')->setValue(2);
|
||||||
|
|
@ -190,10 +186,8 @@ class DefinedNameTest extends TestCase
|
||||||
|
|
||||||
public function testScope(): void
|
public function testScope(): void
|
||||||
{
|
{
|
||||||
$sheet1 = $this->spreadsheet->getSheetByName('Sheet #1');
|
$sheet1 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #1');
|
||||||
$sheet2 = $this->spreadsheet->getSheetByName('Sheet #2');
|
$sheet2 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #2');
|
||||||
self::assertNotNull($sheet1);
|
|
||||||
self::assertNotNull($sheet2);
|
|
||||||
|
|
||||||
$sheet1->getCell('A1')->setValue(1);
|
$sheet1->getCell('A1')->setValue(1);
|
||||||
$sheet2->getCell('A1')->setValue(2);
|
$sheet2->getCell('A1')->setValue(2);
|
||||||
|
|
@ -208,10 +202,8 @@ class DefinedNameTest extends TestCase
|
||||||
|
|
||||||
public function testClone(): void
|
public function testClone(): void
|
||||||
{
|
{
|
||||||
$sheet1 = $this->spreadsheet->getSheetByName('Sheet #1');
|
$sheet1 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #1');
|
||||||
$sheet2 = $this->spreadsheet->getSheetByName('Sheet #2');
|
$sheet2 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #2');
|
||||||
self::assertNotNull($sheet1);
|
|
||||||
self::assertNotNull($sheet2);
|
|
||||||
|
|
||||||
$sheet1->getCell('A1')->setValue(1);
|
$sheet1->getCell('A1')->setValue(1);
|
||||||
$sheet2->getCell('A1')->setValue(2);
|
$sheet2->getCell('A1')->setValue(2);
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,7 @@ class PrintAreaTest extends AbstractFunctional
|
||||||
|
|
||||||
private static function getPrintArea(Spreadsheet $spreadsheet, string $name): string
|
private static function getPrintArea(Spreadsheet $spreadsheet, string $name): string
|
||||||
{
|
{
|
||||||
$sheet = $spreadsheet->getSheetByName($name);
|
$sheet = $spreadsheet->getSheetByNameOrThrow($name);
|
||||||
self::assertNotNull($sheet, "Unable to get sheet $name");
|
|
||||||
|
|
||||||
return $sheet->getPageSetup()->getPrintArea();
|
return $sheet->getPageSetup()->getPrintArea();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class NamedFormulaTest extends TestCase
|
||||||
new NamedFormula('Foo', $this->spreadsheet->getActiveSheet(), '=19%')
|
new NamedFormula('Foo', $this->spreadsheet->getActiveSheet(), '=19%')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addNamedFormula(
|
$this->spreadsheet->addNamedFormula(
|
||||||
new NamedFormula('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=16%', true)
|
new NamedFormula('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=16%', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
self::assertCount(2, $this->spreadsheet->getNamedFormulae());
|
self::assertCount(2, $this->spreadsheet->getNamedFormulae());
|
||||||
|
|
@ -72,7 +72,7 @@ class NamedFormulaTest extends TestCase
|
||||||
'=19%',
|
'=19%',
|
||||||
$formula->getValue()
|
$formula->getValue()
|
||||||
);
|
);
|
||||||
$formula = $this->spreadsheet->getNamedFormula('foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$formula = $this->spreadsheet->getNamedFormula('foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
self::assertNotNull($formula);
|
self::assertNotNull($formula);
|
||||||
self::assertSame(
|
self::assertSame(
|
||||||
'=16%',
|
'=16%',
|
||||||
|
|
@ -100,13 +100,13 @@ class NamedFormulaTest extends TestCase
|
||||||
new NamedFormula('Foo', $this->spreadsheet->getActiveSheet(), '=19%')
|
new NamedFormula('Foo', $this->spreadsheet->getActiveSheet(), '=19%')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addNamedFormula(
|
$this->spreadsheet->addNamedFormula(
|
||||||
new NamedFormula('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=16%', true)
|
new NamedFormula('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=16%', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->spreadsheet->removeNamedFormula('Foo', $this->spreadsheet->getActiveSheet());
|
$this->spreadsheet->removeNamedFormula('Foo', $this->spreadsheet->getActiveSheet());
|
||||||
|
|
||||||
self::assertCount(1, $this->spreadsheet->getNamedFormulae());
|
self::assertCount(1, $this->spreadsheet->getNamedFormulae());
|
||||||
$formula = $this->spreadsheet->getNamedFormula('foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$formula = $this->spreadsheet->getNamedFormula('foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
self::assertNotNull($formula);
|
self::assertNotNull($formula);
|
||||||
self::assertSame(
|
self::assertSame(
|
||||||
'=16%',
|
'=16%',
|
||||||
|
|
@ -120,10 +120,10 @@ class NamedFormulaTest extends TestCase
|
||||||
new NamedFormula('Foo', $this->spreadsheet->getActiveSheet(), '=19%')
|
new NamedFormula('Foo', $this->spreadsheet->getActiveSheet(), '=19%')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addNamedFormula(
|
$this->spreadsheet->addNamedFormula(
|
||||||
new NamedFormula('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=16%', true)
|
new NamedFormula('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=16%', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->spreadsheet->removeNamedFormula('Foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$this->spreadsheet->removeNamedFormula('Foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
|
|
||||||
self::assertCount(1, $this->spreadsheet->getNamedFormulae());
|
self::assertCount(1, $this->spreadsheet->getNamedFormulae());
|
||||||
$formula = $this->spreadsheet->getNamedFormula('foo');
|
$formula = $this->spreadsheet->getNamedFormula('foo');
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class NamedRangeTest extends TestCase
|
||||||
new NamedRange('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
new NamedRange('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addNamedRange(
|
$this->spreadsheet->addNamedRange(
|
||||||
new NamedRange('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=B1', true)
|
new NamedRange('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=B1', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
self::assertCount(2, $this->spreadsheet->getNamedRanges());
|
self::assertCount(2, $this->spreadsheet->getNamedRanges());
|
||||||
|
|
@ -72,7 +72,7 @@ class NamedRangeTest extends TestCase
|
||||||
'=A1',
|
'=A1',
|
||||||
$range->getValue()
|
$range->getValue()
|
||||||
);
|
);
|
||||||
$range = $this->spreadsheet->getNamedRange('foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$range = $this->spreadsheet->getNamedRange('foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
self::assertNotNull($range);
|
self::assertNotNull($range);
|
||||||
self::assertSame(
|
self::assertSame(
|
||||||
'=B1',
|
'=B1',
|
||||||
|
|
@ -100,13 +100,13 @@ class NamedRangeTest extends TestCase
|
||||||
new NamedRange('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
new NamedRange('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addNamedRange(
|
$this->spreadsheet->addNamedRange(
|
||||||
new NamedRange('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=B1', true)
|
new NamedRange('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=B1', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->spreadsheet->removeNamedRange('Foo', $this->spreadsheet->getActiveSheet());
|
$this->spreadsheet->removeNamedRange('Foo', $this->spreadsheet->getActiveSheet());
|
||||||
|
|
||||||
self::assertCount(1, $this->spreadsheet->getNamedRanges());
|
self::assertCount(1, $this->spreadsheet->getNamedRanges());
|
||||||
$sheet = $this->spreadsheet->getNamedRange('foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$sheet = $this->spreadsheet->getNamedRange('foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
self::assertNotNull($sheet);
|
self::assertNotNull($sheet);
|
||||||
self::assertSame(
|
self::assertSame(
|
||||||
'=B1',
|
'=B1',
|
||||||
|
|
@ -120,10 +120,10 @@ class NamedRangeTest extends TestCase
|
||||||
new NamedRange('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
new NamedRange('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addNamedRange(
|
$this->spreadsheet->addNamedRange(
|
||||||
new NamedRange('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=B1', true)
|
new NamedRange('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=B1', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->spreadsheet->removeNamedRange('Foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$this->spreadsheet->removeNamedRange('Foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
|
|
||||||
self::assertCount(1, $this->spreadsheet->getNamedRanges());
|
self::assertCount(1, $this->spreadsheet->getNamedRanges());
|
||||||
$range = $this->spreadsheet->getNamedRange('foo');
|
$range = $this->spreadsheet->getNamedRange('foo');
|
||||||
|
|
|
||||||
|
|
@ -56,13 +56,11 @@ class CsvContiguousTest extends TestCase
|
||||||
|
|
||||||
private static function getCellValue(Spreadsheet $spreadsheet, string $sheetName, string $cellAddress): string
|
private static function getCellValue(Spreadsheet $spreadsheet, string $sheetName, string $cellAddress): string
|
||||||
{
|
{
|
||||||
$sheet = $spreadsheet->getSheetByName($sheetName);
|
$sheet = $spreadsheet->getSheetByNameOrThrow($sheetName);
|
||||||
$result = '';
|
$result = '';
|
||||||
if ($sheet !== null) {
|
$value = $sheet->getCell($cellAddress)->getValue();
|
||||||
$value = $sheet->getCell($cellAddress)->getValue();
|
if (is_scalar($value) || (is_object($value) && method_exists($value, '__toString'))) {
|
||||||
if (is_scalar($value) || (is_object($value) && method_exists($value, '__toString'))) {
|
$result = (string) $value;
|
||||||
$result = (string) $value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
||||||
|
|
@ -15,20 +15,16 @@ class NumberFormatGeneralTest extends AbstractFunctional
|
||||||
|
|
||||||
$reader = new Xls();
|
$reader = new Xls();
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
$sheet = $spreadsheet->getSheetByName('Blad1');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('Blad1');
|
||||||
if ($sheet === null) {
|
$array = $sheet->toArray();
|
||||||
self::fail('Expected to find sheet Blad1');
|
self::assertSame('€ 2.95', $array[1][3]);
|
||||||
} else {
|
self::assertSame(2.95, $sheet->getCell('D2')->getValue());
|
||||||
$array = $sheet->toArray();
|
self::assertSame(2.95, $sheet->getCell('D2')->getCalculatedValue());
|
||||||
self::assertSame('€ 2.95', $array[1][3]);
|
self::assertSame('€ 2.95', $sheet->getCell('D2')->getFormattedValue());
|
||||||
self::assertSame(2.95, $sheet->getCell('D2')->getValue());
|
self::assertSame(21, $array[1][4]);
|
||||||
self::assertSame(2.95, $sheet->getCell('D2')->getCalculatedValue());
|
self::assertSame(21, $sheet->getCell('E2')->getValue());
|
||||||
self::assertSame('€ 2.95', $sheet->getCell('D2')->getFormattedValue());
|
self::assertSame(21, $sheet->getCell('E2')->getCalculatedValue());
|
||||||
self::assertSame(21, $array[1][4]);
|
self::assertSame('21', $sheet->getCell('E2')->getFormattedValue());
|
||||||
self::assertSame(21, $sheet->getCell('E2')->getValue());
|
|
||||||
self::assertSame(21, $sheet->getCell('E2')->getCalculatedValue());
|
|
||||||
self::assertSame('21', $sheet->getCell('E2')->getFormattedValue());
|
|
||||||
}
|
|
||||||
$spreadsheet->disconnectWorksheets();
|
$spreadsheet->disconnectWorksheets();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,7 @@ class RichTextSizeTest extends AbstractFunctional
|
||||||
$filename = 'tests/data/Reader/XLS/RichTextFontSize.xls';
|
$filename = 'tests/data/Reader/XLS/RichTextFontSize.xls';
|
||||||
$reader = new Xls();
|
$reader = new Xls();
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
$sheet = $spreadsheet->getSheetByName('橱柜门板');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('橱柜门板');
|
||||||
self::assertNotNull($sheet);
|
|
||||||
$text = $sheet->getCell('L15')->getValue();
|
$text = $sheet->getCell('L15')->getValue();
|
||||||
$elements = $text->getRichTextElements();
|
$elements = $text->getRichTextElements();
|
||||||
self::assertEquals(10, $elements[2]->getFont()->getSize());
|
self::assertEquals(10, $elements[2]->getFont()->getSize());
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,7 @@ class AutoFilter2Test extends TestCase
|
||||||
public function testReadDateRange(): void
|
public function testReadDateRange(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
||||||
$sheet = $spreadsheet->getSheetByName('daterange');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('daterange');
|
||||||
self::assertNotNull($sheet);
|
|
||||||
$filter = $sheet->getAutoFilter();
|
$filter = $sheet->getAutoFilter();
|
||||||
$maxRow = 30;
|
$maxRow = 30;
|
||||||
self::assertSame("A1:A$maxRow", $filter->getRange());
|
self::assertSame("A1:A$maxRow", $filter->getRange());
|
||||||
|
|
@ -61,8 +60,7 @@ class AutoFilter2Test extends TestCase
|
||||||
public function testReadTopTen(): void
|
public function testReadTopTen(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
||||||
$sheet = $spreadsheet->getSheetByName('top10');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('top10');
|
||||||
self::assertNotNull($sheet);
|
|
||||||
$filter = $sheet->getAutoFilter();
|
$filter = $sheet->getAutoFilter();
|
||||||
$maxRow = 65;
|
$maxRow = 65;
|
||||||
self::assertSame("A1:A$maxRow", $filter->getRange());
|
self::assertSame("A1:A$maxRow", $filter->getRange());
|
||||||
|
|
@ -87,8 +85,7 @@ class AutoFilter2Test extends TestCase
|
||||||
public function testReadDynamic(): void
|
public function testReadDynamic(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
||||||
$sheet = $spreadsheet->getSheetByName('dynamic');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('dynamic');
|
||||||
self::assertNotNull($sheet);
|
|
||||||
$filter = $sheet->getAutoFilter();
|
$filter = $sheet->getAutoFilter();
|
||||||
$maxRow = 30;
|
$maxRow = 30;
|
||||||
self::assertSame("A1:A$maxRow", $filter->getRange());
|
self::assertSame("A1:A$maxRow", $filter->getRange());
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ChartSheetTest extends TestCase
|
class ChartSheetTest extends TestCase
|
||||||
|
|
@ -16,8 +15,7 @@ class ChartSheetTest extends TestCase
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
|
|
||||||
self::assertCount(2, $spreadsheet->getAllSheets());
|
self::assertCount(2, $spreadsheet->getAllSheets());
|
||||||
$chartSheet = $spreadsheet->getSheetByName('Chart1');
|
$chartSheet = $spreadsheet->getSheetByNameOrThrow('Chart1');
|
||||||
self::assertInstanceOf(Worksheet::class, $chartSheet);
|
|
||||||
self::assertSame(1, $chartSheet->getChartCount());
|
self::assertSame(1, $chartSheet->getChartCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,7 +27,6 @@ class ChartSheetTest extends TestCase
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
|
|
||||||
self::assertCount(1, $spreadsheet->getAllSheets());
|
self::assertCount(1, $spreadsheet->getAllSheets());
|
||||||
$chartSheet = $spreadsheet->getSheetByName('Chart1');
|
self::assertNull($spreadsheet->getSheetByName('Chart1'));
|
||||||
self::assertNull($chartSheet);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,28 +42,20 @@ class Issue2501Test extends TestCase
|
||||||
$filename = self::$testbook;
|
$filename = self::$testbook;
|
||||||
$reader = IOFactory::createReader('Xlsx');
|
$reader = IOFactory::createReader('Xlsx');
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
$sheet = $spreadsheet->getSheetByName('Columns');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('Columns');
|
||||||
$expected = [
|
$expected = [
|
||||||
'A1:A1048576',
|
'A1:A1048576',
|
||||||
'B1:D1048576',
|
'B1:D1048576',
|
||||||
'E2:E4',
|
'E2:E4',
|
||||||
];
|
];
|
||||||
if ($sheet === null) {
|
self::assertSame($expected, array_values($sheet->getMergeCells()));
|
||||||
self::fail('Unable to find sheet Columns');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('Rows');
|
||||||
} else {
|
|
||||||
self::assertSame($expected, array_values($sheet->getMergeCells()));
|
|
||||||
}
|
|
||||||
$sheet = $spreadsheet->getSheetByName('Rows');
|
|
||||||
$expected = [
|
$expected = [
|
||||||
'A1:XFD1',
|
'A1:XFD1',
|
||||||
'A2:XFD4',
|
'A2:XFD4',
|
||||||
'B5:D5',
|
'B5:D5',
|
||||||
];
|
];
|
||||||
if ($sheet === null) {
|
self::assertSame($expected, array_values($sheet->getMergeCells()));
|
||||||
self::fail('Unable to find sheet Rows');
|
|
||||||
} else {
|
|
||||||
self::assertSame($expected, array_values($sheet->getMergeCells()));
|
|
||||||
}
|
|
||||||
|
|
||||||
$spreadsheet->disconnectWorksheets();
|
$spreadsheet->disconnectWorksheets();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,9 @@ class NamespaceNonStdTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertSame('A2', $sheet->getFreezePane());
|
self::assertSame('A2', $sheet->getFreezePane());
|
||||||
self::assertSame('A2', $sheet->getTopLeftCell());
|
self::assertSame('A2', $sheet->getTopLeftCell());
|
||||||
self::assertSame('B3', $sheet->getSelectedCells());
|
self::assertSame('B3', $sheet->getSelectedCells());
|
||||||
$sheet = $spreadsheet->getSheetByName('SylkTest');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('SylkTest');
|
||||||
if ($sheet === null) {
|
self::assertNull($sheet->getFreezePane());
|
||||||
self::fail('Unable to load expected sheet');
|
self::assertNull($sheet->getTopLeftCell());
|
||||||
} else {
|
|
||||||
self::assertNull($sheet->getFreezePane());
|
|
||||||
self::assertNull($sheet->getTopLeftCell());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadXlsx(): void
|
public function testLoadXlsx(): void
|
||||||
|
|
|
||||||
|
|
@ -100,13 +100,9 @@ class NamespaceOpenpyxl35Test extends \PHPUnit\Framework\TestCase
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
foreach ($expectedArray as $sheetName => $array1) {
|
foreach ($expectedArray as $sheetName => $array1) {
|
||||||
$sheet = $spreadsheet->getSheetByName($sheetName);
|
$sheet = $spreadsheet->getSheetByNameOrThrow($sheetName);
|
||||||
if ($sheet === null) {
|
foreach ($array1 as $key => $value) {
|
||||||
self::fail("Unable to find sheet $sheetName");
|
self::assertSame($value, self::getCellValue($sheet, $key), "error in sheet $sheetName cell $key");
|
||||||
} else {
|
|
||||||
foreach ($array1 as $key => $value) {
|
|
||||||
self::assertSame($value, self::getCellValue($sheet, $key), "error in sheet $sheetName cell $key");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$spreadsheet->disconnectWorksheets();
|
$spreadsheet->disconnectWorksheets();
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,9 @@ class NamespaceStdTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertSame('A2', $sheet->getFreezePane());
|
self::assertSame('A2', $sheet->getFreezePane());
|
||||||
self::assertSame('A2', $sheet->getTopLeftCell());
|
self::assertSame('A2', $sheet->getTopLeftCell());
|
||||||
self::assertSame('B3', $sheet->getSelectedCells());
|
self::assertSame('B3', $sheet->getSelectedCells());
|
||||||
$sheet = $spreadsheet->getSheetByName('SylkTest');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('SylkTest');
|
||||||
if ($sheet === null) {
|
self::assertNull($sheet->getFreezePane());
|
||||||
self::fail('Unable to load expected sheet');
|
self::assertNull($sheet->getTopLeftCell());
|
||||||
} else {
|
|
||||||
self::assertNull($sheet->getFreezePane());
|
|
||||||
self::assertNull($sheet->getTopLeftCell());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadXlsx(): void
|
public function testLoadXlsx(): void
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,7 @@ class PageSetup2Test extends TestCase
|
||||||
public function testColumnBreak(): void
|
public function testColumnBreak(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
||||||
$sheet = $spreadsheet->getSheetByName('colbreak');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('colbreak');
|
||||||
self::assertNotNull($sheet);
|
|
||||||
$breaks = $sheet->getBreaks();
|
$breaks = $sheet->getBreaks();
|
||||||
self::assertCount(1, $breaks);
|
self::assertCount(1, $breaks);
|
||||||
$break = $breaks['D1'] ?? null;
|
$break = $breaks['D1'] ?? null;
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,27 @@ class PasswordHasherTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerHashPassword
|
* @dataProvider providerHashPassword
|
||||||
*
|
|
||||||
* @param mixed $expectedResult
|
|
||||||
*/
|
*/
|
||||||
public function testHashPassword($expectedResult, ...$args): void
|
public function testHashPassword(
|
||||||
{
|
string $expectedResult,
|
||||||
|
string $password,
|
||||||
|
?string $algorithm = null,
|
||||||
|
?string $salt = null,
|
||||||
|
?int $spinCount = null
|
||||||
|
): void {
|
||||||
if ($expectedResult === 'exception') {
|
if ($expectedResult === 'exception') {
|
||||||
$this->expectException(SpException::class);
|
$this->expectException(SpException::class);
|
||||||
}
|
}
|
||||||
$result = PasswordHasher::hashPassword(...$args);
|
if ($algorithm === null) {
|
||||||
self::assertEquals($expectedResult, $result);
|
$result = PasswordHasher::hashPassword($password);
|
||||||
|
} elseif ($salt === null) {
|
||||||
|
$result = PasswordHasher::hashPassword($password, $algorithm);
|
||||||
|
} elseif ($spinCount === null) {
|
||||||
|
$result = PasswordHasher::hashPassword($password, $algorithm, $salt);
|
||||||
|
} else {
|
||||||
|
$result = PasswordHasher::hashPassword($password, $algorithm, $salt, $spinCount);
|
||||||
|
}
|
||||||
|
self::assertSame($expectedResult, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerHashPassword(): array
|
public function providerHashPassword(): array
|
||||||
|
|
|
||||||
|
|
@ -2,28 +2,38 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests;
|
namespace PhpOffice\PhpSpreadsheetTests;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Exception as ssException;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class SpreadsheetTest extends TestCase
|
class SpreadsheetTest extends TestCase
|
||||||
{
|
{
|
||||||
/** @var Spreadsheet */
|
/** @var ?Spreadsheet */
|
||||||
private $object;
|
private $spreadsheet;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
if ($this->spreadsheet !== null) {
|
||||||
$this->object = new Spreadsheet();
|
$this->spreadsheet->disconnectWorksheets();
|
||||||
$sheet = $this->object->getActiveSheet();
|
$this->spreadsheet = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getSpreadsheet(): Spreadsheet
|
||||||
|
{
|
||||||
|
$this->spreadsheet = $spreadsheet = new Spreadsheet();
|
||||||
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
$sheet->setTitle('someSheet1');
|
$sheet->setTitle('someSheet1');
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet2');
|
$sheet->setTitle('someSheet2');
|
||||||
$this->object->addSheet($sheet);
|
$spreadsheet->addSheet($sheet);
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet 3');
|
$sheet->setTitle('someSheet 3');
|
||||||
$this->object->addSheet($sheet);
|
$spreadsheet->addSheet($sheet);
|
||||||
|
|
||||||
|
return $spreadsheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataProviderForSheetNames(): array
|
public function dataProviderForSheetNames(): array
|
||||||
|
|
@ -35,6 +45,7 @@ class SpreadsheetTest extends TestCase
|
||||||
[1, "'someSheet2'"],
|
[1, "'someSheet2'"],
|
||||||
[2, 'someSheet 3'],
|
[2, 'someSheet 3'],
|
||||||
[2, "'someSheet 3'"],
|
[2, "'someSheet 3'"],
|
||||||
|
[null, 'someSheet 33'],
|
||||||
];
|
];
|
||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
|
|
@ -43,135 +54,153 @@ class SpreadsheetTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataProviderForSheetNames
|
* @dataProvider dataProviderForSheetNames
|
||||||
*/
|
*/
|
||||||
public function testGetSheetByName(int $index, string $sheetName): void
|
public function testGetSheetByName(?int $index, string $sheetName): void
|
||||||
{
|
{
|
||||||
self::assertSame($this->object->getSheet($index), $this->object->getSheetByName($sheetName));
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
|
if ($index === null) {
|
||||||
|
self::assertNull($spreadsheet->getSheetByName($sheetName));
|
||||||
|
} else {
|
||||||
|
self::assertSame($spreadsheet->getSheet($index), $spreadsheet->getSheetByName($sheetName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddSheetDuplicateTitle(): void
|
public function testAddSheetDuplicateTitle(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
|
$this->expectException(ssException::class);
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet2');
|
$sheet->setTitle('someSheet2');
|
||||||
$this->object->addSheet($sheet);
|
$spreadsheet->addSheet($sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddSheetNoAdjustActive(): void
|
public function testAddSheetNoAdjustActive(): void
|
||||||
{
|
{
|
||||||
$this->object->setActiveSheetIndex(2);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
self::assertEquals(2, $this->object->getActiveSheetIndex());
|
$spreadsheet->setActiveSheetIndex(2);
|
||||||
|
self::assertEquals(2, $spreadsheet->getActiveSheetIndex());
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet4');
|
$sheet->setTitle('someSheet4');
|
||||||
$this->object->addSheet($sheet);
|
$spreadsheet->addSheet($sheet);
|
||||||
self::assertEquals(2, $this->object->getActiveSheetIndex());
|
self::assertEquals(2, $spreadsheet->getActiveSheetIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddSheetAdjustActive(): void
|
public function testAddSheetAdjustActive(): void
|
||||||
{
|
{
|
||||||
$this->object->setActiveSheetIndex(2);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
self::assertEquals(2, $this->object->getActiveSheetIndex());
|
$spreadsheet->setActiveSheetIndex(2);
|
||||||
|
self::assertEquals(2, $spreadsheet->getActiveSheetIndex());
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet0');
|
$sheet->setTitle('someSheet0');
|
||||||
$this->object->addSheet($sheet, 0);
|
$spreadsheet->addSheet($sheet, 0);
|
||||||
self::assertEquals(3, $this->object->getActiveSheetIndex());
|
self::assertEquals(3, $spreadsheet->getActiveSheetIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveSheetIndexTooHigh(): void
|
public function testRemoveSheetIndexTooHigh(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
$this->object->removeSheetByIndex(4);
|
$this->expectException(ssException::class);
|
||||||
|
$spreadsheet->removeSheetByIndex(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveSheetNoAdjustActive(): void
|
public function testRemoveSheetNoAdjustActive(): void
|
||||||
{
|
{
|
||||||
$this->object->setActiveSheetIndex(1);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
self::assertEquals(1, $this->object->getActiveSheetIndex());
|
$spreadsheet->setActiveSheetIndex(1);
|
||||||
$this->object->removeSheetByIndex(2);
|
self::assertEquals(1, $spreadsheet->getActiveSheetIndex());
|
||||||
self::assertEquals(1, $this->object->getActiveSheetIndex());
|
$spreadsheet->removeSheetByIndex(2);
|
||||||
|
self::assertEquals(1, $spreadsheet->getActiveSheetIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveSheetAdjustActive(): void
|
public function testRemoveSheetAdjustActive(): void
|
||||||
{
|
{
|
||||||
$this->object->setActiveSheetIndex(2);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
self::assertEquals(2, $this->object->getActiveSheetIndex());
|
$spreadsheet->setActiveSheetIndex(2);
|
||||||
$this->object->removeSheetByIndex(1);
|
self::assertEquals(2, $spreadsheet->getActiveSheetIndex());
|
||||||
self::assertEquals(1, $this->object->getActiveSheetIndex());
|
$spreadsheet->removeSheetByIndex(1);
|
||||||
|
self::assertEquals(1, $spreadsheet->getActiveSheetIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetSheetIndexTooHigh(): void
|
public function testGetSheetIndexTooHigh(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
$this->object->getSheet(4);
|
$this->expectException(ssException::class);
|
||||||
|
$spreadsheet->getSheet(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetIndexNonExistent(): void
|
public function testGetIndexNonExistent(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
|
$this->expectException(ssException::class);
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet4');
|
$sheet->setTitle('someSheet4');
|
||||||
$this->object->getIndex($sheet);
|
$spreadsheet->getIndex($sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetIndexByName(): void
|
public function testSetIndexByName(): void
|
||||||
{
|
{
|
||||||
$this->object->setIndexByName('someSheet1', 1);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
self::assertEquals('someSheet2', $this->object->getSheet(0)->getTitle());
|
$spreadsheet->setIndexByName('someSheet1', 1);
|
||||||
self::assertEquals('someSheet1', $this->object->getSheet(1)->getTitle());
|
self::assertEquals('someSheet2', $spreadsheet->getSheet(0)->getTitle());
|
||||||
self::assertEquals('someSheet 3', $this->object->getSheet(2)->getTitle());
|
self::assertEquals('someSheet1', $spreadsheet->getSheet(1)->getTitle());
|
||||||
|
self::assertEquals('someSheet 3', $spreadsheet->getSheet(2)->getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveAllSheets(): void
|
public function testRemoveAllSheets(): void
|
||||||
{
|
{
|
||||||
$this->object->setActiveSheetIndex(2);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
self::assertEquals(2, $this->object->getActiveSheetIndex());
|
$spreadsheet->setActiveSheetIndex(2);
|
||||||
$this->object->removeSheetByIndex(0);
|
self::assertEquals(2, $spreadsheet->getActiveSheetIndex());
|
||||||
self::assertEquals(1, $this->object->getActiveSheetIndex());
|
$spreadsheet->removeSheetByIndex(0);
|
||||||
$this->object->removeSheetByIndex(0);
|
self::assertEquals(1, $spreadsheet->getActiveSheetIndex());
|
||||||
self::assertEquals(0, $this->object->getActiveSheetIndex());
|
$spreadsheet->removeSheetByIndex(0);
|
||||||
$this->object->removeSheetByIndex(0);
|
self::assertEquals(0, $spreadsheet->getActiveSheetIndex());
|
||||||
self::assertEquals(-1, $this->object->getActiveSheetIndex());
|
$spreadsheet->removeSheetByIndex(0);
|
||||||
|
self::assertEquals(-1, $spreadsheet->getActiveSheetIndex());
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet4');
|
$sheet->setTitle('someSheet4');
|
||||||
$this->object->addSheet($sheet);
|
$spreadsheet->addSheet($sheet);
|
||||||
self::assertEquals(0, $this->object->getActiveSheetIndex());
|
self::assertEquals(0, $spreadsheet->getActiveSheetIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBug1735(): void
|
public function testBug1735(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet1 = new Spreadsheet();
|
||||||
$spreadsheet->createSheet()->setTitle('addedsheet');
|
$spreadsheet1->createSheet()->setTitle('addedsheet');
|
||||||
$spreadsheet->setActiveSheetIndex(1);
|
$spreadsheet1->setActiveSheetIndex(1);
|
||||||
$spreadsheet->removeSheetByIndex(0);
|
$spreadsheet1->removeSheetByIndex(0);
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
$sheet = $spreadsheet1->getActiveSheet();
|
||||||
self::assertEquals('addedsheet', $sheet->getTitle());
|
self::assertEquals('addedsheet', $sheet->getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetActiveSheetIndexTooHigh(): void
|
public function testSetActiveSheetIndexTooHigh(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
$this->object->setActiveSheetIndex(4);
|
$this->expectException(ssException::class);
|
||||||
|
$spreadsheet->setActiveSheetIndex(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetActiveSheetNoSuchName(): void
|
public function testSetActiveSheetNoSuchName(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
$this->object->setActiveSheetIndexByName('unknown');
|
$this->expectException(ssException::class);
|
||||||
|
$spreadsheet->setActiveSheetIndexByName('unknown');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddExternal(): void
|
public function testAddExternal(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
$sheet = $spreadsheet->createSheet()->setTitle('someSheet19');
|
$spreadsheet1 = new Spreadsheet();
|
||||||
|
$sheet = $spreadsheet1->createSheet()->setTitle('someSheet19');
|
||||||
$sheet->getCell('A1')->setValue(1);
|
$sheet->getCell('A1')->setValue(1);
|
||||||
$sheet->getCell('A1')->getStyle()->getFont()->setBold(true);
|
$sheet->getCell('A1')->getStyle()->getFont()->setBold(true);
|
||||||
$sheet->getCell('B1')->getStyle()->getFont()->setSuperscript(true);
|
$sheet->getCell('B1')->getStyle()->getFont()->setSuperscript(true);
|
||||||
$sheet->getCell('C1')->getStyle()->getFont()->setSubscript(true);
|
$sheet->getCell('C1')->getStyle()->getFont()->setSubscript(true);
|
||||||
self::assertCount(4, $spreadsheet->getCellXfCollection());
|
self::assertCount(4, $spreadsheet1->getCellXfCollection());
|
||||||
self::assertEquals(1, $sheet->getCell('A1')->getXfIndex());
|
self::assertEquals(1, $sheet->getCell('A1')->getXfIndex());
|
||||||
$this->object->getActiveSheet()->getCell('A1')->getStyle()->getFont()->setBold(true);
|
$spreadsheet->getActiveSheet()->getCell('A1')->getStyle()->getFont()->setBold(true);
|
||||||
self::assertCount(2, $this->object->getCellXfCollection());
|
self::assertCount(2, $spreadsheet->getCellXfCollection());
|
||||||
$sheet3 = $this->object->addExternalSheet($sheet);
|
$sheet3 = $spreadsheet->addExternalSheet($sheet);
|
||||||
self::assertCount(6, $this->object->getCellXfCollection());
|
self::assertCount(6, $spreadsheet->getCellXfCollection());
|
||||||
self::assertEquals('someSheet19', $sheet3->getTitle());
|
self::assertEquals('someSheet19', $sheet3->getTitle());
|
||||||
self::assertEquals(1, $sheet3->getCell('A1')->getValue());
|
self::assertEquals(1, $sheet3->getCell('A1')->getValue());
|
||||||
self::assertTrue($sheet3->getCell('A1')->getStyle()->getFont()->getBold());
|
self::assertTrue($sheet3->getCell('A1')->getStyle()->getFont()->getBold());
|
||||||
|
|
@ -181,17 +210,17 @@ class SpreadsheetTest extends TestCase
|
||||||
|
|
||||||
public function testAddExternalDuplicateName(): void
|
public function testAddExternalDuplicateName(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$this->expectException(ssException::class);
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
$sheet = $spreadsheet->createSheet()->setTitle('someSheet1');
|
$sheet = $spreadsheet->createSheet()->setTitle('someSheet1');
|
||||||
$sheet->getCell('A1')->setValue(1);
|
$sheet->getCell('A1')->setValue(1);
|
||||||
$sheet->getCell('A1')->getStyle()->getFont()->setBold(true);
|
$sheet->getCell('A1')->getStyle()->getFont()->setBold(true);
|
||||||
$this->object->addExternalSheet($sheet);
|
$spreadsheet->addExternalSheet($sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddExternalColumnDimensionStyles(): void
|
public function testAddExternalColumnDimensionStyles(): void
|
||||||
{
|
{
|
||||||
$spreadsheet1 = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet1 = new Spreadsheet();
|
||||||
$sheet1 = $spreadsheet1->createSheet()->setTitle('sheetWithColumnDimension');
|
$sheet1 = $spreadsheet1->createSheet()->setTitle('sheetWithColumnDimension');
|
||||||
$sheet1->getCell('A1')->setValue(1);
|
$sheet1->getCell('A1')->setValue(1);
|
||||||
$sheet1->getCell('A1')->getStyle()->getFont()->setItalic(true);
|
$sheet1->getCell('A1')->getStyle()->getFont()->setItalic(true);
|
||||||
|
|
@ -200,7 +229,7 @@ class SpreadsheetTest extends TestCase
|
||||||
self::assertEquals(1, $index);
|
self::assertEquals(1, $index);
|
||||||
self::assertCount(2, $spreadsheet1->getCellXfCollection());
|
self::assertCount(2, $spreadsheet1->getCellXfCollection());
|
||||||
|
|
||||||
$spreadsheet2 = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet2 = new Spreadsheet();
|
||||||
$sheet2 = $spreadsheet2->createSheet()->setTitle('sheetWithTwoStyles');
|
$sheet2 = $spreadsheet2->createSheet()->setTitle('sheetWithTwoStyles');
|
||||||
$sheet2->getCell('A1')->setValue(1);
|
$sheet2->getCell('A1')->setValue(1);
|
||||||
$sheet2->getCell('A1')->getStyle()->getFont()->setBold(true);
|
$sheet2->getCell('A1')->getStyle()->getFont()->setBold(true);
|
||||||
|
|
@ -220,7 +249,7 @@ class SpreadsheetTest extends TestCase
|
||||||
|
|
||||||
public function testAddExternalRowDimensionStyles(): void
|
public function testAddExternalRowDimensionStyles(): void
|
||||||
{
|
{
|
||||||
$spreadsheet1 = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet1 = new Spreadsheet();
|
||||||
$sheet1 = $spreadsheet1->createSheet()->setTitle('sheetWithColumnDimension');
|
$sheet1 = $spreadsheet1->createSheet()->setTitle('sheetWithColumnDimension');
|
||||||
$sheet1->getCell('A1')->setValue(1);
|
$sheet1->getCell('A1')->setValue(1);
|
||||||
$sheet1->getCell('A1')->getStyle()->getFont()->setItalic(true);
|
$sheet1->getCell('A1')->getStyle()->getFont()->setItalic(true);
|
||||||
|
|
@ -229,7 +258,7 @@ class SpreadsheetTest extends TestCase
|
||||||
self::assertEquals(1, $index);
|
self::assertEquals(1, $index);
|
||||||
self::assertCount(2, $spreadsheet1->getCellXfCollection());
|
self::assertCount(2, $spreadsheet1->getCellXfCollection());
|
||||||
|
|
||||||
$spreadsheet2 = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet2 = new Spreadsheet();
|
||||||
$sheet2 = $spreadsheet2->createSheet()->setTitle('sheetWithTwoStyles');
|
$sheet2 = $spreadsheet2->createSheet()->setTitle('sheetWithTwoStyles');
|
||||||
$sheet2->getCell('A1')->setValue(1);
|
$sheet2->getCell('A1')->setValue(1);
|
||||||
$sheet2->getCell('A1')->getStyle()->getFont()->setBold(true);
|
$sheet2->getCell('A1')->getStyle()->getFont()->setBold(true);
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,12 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Style\ConditionalFormatting;
|
namespace PhpOffice\PhpSpreadsheetTests\Style\ConditionalFormatting;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Exception as ssException;
|
||||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\CellMatcher;
|
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\CellMatcher;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class CellMatcherTest extends TestCase
|
class CellMatcherTest extends TestCase
|
||||||
|
|
@ -30,18 +33,26 @@ class CellMatcherTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function confirmString(Worksheet $worksheet, Cell $cell, string $cellAddress): string
|
||||||
|
{
|
||||||
|
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate()) ?? '';
|
||||||
|
if ($cfRange === '') {
|
||||||
|
self::fail("{$cellAddress} is not in a Conditional Format range");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cfRange;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider basicCellIsComparisonDataProvider
|
* @dataProvider basicCellIsComparisonDataProvider
|
||||||
*/
|
*/
|
||||||
public function testBasicCellIsComparison(string $sheetname, string $cellAddress, array $expectedMatches): void
|
public function testBasicCellIsComparison(string $sheetname, string $cellAddress, array $expectedMatches): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "{$cellAddress} is not in a Conditional Format range");
|
|
||||||
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -83,18 +94,35 @@ class CellMatcherTest extends TestCase
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNotInRange(): void
|
||||||
|
{
|
||||||
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
|
$sheetname = 'cellIs Comparison';
|
||||||
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
|
$cell = $worksheet->getCell('J20');
|
||||||
|
|
||||||
|
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
||||||
|
self::assertNull($cfRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUnknownSheet(): void
|
||||||
|
{
|
||||||
|
$this->expectException(ssException::class);
|
||||||
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
|
$sheetname = 'cellIs Comparisonxxx';
|
||||||
|
$this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider rangeCellIsComparisonDataProvider
|
* @dataProvider rangeCellIsComparisonDataProvider
|
||||||
*/
|
*/
|
||||||
public function testRangeCellIsComparison(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
public function testRangeCellIsComparison(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -132,12 +160,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testCellIsMultipleExpression(string $sheetname, string $cellAddress, array $expectedMatches): void
|
public function testCellIsMultipleExpression(string $sheetname, string $cellAddress, array $expectedMatches): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -168,12 +194,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testCellIsExpression(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
public function testCellIsExpression(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -214,12 +238,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testTextExpressions(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
public function testTextExpressions(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -324,12 +346,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testBlankExpressions(string $sheetname, string $cellAddress, array $expectedMatches): void
|
public function testBlankExpressions(string $sheetname, string $cellAddress, array $expectedMatches): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -357,12 +377,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testErrorExpressions(string $sheetname, string $cellAddress, array $expectedMatches): void
|
public function testErrorExpressions(string $sheetname, string $cellAddress, array $expectedMatches): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -389,12 +407,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testDateOccurringExpressions(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
public function testDateOccurringExpressions(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -433,12 +449,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testDuplicatesExpressions(string $sheetname, string $cellAddress, array $expectedMatches): void
|
public function testDuplicatesExpressions(string $sheetname, string $cellAddress, array $expectedMatches): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::AssertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -469,12 +483,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testCrossWorksheetExpressions(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
public function testCrossWorksheetExpressions(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ class WizardFactoryTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @dataProvider basicWizardFactoryProvider
|
* @dataProvider basicWizardFactoryProvider
|
||||||
*
|
*
|
||||||
* @param class-string<object> $expectedWizard
|
* @psalm-param class-string<object> $expectedWizard
|
||||||
*/
|
*/
|
||||||
public function testBasicWizardFactory(string $ruleType, $expectedWizard): void
|
public function testBasicWizardFactory(string $ruleType, string $expectedWizard): void
|
||||||
{
|
{
|
||||||
$wizard = $this->wizardFactory->newRule($ruleType);
|
$wizard = $this->wizardFactory->newRule($ruleType);
|
||||||
self::assertInstanceOf($expectedWizard, $wizard);
|
self::assertInstanceOf($expectedWizard, $wizard);
|
||||||
|
|
@ -54,10 +54,7 @@ class WizardFactoryTest extends TestCase
|
||||||
$filename = 'tests/data/Style/ConditionalFormatting/CellMatcher.xlsx';
|
$filename = 'tests/data/Style/ConditionalFormatting/CellMatcher.xlsx';
|
||||||
$reader = IOFactory::createReader('Xlsx');
|
$reader = IOFactory::createReader('Xlsx');
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
$worksheet = $spreadsheet->getSheetByName($sheetName);
|
$worksheet = $spreadsheet->getSheetByNameOrThrow($sheetName);
|
||||||
if ($worksheet === null) {
|
|
||||||
self::markTestSkipped("{$sheetName} not found in test workbook");
|
|
||||||
}
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ class VisibilityTest extends AbstractFunctional
|
||||||
|
|
||||||
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xls');
|
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xls');
|
||||||
foreach ($visibleSheets as $sheetName => $visibility) {
|
foreach ($visibleSheets as $sheetName => $visibility) {
|
||||||
$reloadedWorksheet = $reloadedSpreadsheet->getSheetByName($sheetName) ?? new Worksheet();
|
$reloadedWorksheet = $reloadedSpreadsheet->getSheetByNameOrThrow($sheetName);
|
||||||
self::assertSame($visibility, $reloadedWorksheet->getSheetState());
|
self::assertSame($visibility, $reloadedWorksheet->getSheetState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,19 +77,15 @@ class UnparsedDataCloneTest extends TestCase
|
||||||
$reader1 = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
$reader1 = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||||||
$spreadsheet1 = $reader1->load($resultFilename1);
|
$spreadsheet1 = $reader1->load($resultFilename1);
|
||||||
unlink($resultFilename1);
|
unlink($resultFilename1);
|
||||||
$sheet1c = $spreadsheet1->getSheetByName('Clone');
|
$sheet1c = $spreadsheet1->getSheetByNameOrThrow('Clone');
|
||||||
self::assertNotNull($sheet1c);
|
$sheet1o = $spreadsheet1->getSheetByNameOrThrow('Original');
|
||||||
$sheet1o = $spreadsheet1->getSheetByName('Original');
|
|
||||||
self::assertNotNull($sheet1o);
|
|
||||||
|
|
||||||
$writer->save($resultFilename2);
|
$writer->save($resultFilename2);
|
||||||
$reader2 = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
$reader2 = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||||||
$spreadsheet2 = $reader2->load($resultFilename2);
|
$spreadsheet2 = $reader2->load($resultFilename2);
|
||||||
unlink($resultFilename2);
|
unlink($resultFilename2);
|
||||||
$sheet2c = $spreadsheet2->getSheetByName('Clone');
|
$sheet2c = $spreadsheet2->getSheetByNameOrThrow('Clone');
|
||||||
self::assertNotNull($sheet2c);
|
$sheet2o = $spreadsheet2->getSheetByNameOrThrow('Original');
|
||||||
$sheet2o = $spreadsheet2->getSheetByName('Original');
|
|
||||||
self::assertNotNull($sheet2o);
|
|
||||||
|
|
||||||
self::assertEquals($spreadsheet1->getSheetCount(), $spreadsheet2->getSheetCount());
|
self::assertEquals($spreadsheet1->getSheetCount(), $spreadsheet2->getSheetCount());
|
||||||
self::assertCount(1, $sheet1c->getDrawingCollection());
|
self::assertCount(1, $sheet1c->getDrawingCollection());
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ class VisibilityTest extends AbstractFunctional
|
||||||
|
|
||||||
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
|
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
|
||||||
foreach ($visibleSheets as $sheetName => $visibility) {
|
foreach ($visibleSheets as $sheetName => $visibility) {
|
||||||
$reloadedWorksheet = $reloadedSpreadsheet->getSheetByName($sheetName) ?? new Worksheet();
|
$reloadedWorksheet = $reloadedSpreadsheet->getSheetByNameOrThrow($sheetName);
|
||||||
self::assertSame($visibility, $reloadedWorksheet->getSheetState());
|
self::assertSame($visibility, $reloadedWorksheet->getSheetState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,4 +83,5 @@ return [
|
||||||
-21000,
|
-21000,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
'no arguments' => ['exception'],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue