diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 8dea16d..6f082d3 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -109,4 +109,4 @@ jobs: run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Static analysis with PHPStan - run: ./vendor/bin/phpstan analyse -l 5 + run: ./vendor/bin/phpstan analyse --ansi diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 7c17d43..82afaae 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,12 +1,16 @@ parameters: - level: 5 + level: 8 paths: - src/ - tests/ parallel: processTimeout: 300.0 checkMissingIterableValueType: false + checkGenericClassInNonGenericObjectType: false ignoreErrors: - message: '#Left side of && is always false.#' path: src/Blueprint/Components/Components.php count: 1 + - message: '#Parameter $length of function file_get_contents expects int<0, max>|null, int|null given.#' + path: src/Parser/Utils/IOCapable.php + count: 4 diff --git a/src/Blueprint/Components/Components.php b/src/Blueprint/Components/Components.php index ab28340..f0785c8 100644 --- a/src/Blueprint/Components/Components.php +++ b/src/Blueprint/Components/Components.php @@ -16,7 +16,7 @@ class Components implements ComponentInterface, Iterator private const MISSING_ELEMENT = 'Blueprint section %s is missing a mandatory element %s'; private const INVALID_VALUE = 'Blueprint %s element has invalid value (%s). Acceptable value(s) [%s]'; - private $position = 0; + private int $position = 0; /** @var Component[] */ public readonly array $components; diff --git a/src/Blueprint/Components/Conditions.php b/src/Blueprint/Components/Conditions.php index 1720cda..5b65ff5 100644 --- a/src/Blueprint/Components/Conditions.php +++ b/src/Blueprint/Components/Conditions.php @@ -25,7 +25,7 @@ public function __construct( $this->position = 0; } - protected function buildConditions($conditions): array + protected function buildConditions(array $conditions): array { $objectConditions = []; foreach ($conditions as $condition) { @@ -75,9 +75,6 @@ public static function validation(array &$conditions): void $case = self::getConditionKeyword($condition); - if ($case === false) { - throw new InvalidFieldException('no valid condition found'); - } $finalConditions[] = [ 'column' => $condition['column'], 'keyword' => $case, @@ -87,7 +84,7 @@ public static function validation(array &$conditions): void $conditions = $finalConditions; } - protected static function getConditionKeyword(array $condition): ConditionKeyword | bool + protected static function getConditionKeyword(array $condition): ConditionKeyword { foreach (ConditionKeyword::cases() as $case) { if ( @@ -99,7 +96,7 @@ protected static function getConditionKeyword(array $condition): ConditionKeywor } } - return false; + throw new InvalidFieldException('no valid condition keyword found'); } public static function getMandatoryElements(): array diff --git a/src/Dictionary.php b/src/Dictionary.php index 340f65f..87f8448 100644 --- a/src/Dictionary.php +++ b/src/Dictionary.php @@ -7,14 +7,14 @@ final class Dictionary private const FILE = 'en'; private const DICTIONARY_DIRECTORY = '/storage/dictionary/'; - private readonly string $filePath; + private readonly ?string $filePath; public function __construct(?string $filePath = null) { $this->filePath = $this->generateFilePath($filePath); } - private function generateFilePath(?string $filePath = null) + private function generateFilePath(?string $filePath = null): ?string { return is_file($filePath ?? '') ? $filePath diff --git a/src/Parser/Extension/BlueprintInterpreter.php b/src/Parser/Extension/BlueprintInterpreter.php index 275f659..0dbab2c 100644 --- a/src/Parser/Extension/BlueprintInterpreter.php +++ b/src/Parser/Extension/BlueprintInterpreter.php @@ -80,7 +80,7 @@ protected function matchHit(Component $component, array $row): bool { $found = false; /** @var Condition $condition */ - foreach ($component->conditions as $condition) { + foreach ($component->conditions ?? [] as $condition) { $passedCondition = false; foreach ($condition->columns as $column) { if (isset($row[$column - 1])) { @@ -101,7 +101,7 @@ protected function matchHit(Component $component, array $row): bool return $found; } - protected function matchNext($index): bool + protected function matchNext(int $index): bool { return $this->lastHitIndex === $index - 1; } diff --git a/src/Parser/Parser.php b/src/Parser/Parser.php index d076a30..5e7f284 100644 --- a/src/Parser/Parser.php +++ b/src/Parser/Parser.php @@ -91,7 +91,9 @@ public function getParsedContentPlugin(): ParserPluginInterface */ public function getAsObject(): stdClass { - return json_decode(json_encode($this->getAsArray())); + $json = json_encode($this->getAsArray()); + + return $json === false ? new stdClass() : json_decode($json); } /** diff --git a/src/Parser/ParserBuilder.php b/src/Parser/ParserBuilder.php index 95d6686..907da4f 100644 --- a/src/Parser/ParserBuilder.php +++ b/src/Parser/ParserBuilder.php @@ -43,7 +43,7 @@ public function addBlueprint(Blueprint $blueprint): self public function addFile(string $path): self { - $this->fileContent = $this->load($path, length: $this->maxFileLength); + $this->fileContent = $this->load($path); return $this; } diff --git a/src/Parser/Utils/IOCapable.php b/src/Parser/Utils/IOCapable.php index f4dd200..707123d 100644 --- a/src/Parser/Utils/IOCapable.php +++ b/src/Parser/Utils/IOCapable.php @@ -11,6 +11,7 @@ trait IOCapable private string $path = ''; + /** @var resource */ private $file; /** @@ -20,13 +21,22 @@ trait IOCapable */ protected function writeTemporaryFile(string $content): string { - $this->path = tempnam(sys_get_temp_dir(), __FUNCTION__); - $this->file = fopen($this->path, 'r+b'); + $path = tempnam(sys_get_temp_dir(), __FUNCTION__); - if (!is_resource($this->file)) { + if (!$path) { + throw new UnableToCreateFileException('Unable to get a temporary file path'); + } + + $this->path = $path; + + $file = fopen($this->path, 'r+b'); + + if (!is_resource($file)) { throw new UnableToCreateFileException("Unable to create temporary file in {$this->path}"); } + $this->file = $file; + if (!is_writable($this->path)) { throw new UnableToCreateFileException("Unable to modify temporary file in {$this->path}"); } @@ -41,10 +51,10 @@ protected function deleteTemporaryFile(): bool return $this->path ? unlink($this->path) : true; } - private function loadFromLink($url): string + private function loadFromLink(string $url): string { // TODO: use curl ... maybe - $content = \file_get_contents($url, length: $this->maxFileLength); + $content = \file_get_contents($url, length: $this->maxFileLength ?? null); if ($content === false) { throw new InvalidArgumentException("unable to load file from link: {$url}"); @@ -53,13 +63,19 @@ private function loadFromLink($url): string return $content; } - private function loadFromPath($path): string + private function loadFromPath(string $path): string { if (!is_readable($path)) { - throw new InvalidArgumentException("unable to read file from link: {$path}"); + throw new InvalidArgumentException("unable to read file from path: {$path}"); } - return \file_get_contents($path, length: $this->maxFileLength); + $content = \file_get_contents($path, length: $this->maxFileLength ?? null); + + if ($content === false) { + throw new InvalidArgumentException("unable to load file from path: {$path}"); + } + + return $content; } /** @@ -67,7 +83,7 @@ private function loadFromPath($path): string * * @return string the read data or false on failure */ - protected function load(string $parameter, int $length): string + protected function load(string $parameter): string { if (filter_var($parameter, \FILTER_VALIDATE_URL)) { return $this->loadFromLink($parameter); diff --git a/tests/Blueprint/BlueprintBuilderTest.php b/tests/Blueprint/BlueprintBuilderTest.php index 16bf72b..1dcc55d 100644 --- a/tests/Blueprint/BlueprintBuilderTest.php +++ b/tests/Blueprint/BlueprintBuilderTest.php @@ -15,9 +15,9 @@ class BlueprintBuilderTest extends TestCase protected string $blueprintsDirectory = STORAGE_DIRECTORY . '/blueprints/'; - public function testCreateFromString() + public function testCreateFromString(): void { - $rawFile = file_get_contents($this->blueprintsDirectory . 'valid.yaml'); + $rawFile = (string) file_get_contents($this->blueprintsDirectory . 'valid.yaml'); $builder = new BlueprintBuilder(new BlueprintHelper()); $builder->parse($rawFile); @@ -26,7 +26,7 @@ public function testCreateFromString() $this->assertInstanceOf(BlueprintInterface::class, $blueprint); } - public function testCreateFromPath() + public function testCreateFromPath(): void { $path = $this->blueprintsDirectory . 'valid.yaml'; @@ -40,7 +40,7 @@ public function testCreateFromPath() /** * @dataProvider emptyStreamsProvider */ - public function testThrowingExceptionOnEmptyStream(string $stream, bool $isPath) + public function testThrowingExceptionOnEmptyStream(string $stream, bool $isPath): void { $this->expectException(InvalidBlueprintException::class); $builder = new BlueprintBuilder(new BlueprintHelper()); @@ -51,7 +51,7 @@ public function testThrowingExceptionOnEmptyStream(string $stream, bool $isPath) } $_ = $builder->build(); } - public function emptyStreamsProvider() + public function emptyStreamsProvider(): array { return [ ['', false], diff --git a/tests/Blueprint/BlueprintTest.php b/tests/Blueprint/BlueprintTest.php index 7a99f1b..d61cae5 100644 --- a/tests/Blueprint/BlueprintTest.php +++ b/tests/Blueprint/BlueprintTest.php @@ -15,9 +15,9 @@ class BlueprintTest extends TestCase { protected string $blueprintsDirectory = STORAGE_DIRECTORY . '/blueprints/'; - public function testSuccessfullyCreateBlueprint() + public function testSuccessfullyCreateBlueprint(): void { - $rawFile = file_get_contents($this->blueprintsDirectory . 'valid.yaml'); + $rawFile = (string) file_get_contents($this->blueprintsDirectory . 'valid.yaml'); $blueprint = Blueprint::from( \yaml_parse($rawFile), $this->blueprintsDirectory . 'valid.yaml', @@ -29,14 +29,15 @@ public function testSuccessfullyCreateBlueprint() /** * @dataProvider invalidFilesProvider + * @param class-string<\Throwable> $exception */ - public function testThrowingExceptionOnInvalidBlueprint(string $fileName, string $exception) + public function testThrowingExceptionOnInvalidBlueprint(string $fileName, string $exception): void { $this->expectException($exception); $path = $this->blueprintsDirectory . $fileName . '.yaml'; Blueprint::from(\yaml_parse_file($path), 'some-path', new BlueprintHelper()); } - public function invalidFilesProvider() + public function invalidFilesProvider(): array { return [ ['invalid_blueprint_1', InvalidBlueprintException::class], diff --git a/tests/Blueprint/Components/ComponentsTest.php b/tests/Blueprint/Components/ComponentsTest.php index bc701ab..3d78ba5 100644 --- a/tests/Blueprint/Components/ComponentsTest.php +++ b/tests/Blueprint/Components/ComponentsTest.php @@ -16,7 +16,7 @@ class ComponentsTest extends TestCase { protected string $blueprintsDirectory = STORAGE_DIRECTORY . '/blueprints/'; - protected $helper; + protected mixed $helper; public function setUp(): void { @@ -25,8 +25,9 @@ public function setUp(): void /** * @dataProvider invalidFilesProvider + * @param class-string<\Throwable> $exception */ - public function testThrowingExceptionOnInvalidBlueprint(string $fileName, string $exception) + public function testThrowingExceptionOnInvalidBlueprint(string $fileName, string $exception): void { $this->expectException($exception); $path = $this->blueprintsDirectory . $fileName . '.yaml'; @@ -35,7 +36,7 @@ public function testThrowingExceptionOnInvalidBlueprint(string $fileName, string $_ = $builder->load($path) ->build(); } - public function invalidFilesProvider() + public function invalidFilesProvider(): array { return [ ['invalid_component_1', InvalidComponentException::class], @@ -45,7 +46,7 @@ public function invalidFilesProvider() /** * @dataProvider validParametersDataProvider */ - public function testCreateFromParameters($parametersArray) + public function testCreateFromParameters(array $parametersArray): void { $components = Components::from($parametersArray, new BlueprintHelper()); @@ -69,7 +70,7 @@ public function testCreateFromParameters($parametersArray) $components->components, ); } - public function validParametersDataProvider() + public function validParametersDataProvider(): array { return [ [ @@ -92,13 +93,14 @@ public function validParametersDataProvider() /** * @dataProvider invalidParametersDataProvider + * @param class-string<\Throwable> $exception */ - public function testCreateFromInvalidParameters($parametersArray, $exception) + public function testCreateFromInvalidParameters(array $parametersArray, string $exception): void { $this->expectException($exception); $_ = Components::from($parametersArray, $this->helper); } - public function invalidParametersDataProvider() + public function invalidParametersDataProvider(): array { return [ [ diff --git a/tests/Blueprint/Components/ConditionsTest.php b/tests/Blueprint/Components/ConditionsTest.php index 0dfa4aa..9c4191b 100644 --- a/tests/Blueprint/Components/ConditionsTest.php +++ b/tests/Blueprint/Components/ConditionsTest.php @@ -16,14 +16,14 @@ class ConditionsTest extends TestCase /** * @dataProvider validParametersDataProvider */ - public function testCreateFromParameters($parametersArray, $expected) + public function testCreateFromParameters(array $parametersArray, array $expected): void { $conditions = Conditions::from($parametersArray, new BlueprintHelper()); $this->assertIsIterable($conditions); $this->assertEquals($conditions->conditions, $expected); } - public function validParametersDataProvider() + public function validParametersDataProvider(): array { return [ [ @@ -51,13 +51,14 @@ public function validParametersDataProvider() /** * @dataProvider invalidParametersDataProvider + * @param class-string<\Throwable> $exception */ - public function testCreateFromInvalidParameters($parametersArray, $exception) + public function testCreateFromInvalidParameters(array $parametersArray, string $exception): void { $this->expectException($exception); $_ = Conditions::from($parametersArray, new BlueprintHelper()); } - public function invalidParametersDataProvider() + public function invalidParametersDataProvider(): array { return [ [ diff --git a/tests/Blueprint/Components/FieldsTest.php b/tests/Blueprint/Components/FieldsTest.php index 297617b..4e8cf95 100644 --- a/tests/Blueprint/Components/FieldsTest.php +++ b/tests/Blueprint/Components/FieldsTest.php @@ -18,14 +18,14 @@ class FieldsTest extends TestCase /** * @dataProvider validParametersDataProvider */ - public function testCreateFromParameters($parametersArray, $expected) + public function testCreateFromParameters(array $parametersArray, array $expected): void { $fields = Fields::from($parametersArray, new BlueprintHelper()); $this->assertIsIterable($fields); $this->assertEquals($fields->fields, $expected); } - public function validParametersDataProvider() + public function validParametersDataProvider(): array { return [ [ @@ -51,13 +51,14 @@ public function validParametersDataProvider() /** * @dataProvider invalidParametersDataProvider + * @param class-string<\Throwable> $exception */ - public function testCreateFromInvalidParameters($parametersArray, $exception) + public function testCreateFromInvalidParameters(array $parametersArray, string $exception): void { $this->expectException($exception); $_ = Fields::from($parametersArray, new BlueprintHelper()); } - public function invalidParametersDataProvider() + public function invalidParametersDataProvider(): array { return [ [ diff --git a/tests/DictionaryTest.php b/tests/DictionaryTest.php index b4b59cb..7ce3f5c 100644 --- a/tests/DictionaryTest.php +++ b/tests/DictionaryTest.php @@ -11,7 +11,7 @@ class DictionaryTest extends TestCase { private string $storageTestDirectory = STORAGE_DIRECTORY . '/dictionaries/'; - public function testCreateObject() + public function testCreateObject(): void { $this->assertInstanceOf( Dictionary::class, @@ -22,7 +22,7 @@ public function testCreateObject() /** * @dataProvider getDataProvider */ - public function testCanGetValue($key, $default, $file, $actual) + public function testCanGetValue(string $key, ?string $default, string $file, string $actual): void { $dictionary = new Dictionary($this->storageTestDirectory . $file); @@ -31,7 +31,7 @@ public function testCanGetValue($key, $default, $file, $actual) $actual, ); } - public function getDataProvider() + public function getDataProvider(): array { return [ ['test.my.limits', null, 'valid.php', 'you %s'], @@ -42,7 +42,7 @@ public function getDataProvider() /** * @dataProvider formattedValuesDataProvider */ - public function testCanFormattedGetValue($key, $default, $file, $actual, $values) + public function testCanFormattedGetValue(string $key, ?string $default, string $file, string $actual, array $values): void { $dictionary = new Dictionary($this->storageTestDirectory . $file); @@ -51,7 +51,7 @@ public function testCanFormattedGetValue($key, $default, $file, $actual, $values $actual, ); } - public function formattedValuesDataProvider() + public function formattedValuesDataProvider(): array { return [ ['test.my.limits', null, 'valid.php', 'you fool', ['fool']], diff --git a/tests/HelperTest.php b/tests/HelperTest.php index 3af1c40..9d65937 100644 --- a/tests/HelperTest.php +++ b/tests/HelperTest.php @@ -13,12 +13,11 @@ class HelperTest extends TestCase /** * @dataProvider arraysDataProvider */ - public function testCanProcessArray(array $raw, array $actual, string $separator) + public function testCanProcessArray(array $raw, array $actual, string $separator): void { - $this->assertEquals(Helper::toOneDimensionArray(array: $raw, separator: $separator), $actual); } - public function arraysDataProvider() + public function arraysDataProvider(): array { return [ [ @@ -39,11 +38,11 @@ public function arraysDataProvider() ]; } - public function testCanDetectDuplicateKeys() + public function testCanDetectDuplicateKeys(): void { $array = ['i' => ['hate.you' => false, 'hate' => ['you' => true]]]; $this->expectException(Exception::class); - $a = Helper::toOneDimensionArray($array, separator: '.'); + $_ = Helper::toOneDimensionArray($array, separator: '.'); } } diff --git a/tests/JustExampleTest.php b/tests/JustExampleTest.php index 87ee2f6..52906ce 100644 --- a/tests/JustExampleTest.php +++ b/tests/JustExampleTest.php @@ -11,11 +11,11 @@ class JustExampleTest extends TestCase /** * @dataProvider exampleOneDataProvider */ - public function testExampleOne($expected, $actual) + public function testExampleOne(int $expected, int $actual): void { $this->assertEquals($expected, $actual); } - public function exampleOneDataProvider() + public function exampleOneDataProvider(): array { return [ [1, 1], @@ -23,7 +23,7 @@ public function exampleOneDataProvider() ]; } - public function testExampleTwo() + public function testExampleTwo(): void { $this->assertEquals(1, 1); } diff --git a/tests/Parser/Extension/Spreadsheet/SpreadsheetTest.php b/tests/Parser/Extension/Spreadsheet/SpreadsheetTest.php deleted file mode 100644 index 4ccefc1..0000000 --- a/tests/Parser/Extension/Spreadsheet/SpreadsheetTest.php +++ /dev/null @@ -1,15 +0,0 @@ -assertEquals(1, 1); - } -} diff --git a/tests/Parser/ParserBuilderTest.php b/tests/Parser/ParserBuilderTest.php index 34576cc..49bfe5a 100644 --- a/tests/Parser/ParserBuilderTest.php +++ b/tests/Parser/ParserBuilderTest.php @@ -4,7 +4,6 @@ namespace HusamAwadhi\PowerParserTests\Parser; -use HusamAwadhi\PowerParser\Blueprint\Blueprint; use HusamAwadhi\PowerParser\Blueprint\BlueprintBuilder; use HusamAwadhi\PowerParser\Blueprint\BlueprintHelper; use HusamAwadhi\PowerParser\Exception\InvalidArgumentException; @@ -20,7 +19,7 @@ class ParserBuilderTest extends TestCase protected string $blueprintsDirectory = STORAGE_DIRECTORY . '/blueprints/'; protected string $excelFile = STORAGE_DIRECTORY . '/sample.xlsx'; - public function testParserCreatedSuccessfully() + public function testParserCreatedSuccessfully(): void { $builder = new ParserBuilder(); $blueprintBuilder = new BlueprintBuilder(new BlueprintHelper()); @@ -35,7 +34,7 @@ public function testParserCreatedSuccessfully() $this->assertInstanceOf(Parser::class, $parser); } - public function testExceptionWhenNoBlueprint() + public function testExceptionWhenNoBlueprint(): void { $this->expectException(MissingElementException::class); @@ -46,7 +45,7 @@ public function testExceptionWhenNoBlueprint() ->build(); } - public function testExceptionWhenNoFile() + public function testExceptionWhenNoFile(): void { $this->expectException(MissingElementException::class); @@ -60,7 +59,7 @@ public function testExceptionWhenNoFile() ->build(); } - public function testExceptionWhenFileNotFound() + public function testExceptionWhenFileNotFound(): void { $this->expectException(InvalidArgumentException::class); @@ -71,7 +70,7 @@ public function testExceptionWhenFileNotFound() ->build(); } - public function testExceptionWhenRegisteringDuplicateExtension() + public function testExceptionWhenRegisteringDuplicateExtension(): void { $this->expectException(InvalidPLuginException::class); diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php index bd212c2..093a608 100644 --- a/tests/Parser/ParserTest.php +++ b/tests/Parser/ParserTest.php @@ -20,8 +20,8 @@ class ParserTest extends TestCase protected string $excelFile = STORAGE_DIRECTORY . '/sample.xlsx'; protected string $csvFile = STORAGE_DIRECTORY . '/sample.csv'; protected Blueprint $blueprint; - protected $dummyPlugin; - protected $dummyPlugin2; + protected mixed $dummyPlugin; + protected mixed $dummyPlugin2; public function setUp(): void { @@ -38,23 +38,23 @@ public function setUp(): void ->willReturn(['exe']); } - public function testParserCreatedSuccessfully() + public function testParserCreatedSuccessfully(): void { $parser = new Parser( $this->blueprint, - \file_get_contents($this->excelFile), + (string) \file_get_contents($this->excelFile), [Spreadsheet::class => new Spreadsheet()] ); $this->assertInstanceOf(Parser::class, $parser); } - public function testListOfSupportedExtensions() + public function testListOfSupportedExtensions(): void { $parser = new Parser( $this->blueprint, - \file_get_contents($this->excelFile), + (string) \file_get_contents($this->excelFile), [ Spreadsheet::class => new Spreadsheet(), $this->dummyPlugin::class => $this->dummyPlugin @@ -70,7 +70,7 @@ public function testListOfSupportedExtensions() ); } - public function testSuccessfullyGetRecommendedPlugin() + public function testSuccessfullyGetRecommendedPlugin(): void { $builder = new BlueprintBuilder(new BlueprintHelper()); $builder->load($this->blueprintsDirectory . 'valid_exe.yaml'); @@ -78,7 +78,7 @@ public function testSuccessfullyGetRecommendedPlugin() $parser = new Parser( $blueprint, - \file_get_contents($this->excelFile), + (string) \file_get_contents($this->excelFile), [ $this->dummyPlugin::class => $this->dummyPlugin, $this->dummyPlugin2::class => $this->dummyPlugin2, @@ -88,7 +88,7 @@ public function testSuccessfullyGetRecommendedPlugin() $this->assertEquals($this->dummyPlugin::class, $parser->getRecommendedPluginName()); } - public function testSuccessfullyOverrideRecommendedPlugin() + public function testSuccessfullyOverrideRecommendedPlugin(): void { $builder = new BlueprintBuilder(new BlueprintHelper()); $builder->load($this->blueprintsDirectory . 'valid_exe.yaml'); @@ -96,7 +96,7 @@ public function testSuccessfullyOverrideRecommendedPlugin() $parser = new Parser( $blueprint, - \file_get_contents($this->excelFile), + (string) \file_get_contents($this->excelFile), [ $this->dummyPlugin::class => $this->dummyPlugin, $this->dummyPlugin2::class => $this->dummyPlugin2, @@ -109,15 +109,17 @@ public function testSuccessfullyOverrideRecommendedPlugin() ); } - public function testSuccessfullyIgnoreOverridingIfExtensionDoesNotSupport() + public function testSuccessfullyIgnoreOverridingIfExtensionDoesNotSupport(): void { + /** @var ParserPluginInterface[] */ + $plugins = [ + Spreadsheet::class => new Spreadsheet(), + $this->dummyPlugin::class => $this->dummyPlugin + ]; $parser = new Parser( $this->blueprint, - \file_get_contents($this->excelFile), - [ - Spreadsheet::class => new Spreadsheet(), - $this->dummyPlugin::class => $this->dummyPlugin - ] + (string) \file_get_contents($this->excelFile), + $plugins ); $this->assertEquals( @@ -126,24 +128,24 @@ public function testSuccessfullyIgnoreOverridingIfExtensionDoesNotSupport() ); } - public function testThrowsExceptionOnUnsupportedExtension() + public function testThrowsExceptionOnUnsupportedExtension(): void { $this->expectException(UnsupportedExtensionException::class); $parser = new Parser( $this->blueprint, - \file_get_contents($this->excelFile), + (string) \file_get_contents($this->excelFile), [$this->dummyPlugin::class => $this->dummyPlugin] ); $_ = $parser->getRecommendedPluginName(); } - public function testParseContent() + public function testParseContent(): void { $parser = new Parser( $this->blueprint, - \file_get_contents($this->excelFile), + (string) \file_get_contents($this->excelFile), [Spreadsheet::class => new Spreadsheet()] ); @@ -152,13 +154,13 @@ public function testParseContent() $this->assertInstanceOf(ParserPluginInterface::class, $parser->getParsedContentPlugin()); } - public function testThrowsExceptionIfContentNotParsedYet() + public function testThrowsExceptionIfContentNotParsedYet(): void { $this->expectException(InvalidArgumentException::class); $parser = new Parser( $this->blueprint, - \file_get_contents($this->excelFile), + (string) \file_get_contents($this->excelFile), [Spreadsheet::class => new Spreadsheet()] ); @@ -168,7 +170,7 @@ public function testThrowsExceptionIfContentNotParsedYet() /** * @dataProvider parsedCSVContentDataProvider */ - public function testGettingParsedCSVContentAsJson($expectedArray) + public function testGettingParsedCSVContentAsJson(array $expectedArray): void { $builder = new BlueprintBuilder(new BlueprintHelper()); $builder->load($this->blueprintsDirectory . 'valid_csv.yaml'); @@ -176,15 +178,15 @@ public function testGettingParsedCSVContentAsJson($expectedArray) $parser = new Parser( $blueprint, - \file_get_contents($this->csvFile), + (string) \file_get_contents($this->csvFile), [Spreadsheet::class => new Spreadsheet()] ); $parser->parse(); $this->assertJsonStringEqualsJsonString( - json_encode($expectedArray), - json_encode($parser) + (string) json_encode($expectedArray), + (string) json_encode($parser) ); } public function parsedCSVContentDataProvider(): array @@ -297,18 +299,18 @@ public function parsedCSVContentDataProvider(): array /** * @dataProvider parsedExcelContentDataProvider */ - public function testGettingParsedExcelContentAsObject($expectedArray) + public function testGettingParsedExcelContentAsObject(array $expectedArray): void { $parser = new Parser( $this->blueprint, - \file_get_contents($this->excelFile), + (string) \file_get_contents($this->excelFile), [Spreadsheet::class => new Spreadsheet()] ); $parser->parse(); $this->assertEquals( - json_decode(json_encode($expectedArray)), + json_decode((string) json_encode($expectedArray)), $parser->getAsObject() ); } @@ -316,11 +318,11 @@ public function testGettingParsedExcelContentAsObject($expectedArray) /** * @dataProvider parsedExcelContentDataProvider */ - public function testGettingParsedExcelContentAsArray($expectedArray) + public function testGettingParsedExcelContentAsArray(array $expectedArray): void { $parser = new Parser( $this->blueprint, - \file_get_contents($this->excelFile), + (string) \file_get_contents($this->excelFile), [Spreadsheet::class => new Spreadsheet()] ); $parser->parse(); @@ -331,19 +333,19 @@ public function testGettingParsedExcelContentAsArray($expectedArray) /** * @dataProvider parsedExcelContentDataProvider */ - public function testGettingParsedExcelContentAsJson($expectedArray) + public function testGettingParsedExcelContentAsJson(array $expectedArray): void { $parser = new Parser( $this->blueprint, - \file_get_contents($this->excelFile), + (string) \file_get_contents($this->excelFile), [Spreadsheet::class => new Spreadsheet()] ); $parser->parse(); $this->assertJsonStringEqualsJsonString( - json_encode($expectedArray), - json_encode($parser) + (string) json_encode($expectedArray), + (string) json_encode($parser) ); } @@ -576,7 +578,7 @@ public function parsedExcelContentDataProvider(): array ]; } - public function testThrowsExceptionOnMissingMandatoryComponent() + public function testThrowsExceptionOnMissingMandatoryComponent(): void { $this->expectException(InvalidArgumentException::class); @@ -586,7 +588,7 @@ public function testThrowsExceptionOnMissingMandatoryComponent() $parser = new Parser( $blueprint, - \file_get_contents($this->csvFile), + (string) \file_get_contents($this->csvFile), [Spreadsheet::class => new Spreadsheet()] ); @@ -596,7 +598,7 @@ public function testThrowsExceptionOnMissingMandatoryComponent() /** * @dataProvider parsedExcelContentWithProcessorsDataProvider */ - public function testGettingParsedExcelContentAsJsonWithProcessors($expectedArray) + public function testGettingParsedExcelContentAsJsonWithProcessors(array $expectedArray): void { $builder = new BlueprintBuilder(new BlueprintHelper()); $builder->load($this->blueprintsDirectory . 'valid_with_processors.yaml'); @@ -604,15 +606,15 @@ public function testGettingParsedExcelContentAsJsonWithProcessors($expectedArray $parser = new Parser( $blueprint, - \file_get_contents($this->excelFile), + (string) \file_get_contents($this->excelFile), [Spreadsheet::class => new Spreadsheet()] ); $parser->parse(); $this->assertJsonStringEqualsJsonString( - json_encode($expectedArray), - json_encode($parser) + (string) json_encode($expectedArray), + (string) json_encode($parser) ); } diff --git a/tests/PowerParserTest.php b/tests/PowerParserTest.php index 9c3e805..cfdfbcd 100644 --- a/tests/PowerParserTest.php +++ b/tests/PowerParserTest.php @@ -22,7 +22,7 @@ protected function setUp(): void $this->powerParser = new PowerParser(); } - public function testSuccessfullyCreateParserBuilder() + public function testSuccessfullyCreateParserBuilder(): void { $builder = $this->powerParser->getParserBuilder( $this->blueprintsDirectory . 'valid.yaml', @@ -32,7 +32,7 @@ public function testSuccessfullyCreateParserBuilder() $this->assertInstanceOf(ParserBuilder::class, $builder); } - public function testSuccessfullyCreateBlueprint() + public function testSuccessfullyCreateBlueprint(): void { $blueprint = $this->powerParser->createBlueprint( $this->blueprintsDirectory . 'valid.yaml',