Add phpstan until level 7

This commit is contained in:
Antoine Lamirault committed 2021-09-18 18:09:14 +02:00
1 parent ab973cab34
commit bfb7c2c68f
114 files changed
+527 -319

No files matched your search

+11 -4
View File
@@ -3,23 +3,30 @@
namespace Box\Spout\Common\Entity;
use Box\Spout\Common\Entity\Style\Style;
use PHPUnit\Framework\MockObject\MockObject;
class RowTest extends \PHPUnit\Framework\TestCase
{
/**
* @return \PHPUnit_Framework_MockObject_MockObject|Style
* @return Style&MockObject
*/
private function getStyleMock()
{
return $this->createMock(Style::class);
/** @var Style&MockObject $styleMock */
$styleMock = $this->createMock(Style::class);
return $styleMock;
}
/**
* @return \PHPUnit_Framework_MockObject_MockObject|Cell
* @return Cell&MockObject
*/
private function getCellMock()
{
return $this->createMock(Cell::class);
/** @var Cell&MockObject $cellMock */
$cellMock = $this->createMock(Cell::class);
return $cellMock;
}
/**
@@ -113,7 +113,7 @@ class BorderTest extends TestCase
$border->addPart($borderPart);
$this->assertCount(1, $border->getParts());
/** @var $part BorderPart */
/** @var BorderPart $part */
$part = $border->getParts()[$allowedName];
$this->assertEquals($allowedStyle, $part->getStyle());
@@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase;
class ColorTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestRGB()
{
@@ -54,7 +54,7 @@ class ColorTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestRGBAInvalidColorComponents()
{
@@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase;
class CellTypeHelperTest extends TestCase
{
/**
* @return array
* @return void
*/
public function testIsEmpty()
{
@@ -27,7 +27,7 @@ class CellTypeHelperTest extends TestCase
}
/**
* @return array
* @return void
*/
public function testIsNonEmptyString()
{
@@ -44,7 +44,7 @@ class CellTypeHelperTest extends TestCase
}
/**
* @return array
* @return void
*/
public function testIsNumeric()
{
@@ -66,7 +66,7 @@ class CellTypeHelperTest extends TestCase
}
/**
* @return array
* @return void
*/
public function testIsBoolean()
{
@@ -4,6 +4,7 @@ namespace Box\Spout\Common\Helper;
use Box\Spout\Common\Exception\EncodingConversionException;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
@@ -14,7 +15,7 @@ class EncodingHelperTest extends TestCase
use TestUsingResource;
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestGetBytesOffsetToSkipBOM()
{
@@ -38,6 +39,7 @@ class EncodingHelperTest extends TestCase
public function testGetBytesOffsetToSkipBOM($fileName, $encoding, $expectedBytesOffset)
{
$resourcePath = $this->getResourcePath($fileName);
/** @var resource $filePointer */
$filePointer = fopen($resourcePath, 'r');
$encodingHelper = new EncodingHelper(new GlobalFunctionsHelper());
@@ -47,7 +49,7 @@ class EncodingHelperTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForIconvOrMbstringUsage()
{
@@ -73,7 +75,7 @@ class EncodingHelperTest extends TestCase
$helperStub->method('iconv')->willReturn(false);
$helperStub->method('mb_convert_encoding')->willReturn(false);
/** @var EncodingHelper $encodingHelperStub */
/** @var EncodingHelper&MockObject $encodingHelperStub */
$encodingHelperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\EncodingHelper')
->setConstructorArgs([$helperStub])
->setMethods(['canUseIconv', 'canUseMbString'])
@@ -91,7 +93,7 @@ class EncodingHelperTest extends TestCase
{
$this->expectException(EncodingConversionException::class);
/** @var EncodingHelper $encodingHelperStub */
/** @var EncodingHelper&MockObject $encodingHelperStub */
$encodingHelperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\EncodingHelper')
->disableOriginalConstructor()
->setMethods(['canUseIconv', 'canUseMbString'])
@@ -110,7 +112,7 @@ class EncodingHelperTest extends TestCase
*/
public function testAttemptConversionToUTF8ShouldReturnReencodedString($shouldUseIconv)
{
/** @var EncodingHelper $encodingHelperStub */
/** @var EncodingHelper&MockObject $encodingHelperStub */
$encodingHelperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\EncodingHelper')
->setConstructorArgs([new GlobalFunctionsHelper()])
->setMethods(['canUseIconv', 'canUseMbString'])
@@ -118,6 +120,7 @@ class EncodingHelperTest extends TestCase
$encodingHelperStub->method('canUseIconv')->willReturn($shouldUseIconv);
$encodingHelperStub->method('canUseMbString')->willReturn(true);
/** @var string $encodedString */
$encodedString = iconv(EncodingHelper::ENCODING_UTF8, EncodingHelper::ENCODING_UTF16_LE, 'input');
$decodedString = $encodingHelperStub->attemptConversionToUTF8($encodedString, EncodingHelper::ENCODING_UTF16_LE);
@@ -129,7 +132,7 @@ class EncodingHelperTest extends TestCase
*/
public function testAttemptConversionToUTF8ShouldBeNoopWhenTargetIsUTF8()
{
/** @var EncodingHelper $encodingHelperStub */
/** @var EncodingHelper&MockObject $encodingHelperStub */
$encodingHelperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\EncodingHelper')
->disableOriginalConstructor()
->setMethods(['canUseIconv'])
@@ -156,7 +159,7 @@ class EncodingHelperTest extends TestCase
$helperStub->method('iconv')->willReturn(false);
$helperStub->method('mb_convert_encoding')->willReturn(false);
/** @var EncodingHelper $encodingHelperStub */
/** @var EncodingHelper&MockObject $encodingHelperStub */
$encodingHelperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\EncodingHelper')
->setConstructorArgs([$helperStub])
->setMethods(['canUseIconv', 'canUseMbString'])
@@ -174,7 +177,7 @@ class EncodingHelperTest extends TestCase
{
$this->expectException(EncodingConversionException::class);
/** @var EncodingHelper $encodingHelperStub */
/** @var EncodingHelper&MockObject $encodingHelperStub */
$encodingHelperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\EncodingHelper')
->disableOriginalConstructor()
->setMethods(['canUseIconv', 'canUseMbString'])
@@ -193,7 +196,7 @@ class EncodingHelperTest extends TestCase
*/
public function testAttemptConversionFromUTF8ShouldReturnReencodedString($shouldUseIconv)
{
/** @var EncodingHelper $encodingHelperStub */
/** @var EncodingHelper&MockObject $encodingHelperStub */
$encodingHelperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\EncodingHelper')
->setConstructorArgs([new GlobalFunctionsHelper()])
->setMethods(['canUseIconv', 'canUseMbString'])
@@ -212,7 +215,7 @@ class EncodingHelperTest extends TestCase
*/
public function testAttemptConversionFromUTF8ShouldBeNoopWhenTargetIsUTF8()
{
/** @var EncodingHelper $encodingHelperStub */
/** @var EncodingHelper&MockObject $encodingHelperStub */
$encodingHelperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\EncodingHelper')
->disableOriginalConstructor()
->setMethods(['canUseIconv'])
@@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase;
class ODSTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestEscape()
{
@@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase;
class XLSXTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestEscape()
{
@@ -46,7 +46,7 @@ class XLSXTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestUnescape()
{
@@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase;
*/
class FileSystemHelperTest extends TestCase
{
/** @var \Box\Spout\Writer\XLSX\Helper\FileSystemHelper */
/** @var FileSystemHelper */
protected $fileSystemHelper;
/**
@@ -14,10 +14,13 @@ class OptionsManagerTest extends TestCase
*/
protected $optionsManager;
protected function setUp()
protected function setUp() : void
{
$this->optionsManager = new class() extends OptionsManagerAbstract {
protected function getSupportedOptions()
/**
* @return string[]
*/
protected function getSupportedOptions() : array
{
return [
'foo',
+11 -9
View File
@@ -6,11 +6,13 @@ use Box\Spout\Common\Creator\HelperFactory;
use Box\Spout\Common\Exception\IOException;
use Box\Spout\Common\Helper\EncodingHelper;
use Box\Spout\Common\Helper\GlobalFunctionsHelper;
use Box\Spout\Common\Manager\OptionsManagerInterface;
use Box\Spout\Reader\CSV\Creator\InternalEntityFactory;
use Box\Spout\Reader\CSV\Manager\OptionsManager;
use Box\Spout\Reader\Exception\ReaderNotOpenedException;
use Box\Spout\Reader\ReaderInterface;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
@@ -47,7 +49,7 @@ class ReaderTest extends TestCase
{
$this->expectException(IOException::class);
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper|\PHPUnit_Framework_MockObject_MockObject $helperStub */
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper&MockObject $helperStub */
$helperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\GlobalFunctionsHelper')
->setMethods(['is_readable'])
->getMock();
@@ -66,7 +68,7 @@ class ReaderTest extends TestCase
{
$this->expectException(IOException::class);
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper|\PHPUnit_Framework_MockObject_MockObject $helperStub */
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper&MockObject $helperStub */
$helperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\GlobalFunctionsHelper')
->setMethods(['fopen'])
->getMock();
@@ -159,7 +161,7 @@ class ReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadShouldReadEmptyFile()
{
@@ -241,7 +243,7 @@ class ReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadShouldSkipBom()
{
@@ -274,7 +276,7 @@ class ReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadShouldSupportNonUTF8FilesWithoutBOMs()
{
@@ -302,7 +304,7 @@ class ReaderTest extends TestCase
$allRows = [];
$resourcePath = $this->getResourcePath($fileName);
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper|\PHPUnit_Framework_MockObject_MockObject $helperStub */
/** @var \Box\Spout\Common\Helper\GlobalFunctionsHelper&MockObject $helperStub */
$helperStub = $this->getMockBuilder('\Box\Spout\Common\Helper\GlobalFunctionsHelper')
->setMethods(['function_exists'])
->getMock();
@@ -475,8 +477,8 @@ class ReaderTest extends TestCase
}
/**
* @param \Box\Spout\Common\Helper\GlobalFunctionsHelper|null $optionsManager
* @param \Box\Spout\Common\Manager\OptionsManagerInterface|null $globalFunctionsHelper
* @param OptionsManagerInterface|null $optionsManager
* @param GlobalFunctionsHelper|null $globalFunctionsHelper
* @return ReaderInterface
*/
private function createCSVReader($optionsManager = null, $globalFunctionsHelper = null)
@@ -494,7 +496,7 @@ class ReaderTest extends TestCase
* @param string $fieldEnclosure
* @param string $encoding
* @param bool $shouldPreserveEmptyRows
* @return array All the read rows the given file
* @return array<array> All the read rows the given file
*/
private function getAllRowsForFile(
$fileName,
+2 -1
View File
@@ -3,6 +3,7 @@
namespace Box\Spout\Reader\CSV;
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
use Box\Spout\Reader\SheetInterface;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\TestCase;
@@ -27,7 +28,7 @@ class SheetTest extends TestCase
/**
* @param string $fileName
* @return Sheet
* @return SheetInterface
*/
private function openFileAndReturnSheet($fileName)
{
+16 -6
View File
@@ -14,22 +14,25 @@ class SpoutTestStream
const PATH_TO_CSV_RESOURCES = 'tests/resources/csv/';
const CSV_EXTENSION = '.csv';
/** @var int $position */
/** @var int */
private $position;
/** @var resource $fileHandle */
/** @var resource */
private $fileHandle;
/**
* @param string $path
* @param int $flag
* @return array
* @return array<mixed>
*/
public function url_stat($path, $flag)
{
$filePath = $this->getFilePathFromStreamPath($path);
return stat($filePath);
/** @var array<mixed> $stat */
$stat = stat($filePath);
return $stat;
}
/**
@@ -56,7 +59,11 @@ class SpoutTestStream
// the path is like "spout://csv_name" so the actual file name correspond the name of the host.
$filePath = $this->getFilePathFromStreamPath($path);
$this->fileHandle = fopen($filePath, $mode);
/** @var resource $fileHandle */
$fileHandle = fopen($filePath, $mode);
$this->fileHandle = $fileHandle;
return true;
}
@@ -69,7 +76,10 @@ class SpoutTestStream
{
$this->position += $numBytes;
return fread($this->fileHandle, $numBytes);
/** @var string $read */
$read = fread($this->fileHandle, $numBytes);
return $read;
}
/**
@@ -15,7 +15,7 @@ use PHPUnit\Framework\TestCase;
class RowManagerTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestFillMissingIndexesWithEmptyCells()
{
@@ -34,7 +34,7 @@ class RowManagerTest extends TestCase
* @param Cell[]|null $rowCells
* @param Cell[] $expectedFilledCells
*/
public function testFillMissingIndexesWithEmptyCells($rowCells, $expectedFilledCells)
public function testFillMissingIndexesWithEmptyCells($rowCells, $expectedFilledCells) : void
{
$rowManager = $this->createRowManager();
@@ -48,7 +48,7 @@ class RowManagerTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestIsEmptyRow()
{
@@ -64,7 +64,7 @@ class RowManagerTest extends TestCase
/**
* @dataProvider dataProviderForTestIsEmptyRow
*
* @param array $cells
* @param array<Cell> $cells
* @param bool $expectedIsEmpty
* @return void
*/
@@ -81,10 +81,13 @@ class RowManagerTest extends TestCase
*/
private function createRowManager()
{
$entityFactory = new InternalEntityFactory(
$this->createMock(ManagerFactory::class),
$this->createMock(HelperFactory::class)
);
/** @var ManagerFactory $managerFactory */
$managerFactory = $this->createMock(ManagerFactory::class);
/** @var HelperFactory $helperFactory */
$helperFactory = $this->createMock(HelperFactory::class);
$entityFactory = new InternalEntityFactory($managerFactory, $helperFactory);
return new RowManager($entityFactory);
}
+4 -4
View File
@@ -16,7 +16,7 @@ class ReaderTest extends TestCase
use TestUsingResource;
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadShouldThrowException()
{
@@ -41,7 +41,7 @@ class ReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadForAllWorksheets()
{
@@ -109,7 +109,7 @@ class ReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadWithFilesGeneratedByExternalSoftwares()
{
@@ -530,7 +530,7 @@ class ReaderTest extends TestCase
* @param string $fileName
* @param bool $shouldFormatDates
* @param bool $shouldPreserveEmptyRows
* @return array All the read rows the given file
* @return array<array> All the read rows the given file
*/
private function getAllRowsForFile($fileName, $shouldFormatDates = false, $shouldPreserveEmptyRows = false)
{
+2 -1
View File
@@ -3,6 +3,7 @@
namespace Box\Spout\Reader\ODS;
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
use Box\Spout\Reader\SheetInterface;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\TestCase;
@@ -55,7 +56,7 @@ class SheetTest extends TestCase
/**
* @param string $fileName
* @return Sheet[]
* @return SheetInterface[]
*/
private function openFileAndReturnSheets($fileName)
{
+4 -3
View File
@@ -102,7 +102,7 @@ class XMLReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestFileExistsWithinZip()
{
@@ -134,10 +134,11 @@ class XMLReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestGetRealPathURIForFileInZip()
{
/** @var string $tempFolder */
$tempFolder = realpath(sys_get_temp_dir());
$tempFolderName = basename($tempFolder);
$expectedRealPathURI = 'zip://' . $tempFolder . '/test.xlsx#test.xml';
@@ -174,7 +175,7 @@ class XMLReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestIsPositionedOnStartingAndEndingNode()
{
@@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase;
class CellHelperTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestGetColumnIndexFromCellIndex()
{
@@ -4,7 +4,9 @@ namespace Box\Spout\Reader\XLSX\Helper;
use Box\Spout\Common\Helper\Escaper;
use Box\Spout\Reader\Exception\InvalidValueException;
use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
use Box\Spout\Reader\XLSX\Manager\StyleManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
@@ -13,7 +15,7 @@ use PHPUnit\Framework\TestCase;
class CellValueFormatterTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestExcelDate()
{
@@ -72,6 +74,7 @@ class CellValueFormatterTest extends TestCase
->with(0)
->will($this->returnValue((object) ['nodeValue' => $nodeValue]));
/** @var \DOMElement&MockObject $nodeMock */
$nodeMock = $this->createMock(\DOMElement::class);
$nodeMock
@@ -88,7 +91,7 @@ class CellValueFormatterTest extends TestCase
->with(CellValueFormatter::XML_NODE_VALUE)
->will($this->returnValue($nodeListMock));
/** @var StyleManager|\PHPUnit_Framework_MockObject_MockObject $styleManagerMock */
/** @var StyleManager&MockObject $styleManagerMock */
$styleManagerMock = $this->createMock(StyleManager::class);
$styleManagerMock
@@ -97,7 +100,10 @@ class CellValueFormatterTest extends TestCase
->with(123)
->will($this->returnValue(true));
$formatter = new CellValueFormatter(null, $styleManagerMock, false, $shouldUse1904Dates, new Escaper\XLSX());
/** @var SharedStringsManager $sharedStringManager */
$sharedStringManager = $this->createMock(SharedStringsManager::class);
$formatter = new CellValueFormatter($sharedStringManager, $styleManagerMock, false, $shouldUse1904Dates, new Escaper\XLSX());
try {
$result = $formatter->extractAndFormatNodeValue($nodeMock);
@@ -106,7 +112,9 @@ class CellValueFormatterTest extends TestCase
$this->fail('An exception should have been thrown');
} else {
$this->assertInstanceOf(\DateTime::class, $result);
$this->assertSame($expectedDateAsString, $result->format('Y-m-d H:i:s'));
/** @var \DateTime $datetime */
$datetime = $result;
$this->assertSame($expectedDateAsString, $datetime->format('Y-m-d H:i:s'));
}
} catch (InvalidValueException $exception) {
// do nothing
@@ -114,7 +122,7 @@ class CellValueFormatterTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestFormatNumericCellValueWithNumbers()
{
@@ -149,14 +157,17 @@ class CellValueFormatterTest extends TestCase
*/
public function testFormatNumericCellValueWithNumbers($value, $expectedFormattedValue, $expectedType)
{
/** @var StyleManager|\PHPUnit_Framework_MockObject_MockObject $styleManagerMock */
/** @var StyleManager&MockObject $styleManagerMock */
$styleManagerMock = $this->createMock(StyleManager::class);
$styleManagerMock
->expects($this->once())
->method('shouldFormatNumericValueAsDate')
->will($this->returnValue(false));
$formatter = new CellValueFormatter(null, $styleManagerMock, false, false, new Escaper\XLSX());
/** @var SharedStringsManager $sharedStringManager */
$sharedStringManager = $this->createMock(SharedStringsManager::class);
$formatter = new CellValueFormatter($sharedStringManager, $styleManagerMock, false, false, new Escaper\XLSX());
$formattedValue = \ReflectionHelper::callMethodOnObject($formatter, 'formatNumericCellValue', $value, 0);
$this->assertEquals($expectedFormattedValue, $formattedValue);
@@ -164,7 +175,7 @@ class CellValueFormatterTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestFormatStringCellValue()
{
@@ -199,7 +210,13 @@ class CellValueFormatterTest extends TestCase
->with(CellValueFormatter::XML_NODE_INLINE_STRING_VALUE)
->will($this->returnValue($nodeListMock));
$formatter = new CellValueFormatter(null, null, false, false, new Escaper\XLSX());
/** @var SharedStringsManager $sharedStringManager */
$sharedStringManager = $this->createMock(SharedStringsManager::class);
/** @var StyleManager $styleManager */
$styleManager = $this->createMock(StyleManager::class);
$formatter = new CellValueFormatter($sharedStringManager, $styleManager, false, false, new Escaper\XLSX());
$formattedValue = \ReflectionHelper::callMethodOnObject($formatter, 'formatInlineStringCellValue', $nodeMock);
$this->assertEquals($expectedFormattedValue, $formattedValue);
@@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase;
class DateFormatHelperTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestToPHPDateFormat()
{
@@ -3,6 +3,7 @@
namespace Box\Spout\Reader\XLSX\Manager\SharedStringsCaching;
use Box\Spout\Reader\XLSX\Creator\HelperFactory;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
@@ -11,7 +12,7 @@ use PHPUnit\Framework\TestCase;
class CachingStrategyFactoryTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestCreateBestCachingStrategy()
{
@@ -36,7 +37,7 @@ class CachingStrategyFactoryTest extends TestCase
*/
public function testCreateBestCachingStrategy($sharedStringsUniqueCount, $memoryLimitInKB, $expectedStrategyClassName)
{
/** @var CachingStrategyFactory|\PHPUnit_Framework_MockObject_MockObject $factoryStub */
/** @var CachingStrategyFactory&MockObject $factoryStub */
$factoryStub = $this
->getMockBuilder('\Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory')
->disableOriginalConstructor()
@@ -46,7 +47,7 @@ class CachingStrategyFactoryTest extends TestCase
$factoryStub->method('getMemoryLimitInKB')->willReturn($memoryLimitInKB);
$tempFolder = sys_get_temp_dir();
$helperFactory = new HelperFactory($factoryStub);
$helperFactory = new HelperFactory();
$strategy = $factoryStub->createBestCachingStrategy($sharedStringsUniqueCount, $tempFolder, $helperFactory);
$fullExpectedStrategyClassName = 'Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\\' . $expectedStrategyClassName;
@@ -56,7 +57,7 @@ class CachingStrategyFactoryTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestGetMemoryLimitInKB()
{
@@ -84,7 +85,7 @@ class CachingStrategyFactoryTest extends TestCase
*/
public function testGetMemoryLimitInKB($memoryLimitFormatted, $expectedMemoryLimitInKB)
{
/** @var CachingStrategyFactory|\PHPUnit_Framework_MockObject_MockObject $factoryStub */
/** @var CachingStrategyFactory&MockObject $factoryStub */
$factoryStub = $this
->getMockBuilder('\Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory')
->disableOriginalConstructor()
@@ -19,7 +19,7 @@ class SharedStringsManagerTest extends TestCase
{
use TestUsingResource;
/** @var SharedStringsManager */
/** @var SharedStringsManager|null */
private $sharedStringsManager;
/**
@@ -144,6 +144,7 @@ class SharedStringsManagerTest extends TestCase
public function testGetStringAtIndexWithFileBasedStrategy()
{
// force the file-based strategy by setting no memory limit
/** @var string $originalMemoryLimit */
$originalMemoryLimit = ini_get('memory_limit');
ini_set('memory_limit', '-1');
@@ -3,6 +3,7 @@
namespace Box\Spout\Reader\XLSX\Manager;
use Box\Spout\Reader\XLSX\Creator\InternalEntityFactory;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
@@ -11,8 +12,8 @@ use PHPUnit\Framework\TestCase;
class StyleManagerTest extends TestCase
{
/**
* @param array $styleAttributes
* @param array $customNumberFormats
* @param array<mixed> $styleAttributes
* @param array<mixed> $customNumberFormats
* @return StyleManager
*/
private function getStyleManagerMock($styleAttributes = [], $customNumberFormats = [])
@@ -21,7 +22,7 @@ class StyleManagerTest extends TestCase
$workbookRelationshipsManager = $this->createMock(WorkbookRelationshipsManager::class);
$workbookRelationshipsManager->method('hasStylesXMLFile')->willReturn(true);
/** @var StyleManager $styleManager */
/** @var StyleManager&MockObject $styleManager */
$styleManager = $this->getMockBuilder('\Box\Spout\Reader\XLSX\Manager\StyleManager')
->setConstructorArgs(['/path/to/file.xlsx', $workbookRelationshipsManager, $entityFactory])
->setMethods(['getCustomNumberFormats', 'getStylesAttributes'])
@@ -132,7 +133,7 @@ class StyleManagerTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForCustomDateFormats()
{
+1 -1
View File
@@ -15,7 +15,7 @@ class ReaderPerfTest extends TestCase
use TestUsingResource;
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestPerfWhenReading300kRowsXLSX()
{
+3 -3
View File
@@ -15,7 +15,7 @@ class ReaderTest extends TestCase
use TestUsingResource;
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadShouldThrowException()
{
@@ -42,7 +42,7 @@ class ReaderTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestReadForAllWorksheets()
{
@@ -703,7 +703,7 @@ class ReaderTest extends TestCase
* @param string $fileName
* @param bool $shouldFormatDates
* @param bool $shouldPreserveEmptyRows
* @return array All the read rows the given file
* @return array<array> All the read rows the given file
*/
private function getAllRowsForFile($fileName, $shouldFormatDates = false, $shouldPreserveEmptyRows = false)
{
+2 -1
View File
@@ -3,6 +3,7 @@
namespace Box\Spout\Reader\XLSX;
use Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
use Box\Spout\Reader\SheetInterface;
use Box\Spout\TestUsingResource;
use PHPUnit\Framework\TestCase;
@@ -43,7 +44,7 @@ class SheetTest extends TestCase
/**
* @param string $fileName
* @return Sheet[]
* @return SheetInterface[]
*/
private function openFileAndReturnSheets($fileName)
{
+6 -4
View File
@@ -5,6 +5,9 @@
*/
class ReflectionHelper
{
/**
* @var array<class-string, array>
*/
private static $privateVarsToReset = [];
/**
@@ -27,7 +30,7 @@ class ReflectionHelper
* Get the value of a static private or public class property.
* Used to test internals of class without having to make the property public
*
* @param string $class
* @param class-string $class
* @param string $valueName
* @return mixed|null
*/
@@ -48,7 +51,7 @@ class ReflectionHelper
* Set the value of a static private or public class property.
* Used to test internals of class without having to make the property public
*
* @param string $class
* @param class-string $class
* @param string $valueName
* @param mixed|null $value
* @param bool $saveOriginalValue
@@ -62,7 +65,7 @@ class ReflectionHelper
// to prevent side-effects in later tests, we need to remember the original value and reset it on tear down
// @NOTE: we need to check isset in case the original value was null or array()
if ($saveOriginalValue && (!isset(self::$privateVarsToReset[$class]) || !isset(self::$privateVarsToReset[$class][$name]))) {
if ($saveOriginalValue && (!isset(self::$privateVarsToReset[$class]))) {
self::$privateVarsToReset[$class][$valueName] = $reflectionProperty->getValue();
}
$reflectionProperty->setValue($value);
@@ -95,7 +98,6 @@ class ReflectionHelper
*
* @param object $object
* @param string $methodName
* @param *mixed|null $params
*
* @return mixed|null
*/
+7 -1
View File
@@ -92,7 +92,13 @@ trait TestUsingResource
*/
protected function getTempFolderPath()
{
return realpath($this->tempFolderPath);
$path = realpath($this->tempFolderPath);
if ($path === false) {
throw new \RuntimeException(sprintf("Realpath of '%s' failed.", $path));
}
return $path;
}
/**
+1 -1
View File
@@ -61,7 +61,7 @@ class WriterPerfTest extends TestCase
*/
private function getNumWrittenRows($resourcePath)
{
$lineCountResult = `wc -l $resourcePath`;
$lineCountResult = shell_exec("wc -l $resourcePath");
return (int) $lineCountResult;
}
+7 -3
View File
@@ -69,6 +69,7 @@ class WriterTest extends TestCase
$this->expectException(InvalidArgumentException::class);
$writer = WriterEntityFactory::createCSVWriter();
/* @phpstan-ignore-next-line */
$writer->addRows([['csv--11', 'csv--12']]);
$writer->close();
}
@@ -176,7 +177,7 @@ class WriterTest extends TestCase
$this->assertEquals('#This is, a comma#,csv--12,csv--13', $writtenContent, 'The fields should be enclosed with #');
}
public function testWriteShouldSupportedEscapedCharacters()
public function testWriteShouldSupportedEscapedCharacters() : void
{
$allRows = $this->createRowsFromValues([
['"csv--11"', 'csv--12\\', 'csv--13\\\\', 'csv--14\\\\\\'],
@@ -193,7 +194,7 @@ class WriterTest extends TestCase
* @param string $fieldDelimiter
* @param string $fieldEnclosure
* @param bool $shouldAddBOM
* @return string|null
* @return string
*/
private function writeToCsvFileAndReturnWrittenContent($allRows, $fileName, $fieldDelimiter = ',', $fieldEnclosure = '"', $shouldAddBOM = true)
{
@@ -209,7 +210,10 @@ class WriterTest extends TestCase
$writer->addRows($allRows);
$writer->close();
return file_get_contents($resourcePath);
/** @var string $content */
$content = file_get_contents($resourcePath);
return $content;
}
/**
@@ -25,7 +25,7 @@ class SheetTest extends TestCase
/**
* @param int $sheetIndex
* @param int $associatedWorkbookId
* @param string $associatedWorkbookId
* @return Sheet
*/
private function createSheet($sheetIndex, $associatedWorkbookId)
@@ -57,7 +57,7 @@ class SheetTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForInvalidSheetNames()
{
@@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase;
class CellHelperTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestGetColumnLettersFromColumnIndex()
{
@@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase;
class RowManagerTest extends TestCase
{
/**
* @return array
* @return array<mixed>
*/
public function dataProviderForTestIsEmptyRow()
{
@@ -26,7 +26,7 @@ class RowManagerTest extends TestCase
/**
* @dataProvider dataProviderForTestIsEmptyRow
*
* @param array $cells
* @param array<Cell> $cells
* @param bool $expectedIsEmpty
* @return void
*/
+1 -1
View File
@@ -95,7 +95,7 @@ class SheetTest extends TestCase
/**
* @param string $fileName
* @param string $sheetName
* @return Sheet
* @return void
*/
private function writeDataAndReturnSheetWithCustomName($fileName, $sheetName)
{
+1 -1
View File
@@ -88,7 +88,7 @@ class WriterPerfTest extends TestCase
copy($pathToContentXmlFile, $tmpFile);
// Get the last 200 characters
$lastCharacters = `tail -c 200 $tmpFile`;
$lastCharacters = shell_exec("tail -c 200 $tmpFile");
// remove the temporary file
unlink($tmpFile);
+7 -3
View File
@@ -280,7 +280,7 @@ class WriterTest extends TestCase
}
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestAddRowShouldUseNumberColumnsRepeatedForRepeatedValues()
{
@@ -296,7 +296,7 @@ class WriterTest extends TestCase
/**
* @dataProvider dataProviderForTestAddRowShouldUseNumberColumnsRepeatedForRepeatedValues
*
* @param array $dataRow
* @param array<mixed> $dataRow
* @param int $expectedNumTableCells
* @param int $expectedNumColumnsRepeated
* @return void
@@ -306,6 +306,7 @@ class WriterTest extends TestCase
$fileName = 'test_add_row_should_use_number_columns_repeated.ods';
$this->writeToODSFile($this->createRowsFromValues([$dataRow]), $fileName);
/** @var \DOMElement $sheetXmlNode */
$sheetXmlNode = $this->getSheetXmlNode($fileName, 1);
$tableCellNodes = $sheetXmlNode->getElementsByTagName('table-cell');
@@ -589,7 +590,10 @@ class WriterTest extends TestCase
{
$xmlReader = $this->moveReaderToCorrectTableNode($fileName, $sheetIndex);
return $xmlReader->expand();
/** @var \DOMNode $node */
$node = $xmlReader->expand();
return $node;
}
/**
+19 -7
View File
@@ -112,6 +112,7 @@ class WriterWithStyleTest extends TestCase
$this->writeToODSFile([$dataRow], $fileName);
/** @var \DOMElement $textPropertiesElement */
$textPropertiesElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'style:text-properties');
$this->assertEquals(Style::DEFAULT_FONT_SIZE . 'pt', $textPropertiesElement->getAttribute('fo:font-size'));
$this->assertEquals('#' . Style::DEFAULT_FONT_COLOR, $textPropertiesElement->getAttribute('fo:color'));
@@ -351,6 +352,7 @@ class WriterWithStyleTest extends TestCase
$this->writeToODSFileWithDefaultStyle($dataRows, $fileName, $defaultStyle);
/** @var \DOMElement $textPropertiesElement */
$textPropertiesElement = $this->getXmlSectionFromStylesXmlFile($fileName, 'style:text-properties');
$this->assertEquals($defaultFontSize . 'pt', $textPropertiesElement->getAttribute('fo:font-size'));
}
@@ -397,7 +399,7 @@ class WriterWithStyleTest extends TestCase
/**
* @param string $fileName
* @return \DOMNode[]
* @return \DOMElement[]
*/
private function getCellElementsFromContentXmlFile($fileName)
{
@@ -410,7 +412,9 @@ class WriterWithStyleTest extends TestCase
while ($xmlReader->read()) {
if ($xmlReader->isPositionedOnStartingNode('table:table-cell') && $xmlReader->getAttribute('office:value-type') !== null) {
$cellElements[] = $xmlReader->expand();
/** @var \DOMElement $element */
$element = $xmlReader->expand();
$cellElements[] = $element;
}
}
@@ -421,7 +425,7 @@ class WriterWithStyleTest extends TestCase
/**
* @param string $fileName
* @return \DOMNode[]
* @return \DOMElement[]
*/
private function getCellStyleElementsFromContentXmlFile($fileName)
{
@@ -434,7 +438,10 @@ class WriterWithStyleTest extends TestCase
while ($xmlReader->read()) {
if ($xmlReader->isPositionedOnStartingNode('style:style') && $xmlReader->getAttribute('style:family') === 'table-cell') {
$cellStyleElements[] = $xmlReader->expand();
/** @var \DOMElement $element */
$element = $xmlReader->expand();
$cellStyleElements[] = $element;
}
}
@@ -456,18 +463,23 @@ class WriterWithStyleTest extends TestCase
$xmlReader->openFileInZip($resourcePath, 'styles.xml');
$xmlReader->readUntilNodeFound($section);
return $xmlReader->expand();
/** @var \DOMNode $node */
$node = $xmlReader->expand();
return $node;
}
/**
* @param string $expectedValue
* @param \DOMNode $parentElement
* @param \DOMElement $parentElement
* @param string $childTagName
* @param string $attributeName
* @return void
*/
private function assertFirstChildHasAttributeEquals($expectedValue, $parentElement, $childTagName, $attributeName)
{
$this->assertEquals($expectedValue, $parentElement->getElementsByTagName($childTagName)->item(0)->getAttribute($attributeName));
/** @var \DOMElement $child */
$child = $parentElement->getElementsByTagName($childTagName)->item(0);
$this->assertEquals($expectedValue, $child->getAttribute($attributeName));
}
}
+4 -4
View File
@@ -12,7 +12,7 @@ use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
trait RowCreationHelper
{
/**
* @param array $cellValues
* @param array<mixed> $cellValues
* @return Row
*/
protected function createRowFromValues(array $cellValues)
@@ -21,7 +21,7 @@ trait RowCreationHelper
}
/**
* @param array $cellValues
* @param array<mixed> $cellValues
* @param Style|null $rowStyle
* @return Row
*/
@@ -31,7 +31,7 @@ trait RowCreationHelper
}
/**
* @param array $rowValues
* @param array<array> $rowValues
* @return Row[]
*/
protected function createRowsFromValues(array $rowValues)
@@ -40,7 +40,7 @@ trait RowCreationHelper
}
/**
* @param array $rowValues
* @param array<array> $rowValues
* @param Style|null $rowsStyle
* @return Row[]
*/
@@ -2,6 +2,7 @@
namespace Box\Spout\Writer\XLSX\Manager\Style;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
/**
@@ -10,7 +11,7 @@ use PHPUnit\Framework\TestCase;
class StyleManagerTest extends TestCase
{
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestShouldApplyStyleOnEmptyCell()
{
@@ -38,6 +39,7 @@ class StyleManagerTest extends TestCase
*/
public function testShouldApplyStyleOnEmptyCell($fillId, $borderId, $expectedResult)
{
/** @var \Box\Spout\Writer\Common\Manager\Style\StyleRegistry&MockObject $styleRegistryMock */
$styleRegistryMock = $this->getMockBuilder(StyleRegistry::class)
->disableOriginalConstructor()
->setMethods(['getFillIdForStyleId', 'getBorderIdForStyleId'])
+3 -3
View File
@@ -15,7 +15,7 @@ class WriterPerfTest extends TestCase
use TestUsingResource;
/**
* @return array
* @return array<array>
*/
public function dataProviderForTestPerfWhenWritingOneMillionRowsXLSX()
{
@@ -102,7 +102,7 @@ class WriterPerfTest extends TestCase
/**
* @param string $filePath
* @return string
* @return int
*/
private function getLasRowNumberForFile($filePath)
{
@@ -135,7 +135,7 @@ class WriterPerfTest extends TestCase
copy($filePath, $tmpFile);
// Get the last 200 characters
$lastCharacters = `tail -c $numCharacters $tmpFile`;
$lastCharacters = shell_exec("tail -c $numCharacters $tmpFile");
// remove the temporary file
unlink($tmpFile);
+1
View File
@@ -120,6 +120,7 @@ class WriterTest extends TestCase
[str_repeat('a', WorksheetManager::MAX_CHARACTERS_PER_CELL + 1)],
];
/* @phpstan-ignore-next-line */
$this->writeToXLSXFile($dataRows, $fileName);
}
@@ -394,10 +394,16 @@ class WriterWithStyleTest extends TestCase
'3 cell xfs present - a default one and two custom ones'
);
$firstCustomId = $styleXfsElements->childNodes->item(1)->getAttribute('fillId');
/** @var \DOMElement $firstItem */
$firstItem = $styleXfsElements->childNodes->item(1);
$firstCustomId = $firstItem->getAttribute('fillId');
$this->assertEquals(2, (int) $firstCustomId, 'The first custom fill id should have the index 2');
$secondCustomId = $styleXfsElements->childNodes->item(2)->getAttribute('fillId');
/** @var \DOMElement $secondItem */
$secondItem = $styleXfsElements->childNodes->item(2);
$secondCustomId = $secondItem->getAttribute('fillId');
$this->assertEquals(2, (int) $secondCustomId, 'The second custom fill id should have the index 2');
}
@@ -468,7 +474,6 @@ class WriterWithStyleTest extends TestCase
$borderParts = $borderNode->childNodes;
$ordering = [];
/** @var \DOMText $part */
foreach ($borderParts as $part) {
if ($part instanceof \DOMElement) {
$ordering[] = $part->nodeName;
@@ -617,6 +622,7 @@ class WriterWithStyleTest extends TestCase
$xmlReader->openFileInZip($resourcePath, 'xl/styles.xml');
$xmlReader->readUntilNodeFound($section);
/** @var \DOMElement $xmlSection */
$xmlSection = $xmlReader->expand();
$xmlReader->close();
@@ -626,7 +632,7 @@ class WriterWithStyleTest extends TestCase
/**
* @param string $fileName
* @return \DOMNode[]
* @return \DOMElement[]
*/
private function getCellElementsFromSheetXmlFile($fileName)
{
@@ -639,7 +645,9 @@ class WriterWithStyleTest extends TestCase
while ($xmlReader->read()) {
if ($xmlReader->isPositionedOnStartingNode('c')) {
$cellElements[] = $xmlReader->expand();
/** @var \DOMElement $element */
$element = $xmlReader->expand();
$cellElements[] = $element;
}
}
@@ -650,19 +658,21 @@ class WriterWithStyleTest extends TestCase
/**
* @param string $expectedValue
* @param \DOMNode $parentElement
* @param \DOMElement $parentElement
* @param string $childTagName
* @param string $attributeName
* @return void
*/
private function assertFirstChildHasAttributeEquals($expectedValue, $parentElement, $childTagName, $attributeName)
{
$this->assertEquals($expectedValue, $parentElement->getElementsByTagName($childTagName)->item(0)->getAttribute($attributeName));
/** @var \DOMElement $child */
$child = $parentElement->getElementsByTagName($childTagName)->item(0);
$this->assertEquals($expectedValue, $child->getAttribute($attributeName));
}
/**
* @param int $expectedNumber
* @param \DOMNode $parentElement
* @param \DOMElement $parentElement
* @param string $message
* @return void
*/
@@ -672,7 +682,7 @@ class WriterWithStyleTest extends TestCase
}
/**
* @param \DOMNode $parentElement
* @param \DOMElement $parentElement
* @param string $childTagName
* @return void
*/