Skip to content

Commit

Permalink
Merge pull request #135 from findologic/HR-1408_make_reserved_propert…
Browse files Browse the repository at this point in the history
…y_validation_more_accurate

HR-1408_make_reserved_property_validation_more_accurate (FINDO-9622)
  • Loading branch information
howard authored Nov 9, 2022
2 parents a3649c3 + 35c8418 commit aebac7a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.1', '7.2', '7.3', '7.4', '8.0']
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
stability: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }} Test
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"findologic/xml-export-schema": "^1.4"
},
"require-dev": {
"phpunit/phpunit": "^7.5|^8.5|^9.0",
"squizlabs/php_codesniffer": "^3.5"
"phpunit/phpunit": "^7.5|^8.6|^9.0",
"squizlabs/php_codesniffer": "^3.5",
"nikic/php-parser": "^4.15"
},
"scripts": {
"lint": "phpcs",
Expand Down
12 changes: 6 additions & 6 deletions src/FINDOLOGIC/Export/Data/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class Property
/**
* Reserved property keys for internal use which would be overwritten when importing
*
* /image\d+/: Image URLs of type default.
* /thumbnail\d+/: Image URLs of type thumbnail.
* /ordernumber/: The products first exported ordernumber.
* - Image URLs of type default.
* - Image URLs of type thumbnail.
* - The products first exported ordernumber.
*/
private const RESERVED_PROPERTY_KEYS = [
"/image\d+/",
"/thumbnail\d+/",
"/ordernumber/"
"/^image\d+$/",
"/^thumbnail\d+$/",
"/^ordernumber$/"
];

/** @var string */
Expand Down
11 changes: 9 additions & 2 deletions tests/FINDOLOGIC/Export/Tests/PropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function propertyKeyProvider(): array
'reserved property "image\d+"' => ['image0', true],
'reserved property "thumbnail\d+"' => ['thumbnail1', true],
'reserved property "ordernumber"' => ['ordernumber', true],
'non-reserved property key' => ['foobar', false]
'non-reserved property key' => ['foobar', false],
'non-reserved property key containing "ordernumber"' => ['main_ordernumber', false],
'non-reserved property key containing "image0"' => ['main_image0', false],
'non-reserved property key containing "thumbnail0"' => ['main_thumbnail0', false],
];
}

Expand All @@ -58,7 +61,11 @@ public function testReservedPropertyKeysCausesException(string $key, bool $shoul
$this->assertNotNull($property);
}
} catch (Exception $exception) {
$this->assertMatchesRegularExpression('/' . $key . '/', $exception->getMessage());
if (!$shouldCauseException) {
$this->fail('Using a non-reserved property key should not cause an exception.');
} else {
$this->assertMatchesRegularExpression('/' . $key . '/', $exception->getMessage());
}
}
}

Expand Down
16 changes: 8 additions & 8 deletions tests/FINDOLOGIC/Export/Tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class TestCase extends BaseTestCase
{
public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
{
if (method_exists(BaseTestCase::class, 'assertMatchesRegularExpression')) {
parent::assertMatchesRegularExpression($pattern, $string, $message);
} else {
parent::assertRegExp($pattern, $string, $message);
}
}
public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void
{
if (method_exists(BaseTestCase::class, 'assertMatchesRegularExpression')) {
parent::assertMatchesRegularExpression($pattern, $string, $message);
} else {
parent::assertRegExp($pattern, $string, $message);
}
}
}

0 comments on commit aebac7a

Please sign in to comment.