From 1015b6f7c16d3cf92ccd54a84710605a8119f9eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Mon, 14 Oct 2024 13:59:07 +0200 Subject: [PATCH 1/4] fix: throw error when property range is null --- model/import/ChecksumGenerator.php | 5 +++++ test/unit/model/import/ChecksumGeneratorTest.php | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/model/import/ChecksumGenerator.php b/model/import/ChecksumGenerator.php index 15e68ed2ad..b227d83a75 100644 --- a/model/import/ChecksumGenerator.php +++ b/model/import/ChecksumGenerator.php @@ -23,6 +23,7 @@ namespace oat\taoQtiItem\model\import; use core_kernel_classes_Property as Property; +use InvalidArgumentException; use oat\taoBackOffice\model\lists\ListService; class ChecksumGenerator @@ -36,6 +37,10 @@ public function __construct(ListService $listService) public function getRangeChecksum(Property $property): string { + if ($property->getRange() === null) { + throw new InvalidArgumentException('Property range is not set'); + } + $labels = []; foreach ($this->listService->getListElements($property->getRange()) as $listEntry) { $labels[] = strtolower($listEntry->getLabel()); diff --git a/test/unit/model/import/ChecksumGeneratorTest.php b/test/unit/model/import/ChecksumGeneratorTest.php index 46f42826b1..7faf44d803 100644 --- a/test/unit/model/import/ChecksumGeneratorTest.php +++ b/test/unit/model/import/ChecksumGeneratorTest.php @@ -25,7 +25,7 @@ use core_kernel_classes_Class as ClassResource; use core_kernel_classes_Property as Property; use core_kernel_classes_Resource as Resource; -use oat\generis\model\data\Ontology; +use InvalidArgumentException; use oat\taoBackOffice\model\lists\ListService; use oat\taoQtiItem\model\import\ChecksumGenerator; use PHPUnit\Framework\TestCase; @@ -74,4 +74,13 @@ public function testGetRangeChecksum(): void $this->checksumGenerator->getRangeChecksum($this->propertyMock) ); } + + public function testThrowExceptionOnPropertyWithoutRange(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Property range is not set'); + $this->propertyMock->method('getRange')->willReturn(null); + + $this->checksumGenerator->getRangeChecksum($this->propertyMock); + } } From 25a25f786630c676367dfb938197c1f01931ca97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Mon, 21 Oct 2024 12:41:49 +0200 Subject: [PATCH 2/4] fix: Exception message reformat --- model/import/ChecksumGenerator.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/model/import/ChecksumGenerator.php b/model/import/ChecksumGenerator.php index b227d83a75..dcc36dcec0 100644 --- a/model/import/ChecksumGenerator.php +++ b/model/import/ChecksumGenerator.php @@ -38,7 +38,12 @@ public function __construct(ListService $listService) public function getRangeChecksum(Property $property): string { if ($property->getRange() === null) { - throw new InvalidArgumentException('Property range is not set'); + throw new InvalidArgumentException( + sprintf( + 'Property %s does not have range set. Only properties with range can have checksum', + $property->getUri() + ) + ); } $labels = []; From 70781d6c55a28b4d3b6b20a07421075d35177dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Mon, 21 Oct 2024 12:50:24 +0200 Subject: [PATCH 3/4] fix: exception message --- test/unit/model/import/ChecksumGeneratorTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/model/import/ChecksumGeneratorTest.php b/test/unit/model/import/ChecksumGeneratorTest.php index 7faf44d803..16974ee269 100644 --- a/test/unit/model/import/ChecksumGeneratorTest.php +++ b/test/unit/model/import/ChecksumGeneratorTest.php @@ -78,8 +78,9 @@ public function testGetRangeChecksum(): void public function testThrowExceptionOnPropertyWithoutRange(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Property range is not set'); + $this->expectExceptionMessage('Property propertyUri does not have range set. Only properties with range can have checksum'); $this->propertyMock->method('getRange')->willReturn(null); + $this->propertyMock->method('getUri')->willReturn('propertyUri'); $this->checksumGenerator->getRangeChecksum($this->propertyMock); } From 3ad8fc50ca9c877ac3a1b90e5637db46768203b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Marsza=C5=82?= Date: Mon, 21 Oct 2024 12:51:44 +0200 Subject: [PATCH 4/4] fix: phpcs --- test/unit/model/import/ChecksumGeneratorTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unit/model/import/ChecksumGeneratorTest.php b/test/unit/model/import/ChecksumGeneratorTest.php index 16974ee269..2dac305efa 100644 --- a/test/unit/model/import/ChecksumGeneratorTest.php +++ b/test/unit/model/import/ChecksumGeneratorTest.php @@ -78,7 +78,9 @@ public function testGetRangeChecksum(): void public function testThrowExceptionOnPropertyWithoutRange(): void { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Property propertyUri does not have range set. Only properties with range can have checksum'); + $this->expectExceptionMessage( + 'Property propertyUri does not have range set. Only properties with range can have checksum' + ); $this->propertyMock->method('getRange')->willReturn(null); $this->propertyMock->method('getUri')->willReturn('propertyUri');