Skip to content

Commit

Permalink
Merge pull request #2171 from oleibman/xlsxtest2
Browse files Browse the repository at this point in the history
Move Reader Xlsx Tests from Reader to Reader/Xlsx Try 2
  • Loading branch information
oleibman authored Jun 18, 2021
2 parents 16d0075 + 83c0f02 commit 33ef03d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 47 deletions.
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7205,16 +7205,6 @@ parameters:
count: 1
path: tests/PhpSpreadsheetTests/Reader/Xlsx/AutoFilterTest.php

-
message: "#^Function PhpOffice\\\\PhpSpreadsheetTests\\\\Reader\\\\getTitleText\\(\\) has no return typehint specified\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Reader/Xlsx/ChartsTitleTest.php

-
message: "#^Function PhpOffice\\\\PhpSpreadsheetTests\\\\Reader\\\\getTitleText\\(\\) has parameter \\$title with no typehint specified\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Reader/Xlsx/ChartsTitleTest.php

-
message: "#^Cannot call method setMinimumConditionalFormatValueObject\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\ConditionalFormatting\\\\ConditionalDataBar\\|null\\.$#"
count: 1
Expand Down Expand Up @@ -7245,11 +7235,6 @@ parameters:
count: 1
path: tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalFormattingDataBarXlsxTest.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheetTests\\\\Reader\\\\XlsxTest\\:\\:testStripsWhiteSpaceFromStyleString\\(\\) has parameter \\$string with no typehint specified\\.$#"
count: 1
path: tests/PhpSpreadsheetTests/Reader/XlsxTest.php

-
message: "#^Method PhpOffice\\\\PhpSpreadsheetTests\\\\Reader\\\\Xml\\\\XmlTest\\:\\:testInvalidSimpleXML\\(\\) has parameter \\$filename with no typehint specified\\.$#"
count: 1
Expand Down
53 changes: 27 additions & 26 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/ChartsTitleTest.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader;
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PHPUnit\Framework\TestCase;

function getTitleText($title)
class ChartsTitleTest extends TestCase
{
if (null === $title || null === $title->getCaption()) {
return null;
}
private static function getTitleText(?Title $title): ?string
{
if (null === $title || empty($title->getCaption())) {
return null;
}

return implode("\n", array_map(function ($rt) {
return $rt->getPlainText();
}, $title->getCaption()));
}
return implode("\n", array_map(function ($rt) {
return $rt->getPlainText();
}, $title->getCaption())); // @phpstan-ignore-line
}

class ChartsTitleTest extends TestCase
{
public function testChartTitles(): void
{
$filename = 'tests/data/Reader/XLSX/excelChartsTest.xlsx';
Expand All @@ -31,34 +32,34 @@ public function testChartTitles(): void

// No title or axis labels
$chart1 = $charts[0];
$title = getTitleText($chart1->getTitle());
$title = self::getTitleText($chart1->getTitle());
self::assertEmpty($title);
self::assertEmpty(getTitleText($chart1->getXAxisLabel()));
self::assertEmpty(getTitleText($chart1->getYAxisLabel()));
self::assertEmpty(self::getTitleText($chart1->getXAxisLabel()));
self::assertEmpty(self::getTitleText($chart1->getYAxisLabel()));

// Title, no axis labels
$chart2 = $charts[1];

self::assertEquals('Chart with Title and no Axis Labels', getTitleText($chart2->getTitle()));
self::assertEmpty(getTitleText($chart2->getXAxisLabel()));
self::assertEmpty(getTitleText($chart2->getYAxisLabel()));
self::assertEquals('Chart with Title and no Axis Labels', self::getTitleText($chart2->getTitle()));
self::assertEmpty(self::getTitleText($chart2->getXAxisLabel()));
self::assertEmpty(self::getTitleText($chart2->getYAxisLabel()));

// No title, only horizontal axis label
$chart3 = $charts[2];
self::assertEmpty(getTitleText($chart3->getTitle()));
self::assertEquals('Horizontal Axis Title Only', getTitleText($chart3->getXAxisLabel()));
self::assertEmpty(getTitleText($chart3->getYAxisLabel()));
self::assertEmpty(self::getTitleText($chart3->getTitle()));
self::assertEquals('Horizontal Axis Title Only', self::getTitleText($chart3->getXAxisLabel()));
self::assertEmpty(self::getTitleText($chart3->getYAxisLabel()));

// No title, only vertical axis label
$chart4 = $charts[3];
self::assertEmpty(getTitleText($chart4->getTitle()));
self::assertEquals('Vertical Axis Title Only', getTitleText($chart4->getYAxisLabel()));
self::assertEmpty(getTitleText($chart4->getXAxisLabel()));
self::assertEmpty(self::getTitleText($chart4->getTitle()));
self::assertEquals('Vertical Axis Title Only', self::getTitleText($chart4->getYAxisLabel()));
self::assertEmpty(self::getTitleText($chart4->getXAxisLabel()));

// Title and both axis labels
$chart5 = $charts[4];
self::assertEquals('Complete Annotations', getTitleText($chart5->getTitle()));
self::assertEquals('Horizontal Axis Title', getTitleText($chart5->getXAxisLabel()));
self::assertEquals('Vertical Axis Title', getTitleText($chart5->getYAxisLabel()));
self::assertEquals('Complete Annotations', self::getTitleText($chart5->getTitle()));
self::assertEquals('Horizontal Axis Title', self::getTitleText($chart5->getXAxisLabel()));
self::assertEquals('Vertical Axis Title', self::getTitleText($chart5->getYAxisLabel()));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader;
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader;
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader;
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\IOFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader;
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Shared\File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader;
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
Expand Down Expand Up @@ -237,7 +237,7 @@ public function testLoadSaveWithEmptyDrawings(): void
*
* @dataProvider providerStripsWhiteSpaceFromStyleString
*/
public function testStripsWhiteSpaceFromStyleString($string): void
public function testStripsWhiteSpaceFromStyleString(string $string): void
{
$string = Xlsx::stripWhiteSpaceFromStyleString($string);
self::assertEquals(preg_match('/\s/', $string), 0);
Expand Down

0 comments on commit 33ef03d

Please sign in to comment.