diff --git a/src/ShoppinPal/Vend/DataObject/Entity/V2/Version.php b/src/ShoppinPal/Vend/DataObject/Entity/V2/Version.php index dbc79e3..43dd091 100644 --- a/src/ShoppinPal/Vend/DataObject/Entity/V2/Version.php +++ b/src/ShoppinPal/Vend/DataObject/Entity/V2/Version.php @@ -76,6 +76,6 @@ public function hasNewerVersion(string $entityType, ?int $lastRetrievedVersion, throw new ParameterException('Invalid entity type: ' . $entityType); } - return $lastRetrievedVersion > max($minimumVersion - 1, (int)$lastRetrievedVersion); + return $this->$entityType > max($minimumVersion - 1, (int)$lastRetrievedVersion); } } diff --git a/test/ShoppinPal/Vend/DataObject/Entity/V2/VersionTest.php b/test/ShoppinPal/Vend/DataObject/Entity/V2/VersionTest.php new file mode 100644 index 0000000..5e81803 --- /dev/null +++ b/test/ShoppinPal/Vend/DataObject/Entity/V2/VersionTest.php @@ -0,0 +1,74 @@ + null]); + + $this->assertFalse($version->hasNewerVersion('outlets', null)); + } + + public function testHasNewerVersionWithValueOverride(): void + { + $version = new Version(['outlets' => 20]); + + $this->assertFalse($version->hasNewerVersion('outlets', null, 21)); + $this->assertTrue($version->hasNewerVersion('outlets', null, 20)); + } + + public function testHasNewerVersionWithInvalidEntity(): void + { + $this->expectException(ParameterException::class); + + $version = new Version(['outlets' => null]); + + $version->hasNewerVersion('invalid', null); + } + + /** + * @dataProvider hasNewerVersionDataProvider + */ + public function testHasNewerVersionVersionChecks( + string $entityType, + int $currentVersion, + ?int $lastRetrievedVersion, + bool $expectedResult, + string $description + ): void + { + $version = new Version( + [ + $entityType => $currentVersion + ], + Version::UNKNOWN_PROPERTY_THROW, + true + ); + + $this->assertSame( + $expectedResult, + $version->hasNewerVersion($entityType, $lastRetrievedVersion), + 'Invalid result for test with ' . $description + ); + } + + public function hasNewerVersionDataProvider(): array + { + return [ + // Old behaviour for no entity + ['brands', 0, null, false, 'old behaviour for no entity for retailer'], + // New behaviour for no entity + ['outlets', 1, null, false, 'new behaviour for no entity for retailer'], + ['outlets', 9, null, false, 'just below default ignored minimum version'], + ['outlets', 10, null, true, 'at default ignored minimum version'], + ['outlets', 5000, null, true, 'no synced entity with NULL'], + ['outlets', 5000, 0, true, 'no synced entity with 0'], + ['outlets', 5000, 4999, true, 'synced entity with lover version'], + ['outlets', 5000, 5000, false, 'fully synchronised'], + ]; + } +}