diff --git a/README.md b/README.md index e7c899f3..167d7426 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ Code of v1 is in branch "[1.x](https://github.com/CycloneDX/cyclonedx-php-librar * `HashDictionary` * `LicenseExpression`, `NamedLicense`, `SpdxLicense`, `LicenseRepository` * `Metadata` + * `Property`, `PropertyRepository` * `Tool`, `ToolRepository` * Factories for the following use cases: * Create data models from any license descriptor string diff --git a/tests/Core/Collections/BomRefRepositoryTest.php b/tests/Core/Collections/BomRefRepositoryTest.php index 480128bf..78b3b3c1 100644 --- a/tests/Core/Collections/BomRefRepositoryTest.php +++ b/tests/Core/Collections/BomRefRepositoryTest.php @@ -26,9 +26,11 @@ use CycloneDX\Core\Collections\BomRefRepository; use CycloneDX\Core\Models\BomRef; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\BomRefRepository::class)] +#[CoversClass(BomRefRepository::class)] class BomRefRepositoryTest extends TestCase { public function testEmptyConstructor(): void @@ -43,7 +45,7 @@ public function testEmptyConstructor(): void * @param BomRef[] $bomRefs * @param BomRef[] $expectedContains */ - #[\PHPUnit\Framework\Attributes\DataProvider('dpNonEmptyConstructor')] + #[DataProvider('dpNonEmptyConstructor')] public function testNonEmptyConstructor(array $bomRefs, array $expectedContains): void { $repo = new BomRefRepository(...$bomRefs); @@ -79,7 +81,7 @@ public static function dpNonEmptyConstructor(): Generator * @param BomRef[] $add * @param BomRef[] $expectedContains */ - #[\PHPUnit\Framework\Attributes\DataProvider('dpAddBomRef')] + #[DataProvider('dpAddBomRef')] public function testAddAndGetItems(array $initial, array $add, array $expectedContains): void { $repo = new BomRefRepository(...$initial); diff --git a/tests/Core/Collections/ComponentRepositoryTest.php b/tests/Core/Collections/ComponentRepositoryTest.php index 910b3d8b..03d1a446 100644 --- a/tests/Core/Collections/ComponentRepositoryTest.php +++ b/tests/Core/Collections/ComponentRepositoryTest.php @@ -26,9 +26,11 @@ use CycloneDX\Core\Collections\ComponentRepository; use CycloneDX\Core\Models\Component; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\ComponentRepository::class)] +#[CoversClass(ComponentRepository::class)] class ComponentRepositoryTest extends TestCase { public function testEmptyConstructor(): void @@ -72,7 +74,7 @@ public function testAddAndGetItems(): void /** * @param Component[] $expectedFindings */ - #[\PHPUnit\Framework\Attributes\DataProvider('dpFindComponents')] + #[DataProvider('dpFindComponents')] public function testFindItem( ComponentRepository $repo, string $findName, diff --git a/tests/Core/Collections/ExternalReferenceRepositoryTest.php b/tests/Core/Collections/ExternalReferenceRepositoryTest.php index 996ae1f2..4a85e2a2 100644 --- a/tests/Core/Collections/ExternalReferenceRepositoryTest.php +++ b/tests/Core/Collections/ExternalReferenceRepositoryTest.php @@ -25,9 +25,10 @@ use CycloneDX\Core\Collections\ExternalReferenceRepository; use CycloneDX\Core\Models\ExternalReference; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\ExternalReferenceRepository::class)] +#[CoversClass(ExternalReferenceRepository::class)] class ExternalReferenceRepositoryTest extends TestCase { public function testEmptyConstructor(): void diff --git a/tests/Core/Collections/HashDictionaryTest.php b/tests/Core/Collections/HashDictionaryTest.php index 0d4d582b..6efdc4e9 100644 --- a/tests/Core/Collections/HashDictionaryTest.php +++ b/tests/Core/Collections/HashDictionaryTest.php @@ -25,9 +25,10 @@ use CycloneDX\Core\Collections\HashDictionary; use CycloneDX\Core\Enums\HashAlgorithm; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\HashDictionary::class)] +#[CoversClass(HashDictionary::class)] class HashDictionaryTest extends TestCase { public function testNonEmptyConstructor(): void diff --git a/tests/Core/Collections/LicenseRepositoryTest.php b/tests/Core/Collections/LicenseRepositoryTest.php index bf3acb89..ba49036d 100644 --- a/tests/Core/Collections/LicenseRepositoryTest.php +++ b/tests/Core/Collections/LicenseRepositoryTest.php @@ -26,9 +26,10 @@ use CycloneDX\Core\Collections\LicenseRepository; use CycloneDX\Core\Models\License\NamedLicense; use CycloneDX\Core\Models\License\SpdxLicense; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\LicenseRepository::class)] +#[CoversClass(LicenseRepository::class)] class LicenseRepositoryTest extends TestCase { public function testEmptyConstructor(): void diff --git a/tests/Core/Collections/PropertyRepositoryTest.php b/tests/Core/Collections/PropertyRepositoryTest.php index c136a49e..926a317f 100644 --- a/tests/Core/Collections/PropertyRepositoryTest.php +++ b/tests/Core/Collections/PropertyRepositoryTest.php @@ -25,9 +25,10 @@ use CycloneDX\Core\Collections\PropertyRepository; use CycloneDX\Core\Models\Property; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\PropertyRepository::class)] +#[CoversClass(PropertyRepository::class)] class PropertyRepositoryTest extends TestCase { public function testEmptyConstructor(): void diff --git a/tests/Core/Collections/ToolRepositoryTest.php b/tests/Core/Collections/ToolRepositoryTest.php index 11c0e65b..94726ba4 100644 --- a/tests/Core/Collections/ToolRepositoryTest.php +++ b/tests/Core/Collections/ToolRepositoryTest.php @@ -25,9 +25,10 @@ use CycloneDX\Core\Collections\ToolRepository; use CycloneDX\Core\Models\Tool; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\ToolRepository::class)] +#[CoversClass(ToolRepository::class)] class ToolRepositoryTest extends TestCase { public function testEmptyConstructor(): void diff --git a/tests/Core/Enums/ComponentTypeTest.php b/tests/Core/Enums/ComponentTypeTest.php index 80ba2f0b..a6f1c31a 100644 --- a/tests/Core/Enums/ComponentTypeTest.php +++ b/tests/Core/Enums/ComponentTypeTest.php @@ -26,9 +26,10 @@ use CycloneDX\Core\Enums\ComponentType; use CycloneDX\Tests\_data\BomSpecData; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Enums\ComponentType::class)] +#[CoversClass(ComponentType::class)] class ComponentTypeTest extends TestCase { #[\PHPUnit\Framework\Attributes\DataProvider('dpSchemaValues')] diff --git a/tests/Core/Enums/ExternalReferenceTypeTest.php b/tests/Core/Enums/ExternalReferenceTypeTest.php index 96b1b281..d42f64e8 100644 --- a/tests/Core/Enums/ExternalReferenceTypeTest.php +++ b/tests/Core/Enums/ExternalReferenceTypeTest.php @@ -26,9 +26,10 @@ use CycloneDX\Core\Enums\ExternalReferenceType; use CycloneDX\Tests\_data\BomSpecData; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Enums\ExternalReferenceType::class)] +#[CoversClass(ExternalReferenceType::class)] class ExternalReferenceTypeTest extends TestCase { #[\PHPUnit\Framework\Attributes\DataProvider('dpSchemaValues')] diff --git a/tests/Core/Enums/HashAlgorithmTest.php b/tests/Core/Enums/HashAlgorithmTest.php index 21794824..e66e4822 100644 --- a/tests/Core/Enums/HashAlgorithmTest.php +++ b/tests/Core/Enums/HashAlgorithmTest.php @@ -26,12 +26,14 @@ use CycloneDX\Core\Enums\HashAlgorithm; use CycloneDX\Tests\_data\BomSpecData; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Enums\HashAlgorithm::class)] +#[CoversClass(HashAlgorithm::class)] class HashAlgorithmTest extends TestCase { - #[\PHPUnit\Framework\Attributes\DataProvider('dpSchemaValues')] + #[DataProvider('dpSchemaValues')] public function testHaseCaseForSchemaValue(string $value): void { self::assertNotNull(HashAlgorithm::tryFrom($value)); diff --git a/tests/Core/Factories/LicenseFactoryTest.php b/tests/Core/Factories/LicenseFactoryTest.php index 70f4bd16..66bb6a2f 100644 --- a/tests/Core/Factories/LicenseFactoryTest.php +++ b/tests/Core/Factories/LicenseFactoryTest.php @@ -30,13 +30,16 @@ use CycloneDX\Core\Spdx\LicenseValidator as SpdxLicenseValidator; use DomainException; use Exception; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DependsUsingShallowClone; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; use UnexpectedValueException; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Factories\LicenseFactory::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\License\LicenseExpression::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\License\SpdxLicense::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\License\NamedLicense::class)] +#[CoversClass(LicenseFactory::class)] +#[UsesClass(LicenseExpression::class)] +#[UsesClass(SpdxLicense::class)] +#[UsesClass(NamedLicense::class)] class LicenseFactoryTest extends TestCase { public function testConstructorWithValidator(): LicenseFactory @@ -66,7 +69,7 @@ public function testConstructor(): LicenseFactory return $factory; } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testSetSpdxLicenseValidator(LicenseFactory $factory): void { $spdxLicenseValidator = $this->createStub(SpdxLicenseValidator::class); diff --git a/tests/Core/Models/BomRefTest.php b/tests/Core/Models/BomRefTest.php index c7efe868..ab12a514 100644 --- a/tests/Core/Models/BomRefTest.php +++ b/tests/Core/Models/BomRefTest.php @@ -24,9 +24,11 @@ namespace CycloneDX\Tests\Core\Models; use CycloneDX\Core\Models\BomRef; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DependsUsingShallowClone; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Models\BomRef::class)] +#[CoversClass(BomRef::class)] class BomRefTest extends TestCase { public function testConstructValueDefaultsToNull(): BomRef @@ -47,21 +49,21 @@ public function testConstructSetsValue(): BomRef return $bomRef; } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructSetsValue')] + #[DependsUsingShallowClone('testConstructSetsValue')] public function testSetValueNull(BomRef $bomRef): void { $bomRef->setValue(null); self::assertNull($bomRef->getValue()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructSetsValue')] + #[DependsUsingShallowClone('testConstructSetsValue')] public function testSetValueEmptyIsNull(BomRef $bomRef): void { $bomRef->setValue(''); self::assertNull($bomRef->getValue()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructValueDefaultsToNull')] + #[DependsUsingShallowClone('testConstructValueDefaultsToNull')] public function testSetValue(BomRef $bomRef): void { $bomRef->setValue('asdewqe'); diff --git a/tests/Core/Models/BomTest.php b/tests/Core/Models/BomTest.php index cb9ea218..7567d5a4 100644 --- a/tests/Core/Models/BomTest.php +++ b/tests/Core/Models/BomTest.php @@ -26,17 +26,21 @@ use CycloneDX\Core\Collections\ComponentRepository; use CycloneDX\Core\Collections\ExternalReferenceRepository; use CycloneDX\Core\Collections\PropertyRepository; +use CycloneDX\Core\Collections\ToolRepository; use CycloneDX\Core\Models\Bom; use CycloneDX\Core\Models\Metadata; use DomainException; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DependsUsingShallowClone; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Models\Bom::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\ComponentRepository::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\Metadata::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\ToolRepository::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\ExternalReferenceRepository::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\PropertyRepository::class)] +#[CoversClass(Bom::class)] +#[UsesClass(ComponentRepository::class)] +#[UsesClass(Metadata::class)] +#[UsesClass(ToolRepository::class)] +#[UsesClass(ExternalReferenceRepository::class)] +#[UsesClass(PropertyRepository::class)] class BomTest extends TestCase { public function testConstruct(): Bom @@ -55,7 +59,7 @@ public function testConstruct(): Bom // region serialNumber setter&getter - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testSerialNumber(Bom $bom): Bom { $serialNumber = 'urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79'; @@ -67,7 +71,7 @@ public function testSerialNumber(Bom $bom): Bom return $bom; } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testSerialNumber')] + #[DependsUsingShallowClone('testSerialNumber')] public function testSerialNumberEmptyString(Bom $bom): void { $setOn = $bom->setSerialNumber(''); @@ -76,7 +80,7 @@ public function testSerialNumberEmptyString(Bom $bom): void self::assertNull($bom->getSerialNumber()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testSerialNumber')] + #[DependsUsingShallowClone('testSerialNumber')] public function testSerialNumberEmptyStringInvalidValue(Bom $bom): void { $serialNumber = uniqid('invalid-value', true); @@ -88,7 +92,7 @@ public function testSerialNumberEmptyStringInvalidValue(Bom $bom): void // region components setter&getter&modifiers - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testComponentsSetterGetter(Bom $bom): void { $components = $this->createStub(ComponentRepository::class); @@ -101,7 +105,7 @@ public function testComponentsSetterGetter(Bom $bom): void // region version setter&getter - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testVersionSetterGetter(Bom $bom): void { $version = random_int(1, 255); @@ -110,7 +114,7 @@ public function testVersionSetterGetter(Bom $bom): void self::assertSame($version, $bom->getVersion()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testVersionSetterInvalidValue(Bom $bom): void { $version = 0 - random_int(1, 255); @@ -122,7 +126,7 @@ public function testVersionSetterInvalidValue(Bom $bom): void // region metadata setter&getter - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testMetadataSetterGetter(Bom $bom): void { $metadata = $this->createStub(Metadata::class); @@ -135,7 +139,7 @@ public function testMetadataSetterGetter(Bom $bom): void // region externalReferenceRepository setter&getter - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testExternalReferenceRepositorySetterGetter(Bom $bom): void { $extRefRepo = $this->createStub(ExternalReferenceRepository::class); @@ -148,7 +152,7 @@ public function testExternalReferenceRepositorySetterGetter(Bom $bom): void // region externalReferenceRepository setter&getter - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testPropertiesSetterGetter(Bom $bom): void { $repo = $this->createStub(PropertyRepository::class); diff --git a/tests/Core/Models/ComponentTest.php b/tests/Core/Models/ComponentTest.php index 595dd7c9..6e374295 100644 --- a/tests/Core/Models/ComponentTest.php +++ b/tests/Core/Models/ComponentTest.php @@ -33,15 +33,19 @@ use CycloneDX\Core\Models\Component; use Generator; use PackageUrl\PackageUrl; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DependsUsingShallowClone; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Models\Component::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\BomRef::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\LicenseRepository::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\HashDictionary::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\ExternalReferenceRepository::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\BomRefRepository::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\PropertyRepository::class)] +#[CoversClass(Component::class)] +#[UsesClass(BomRef::class)] +#[UsesClass(LicenseRepository::class)] +#[UsesClass(HashDictionary::class)] +#[UsesClass(ExternalReferenceRepository::class)] +#[UsesClass(BomRefRepository::class)] +#[UsesClass(PropertyRepository::class)] class ComponentTest extends TestCase { public function testConstructor(): Component @@ -68,7 +72,7 @@ public function testConstructor(): Component return $component; } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testSetBomRefValue(Component $component): void { $bomRef = $component->getBomRef(); @@ -80,7 +84,7 @@ public function testSetBomRefValue(Component $component): void // region type getter&setter - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testTypeSetterGetter(Component $component): void { $type = ComponentType::FILE; @@ -94,7 +98,7 @@ public function testTypeSetterGetter(Component $component): void // region version setter&getter - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testVersionSetterGetter(Component $component): void { $version = uniqid('v', true); @@ -108,7 +112,7 @@ public function testVersionSetterGetter(Component $component): void // region licenses setter&getter - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testLicensesSetterGetter(Component $component): void { $licenses = $this->createStub(LicenseRepository::class); @@ -122,7 +126,7 @@ public function testLicensesSetterGetter(Component $component): void // region hashes setter&getter - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testHashesSetterGetter(Component $component): void { $hashes = $this->createStub(HashDictionary::class); @@ -136,7 +140,7 @@ public function testHashesSetterGetter(Component $component): void // region packageUrl setter&getter - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testPackageUrlSetterGetter(Component $component): void { $url = $this->createMock(PackageUrl::class); @@ -150,7 +154,7 @@ public function testPackageUrlSetterGetter(Component $component): void // region description setter&getter - #[\PHPUnit\Framework\Attributes\DataProvider('dpDescriptionSetterGetter')] + #[DataProvider('dpDescriptionSetterGetter')] public function testDescriptionSetterGetter(?string $description, ?string $expected): void { $component = new Component(ComponentType::CONTAINER, 'foo'); @@ -171,7 +175,7 @@ public static function dpDescriptionSetterGetter(): Generator // region author setter&getter - #[\PHPUnit\Framework\Attributes\DataProvider('dpAuthorSetterGetter')] + #[DataProvider('dpAuthorSetterGetter')] public function testAuthorSetterGetter(?string $author, ?string $expected): void { $component = new Component(ComponentType::CONTAINER, 'foo'); @@ -192,7 +196,7 @@ public static function dpAuthorSetterGetter(): Generator // region group setter&getter - #[\PHPUnit\Framework\Attributes\DataProvider('dpGroupSetterGetter')] + #[DataProvider('dpGroupSetterGetter')] public function testGroupSetterGetter(?string $group, ?string $expected): void { $component = new Component(ComponentType::CONTAINER, 'foo'); @@ -213,7 +217,7 @@ public static function dpGroupSetterGetter(): Generator // region dependenciesBomRefRepository setter&getter - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testDependenciesBomRefRepositorySetterGetter(Component $component): void { $repo = $this->createMock(BomRefRepository::class); @@ -227,7 +231,7 @@ public function testDependenciesBomRefRepositorySetterGetter(Component $componen // region externalReferenceRepository setter&getter - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testExternalReferenceRepositorySetterGetter(Component $component): void { $extRefRepo = $this->createStub(ExternalReferenceRepository::class); @@ -241,7 +245,7 @@ public function testExternalReferenceRepositorySetterGetter(Component $component // region properties setter&getter - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testGetterSetterProperties(Component $component): void { $properties = $this->createStub(PropertyRepository::class); @@ -255,7 +259,7 @@ public function testGetterSetterProperties(Component $component): void // region clone - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testCloneHasOwnBom(Component $component): void { $component->setDescription('foobar'); diff --git a/tests/Core/Models/ExternalReferenceTest.php b/tests/Core/Models/ExternalReferenceTest.php index 05b5ab3d..2834e304 100644 --- a/tests/Core/Models/ExternalReferenceTest.php +++ b/tests/Core/Models/ExternalReferenceTest.php @@ -26,10 +26,13 @@ use CycloneDX\Core\Collections\HashDictionary; use CycloneDX\Core\Enums\ExternalReferenceType; use CycloneDX\Core\Models\ExternalReference; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DependsUsingShallowClone; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Models\ExternalReference::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\HashDictionary::class)] +#[CoversClass(ExternalReference::class)] +#[UsesClass(HashDictionary::class)] class ExternalReferenceTest extends TestCase { public function testConstructor(): ExternalReference @@ -46,7 +49,7 @@ public function testConstructor(): ExternalReference // region test Type - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testTypeSetterAndGetter(ExternalReference $extRef): void { $this->assertNotSame(ExternalReferenceType::CHAT, $extRef->getType()); @@ -59,7 +62,7 @@ public function testTypeSetterAndGetter(ExternalReference $extRef): void // region test Url - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testUrlSetterAndGetter(ExternalReference $extRef): void { $this->assertNotSame('ftp://localhost/foobar', $extRef->getUrl()); @@ -68,7 +71,7 @@ public function testUrlSetterAndGetter(ExternalReference $extRef): void $this->assertSame('ftp://localhost/foobar', $extRef->getUrl()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testUrlSetterWithURN(ExternalReference $extRef): void { $this->assertNotSame('urn:uuid:bdd819e6-ee8f-42d7-a4d0-166ff44d51e8', $extRef->getUrl()); @@ -81,7 +84,7 @@ public function testUrlSetterWithURN(ExternalReference $extRef): void // region test Comment - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testCommentSetterAndGetter(ExternalReference $extRef): void { $this->assertNotSame('foobar', $extRef->getComment()); @@ -94,7 +97,7 @@ public function testCommentSetterAndGetter(ExternalReference $extRef): void // region test Comment - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testHashesSetterAndGetter(ExternalReference $extRef): void { $hashes = $this->createStub(HashDictionary::class); diff --git a/tests/Core/Models/License/LicenseExpressionTest.php b/tests/Core/Models/License/LicenseExpressionTest.php index 2952b585..1e25aa2b 100644 --- a/tests/Core/Models/License/LicenseExpressionTest.php +++ b/tests/Core/Models/License/LicenseExpressionTest.php @@ -26,9 +26,11 @@ use CycloneDX\Core\Models\License\LicenseExpression; use DomainException; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Models\License\LicenseExpression::class)] +#[CoversClass(LicenseExpression::class)] class LicenseExpressionTest extends TestCase { public function testConstructAndGet(): void @@ -73,7 +75,7 @@ public function testSetThrowsOnUnknownExpression(): void $license->setExpression("$expression"); } - #[\PHPUnit\Framework\Attributes\DataProvider('dpIsValid')] + #[DataProvider('dpIsValid')] public function testIsValid(string $expression, $expected): void { $isValid = LicenseExpression::isValid($expression); diff --git a/tests/Core/Models/License/NamedLicenseTest.php b/tests/Core/Models/License/NamedLicenseTest.php index e8c1fdf2..12307203 100644 --- a/tests/Core/Models/License/NamedLicenseTest.php +++ b/tests/Core/Models/License/NamedLicenseTest.php @@ -24,9 +24,11 @@ namespace CycloneDX\Tests\Core\Models\License; use CycloneDX\Core\Models\License\NamedLicense; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DependsUsingShallowClone; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Models\License\NamedLicense::class)] +#[CoversClass(NamedLicense::class)] class NamedLicenseTest extends TestCase { public function testConstruct(): NamedLicense @@ -38,14 +40,14 @@ public function testConstruct(): NamedLicense return $license; } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testSetName(NamedLicense $license): void { $license->setName('bar'); self::assertSame('bar', $license->getName()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testSetAndGetUrl(NamedLicense $license): NamedLicense { $url = uniqid('url', true); @@ -55,7 +57,7 @@ public function testSetAndGetUrl(NamedLicense $license): NamedLicense return $license; } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testSetAndGetUrl')] + #[DependsUsingShallowClone('testSetAndGetUrl')] public function testSetUrlNull(NamedLicense $license): void { $license->setUrl(null); diff --git a/tests/Core/Models/License/SpdxLicenseTest.php b/tests/Core/Models/License/SpdxLicenseTest.php index 40b52c6b..c6eecc78 100644 --- a/tests/Core/Models/License/SpdxLicenseTest.php +++ b/tests/Core/Models/License/SpdxLicenseTest.php @@ -26,9 +26,11 @@ use CycloneDX\Core\Models\License\SpdxLicense; use CycloneDX\Core\Spdx\LicenseValidator; use DomainException; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DependsUsingShallowClone; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Models\License\SpdxLicense::class)] +#[CoversClass(SpdxLicense::class)] class SpdxLicenseTest extends TestCase { public function testConstruct(): SpdxLicense @@ -57,7 +59,7 @@ public function testConstructThrowsWHenUnknown(): void SpdxLicense::makeValidated('foo', $spdxLicenseValidator); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testSetAndGetUrl(SpdxLicense $license): SpdxLicense { $url = uniqid('url', true); @@ -67,7 +69,7 @@ public function testSetAndGetUrl(SpdxLicense $license): SpdxLicense return $license; } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testSetAndGetUrl')] + #[DependsUsingShallowClone('testSetAndGetUrl')] public function testSetUrlNull(SpdxLicense $license): void { $license->setUrl(null); diff --git a/tests/Core/Models/MetadataTest.php b/tests/Core/Models/MetadataTest.php index 8b261df8..2d1aad81 100644 --- a/tests/Core/Models/MetadataTest.php +++ b/tests/Core/Models/MetadataTest.php @@ -28,11 +28,14 @@ use CycloneDX\Core\Models\Component; use CycloneDX\Core\Models\Metadata; use DateTime; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DependsUsingShallowClone; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Models\Metadata::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\ToolRepository::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\PropertyRepository::class)] +#[CoversClass(Metadata::class)] +#[UsesClass(ToolRepository::class)] +#[UsesClass(PropertyRepository::class)] class MetadataTest extends TestCase { public function testConstructor(): Metadata @@ -47,7 +50,7 @@ public function testConstructor(): Metadata return $metadata; } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testGetterSetterTimestamp(Metadata $metadata): void { $timestamp = $this->createStub(DateTime::class); @@ -57,7 +60,7 @@ public function testGetterSetterTimestamp(Metadata $metadata): void self::assertSame($timestamp, $metadata->getTimestamp()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testGetterSetterTools(Metadata $metadata): void { $tools = $this->createStub(ToolRepository::class); @@ -66,7 +69,7 @@ public function testGetterSetterTools(Metadata $metadata): void self::assertSame($tools, $metadata->getTools()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testGetterSetterComponent(Metadata $metadata): void { $component = $this->createStub(Component::class); @@ -76,7 +79,7 @@ public function testGetterSetterComponent(Metadata $metadata): void self::assertSame($component, $metadata->getComponent()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')] + #[DependsUsingShallowClone('testConstructor')] public function testGetterSetterProperties(Metadata $metadata): void { $properties = $this->createStub(PropertyRepository::class); diff --git a/tests/Core/Models/PropertyTest.php b/tests/Core/Models/PropertyTest.php index 71566008..39c06a27 100644 --- a/tests/Core/Models/PropertyTest.php +++ b/tests/Core/Models/PropertyTest.php @@ -24,9 +24,11 @@ namespace CycloneDX\Tests\Core\Models; use CycloneDX\Core\Models\Property; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DependsUsingShallowClone; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Models\Property::class)] +#[CoversClass(Property::class)] class PropertyTest extends TestCase { public function testConstruct(): Property @@ -42,7 +44,7 @@ public function testConstruct(): Property return $property; } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testSetterGetterName(Property $property): void { $name = uniqid('testingName', true); @@ -52,7 +54,7 @@ public function testSetterGetterName(Property $property): void self::assertSame($name, $property->getName()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testSetterGetterValue(Property $property): void { $value = uniqid('testingValue', true); diff --git a/tests/Core/Models/ToolTest.php b/tests/Core/Models/ToolTest.php index d3aa5b4d..76f435db 100644 --- a/tests/Core/Models/ToolTest.php +++ b/tests/Core/Models/ToolTest.php @@ -26,11 +26,14 @@ use CycloneDX\Core\Collections\ExternalReferenceRepository; use CycloneDX\Core\Collections\HashDictionary; use CycloneDX\Core\Models\Tool; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DependsUsingShallowClone; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Models\Tool::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\HashDictionary::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\ExternalReferenceRepository::class)] +#[CoversClass(Tool::class)] +#[UsesClass(HashDictionary::class)] +#[UsesClass(ExternalReferenceRepository::class)] class ToolTest extends TestCase { public function testConstruct(): Tool @@ -46,7 +49,7 @@ public function testConstruct(): Tool return $tool; } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testSetterGetterVersion(Tool $tool): void { $version = 'v1.2.3'; @@ -56,7 +59,7 @@ public function testSetterGetterVersion(Tool $tool): void self::assertSame($version, $tool->getVersion()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testSetterGetterVendor(Tool $tool): void { $vendor = 'myVendor'; @@ -66,7 +69,7 @@ public function testSetterGetterVendor(Tool $tool): void self::assertSame($vendor, $tool->getVendor()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testSetterGetterName(Tool $tool): void { $name = 'myName'; @@ -76,7 +79,7 @@ public function testSetterGetterName(Tool $tool): void self::assertSame($name, $tool->getName()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testSetterGetterHashDictionary(Tool $tool): void { $hashes = $this->createStub(HashDictionary::class); @@ -86,7 +89,7 @@ public function testSetterGetterHashDictionary(Tool $tool): void self::assertSame($hashes, $tool->getHashes()); } - #[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')] + #[DependsUsingShallowClone('testConstruct')] public function testSetterGetterExternalReferenceRepository(Tool $tool): void { $extRefs = $this->createStub(ExternalReferenceRepository::class); diff --git a/tests/Core/ResourcesTest.php b/tests/Core/ResourcesTest.php index 4f899f22..77fc6c28 100644 --- a/tests/Core/ResourcesTest.php +++ b/tests/Core/ResourcesTest.php @@ -25,10 +25,11 @@ use CycloneDX\Core\Resources; use Generator; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; use ReflectionClass; -#[\PHPUnit\Framework\Attributes\CoversNothing] +#[CoversNothing] class ResourcesTest extends TestCase { public function testRootDirIsReadable(): void diff --git a/tests/Core/Serialization/BaseSerializerTest.php b/tests/Core/Serialization/BaseSerializerTest.php index 27db9994..06040f6a 100644 --- a/tests/Core/Serialization/BaseSerializerTest.php +++ b/tests/Core/Serialization/BaseSerializerTest.php @@ -30,14 +30,17 @@ use CycloneDX\Core\Models\Component; use CycloneDX\Core\Models\Metadata; use CycloneDX\Core\Serialization\BaseSerializer; +use CycloneDX\Core\Serialization\BomRefDiscriminator; use Exception; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; use Throwable; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\BaseSerializer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\BomRefDiscriminator::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\BomRef::class)] +#[CoversClass(BaseSerializer::class)] +#[UsesClass(BomRefDiscriminator::class)] +#[UsesClass(BomRef::class)] class BaseSerializerTest extends TestCase { public function testSerialize(): void diff --git a/tests/Core/Serialization/BomRefDiscriminatorTest.php b/tests/Core/Serialization/BomRefDiscriminatorTest.php new file mode 100644 index 00000000..ca5533f6 --- /dev/null +++ b/tests/Core/Serialization/BomRefDiscriminatorTest.php @@ -0,0 +1,100 @@ +discriminate(); + + self::assertNotNull($bomRefNullA->getValue()); + self::assertNotNull($bomRefNullB->getValue()); + self::assertNotNull($bomRefFooA->getValue()); + self::assertNotNull($bomRefFooB->getValue()); + self::assertNotNull($bomRefBar->getValue()); + self::assertNotSame($bomRefFooA->getValue(), $bomRefFooB->getValue()); + self::assertSame('Bar', $bomRefBar->getValue()); + self::assertCount(5, array_unique([ + $bomRefNullA->getValue(), + $bomRefNullB->getValue(), + $bomRefFooA->getValue(), + $bomRefFooB->getValue(), + $bomRefBar->getValue(), + ])); + } + + public function testReset(): void + { + $bomRefNullA = new BomRef(null); + $bomRefNullB = new BomRef(null); + $bomRefFooA = new BomRef('Foo'); + $bomRefFooB = new BomRef('Foo'); + $bomRefBar = new BomRef('Bar'); + $discriminator = new BomRefDiscriminator( + $bomRefNullA, $bomRefNullB, + $bomRefFooA, $bomRefFooB, + $bomRefBar + ); + + $bomRefNullA->setValue('Baz'); + $bomRefNullB->setValue('Baz'); + $bomRefFooA->setValue('Baz'); + $bomRefFooB->setValue('Baz'); + $bomRefBar->setValue('Baz'); + + self::assertSame('Baz', $bomRefNullA->getValue()); + self::assertSame('Baz', $bomRefNullB->getValue()); + self::assertSame('Baz', $bomRefFooA->getValue()); + self::assertSame('Baz', $bomRefFooB->getValue()); + self::assertSame('Baz', $bomRefBar->getValue()); + + $discriminator->reset(); + + self::assertNull($bomRefNullA->getValue()); + self::assertNull($bomRefNullB->getValue()); + self::assertSame('Foo', $bomRefFooA->getValue()); + self::assertSame('Foo', $bomRefFooB->getValue()); + self::assertSame('Bar', $bomRefBar->getValue()); + } +} diff --git a/tests/Core/Serialization/DOM/NormalizerFactoryTest.php b/tests/Core/Serialization/DOM/NormalizerFactoryTest.php index 5cbcbfdb..a220b0ef 100644 --- a/tests/Core/Serialization/DOM/NormalizerFactoryTest.php +++ b/tests/Core/Serialization/DOM/NormalizerFactoryTest.php @@ -23,31 +23,35 @@ namespace CycloneDX\Tests\Core\Serialization\DOM; +use CycloneDX\Core\Serialization\DOM\_BaseNormalizer; use CycloneDX\Core\Serialization\DOM\NormalizerFactory; use CycloneDX\Core\Serialization\DOM\Normalizers; use CycloneDX\Core\Spec\Spec; use CycloneDX\Core\Spec\Version; use DomainException; use DOMDocument; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Depends; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\NormalizerFactory::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ComponentRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\BomNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\LicenseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\LicenseRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\HashDictionaryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ComponentNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\HashNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\MetadataNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ToolRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ToolNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ToolNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ExternalReferenceNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ExternalReferenceRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\PropertyNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\PropertyRepositoryNormalizer::class)] +#[CoversClass(NormalizerFactory::class)] +#[UsesClass(_BaseNormalizer::class)] +#[UsesClass(Normalizers\ComponentRepositoryNormalizer::class)] +#[UsesClass(Normalizers\BomNormalizer::class)] +#[UsesClass(Normalizers\LicenseNormalizer::class)] +#[UsesClass(Normalizers\LicenseRepositoryNormalizer::class)] +#[UsesClass(Normalizers\HashDictionaryNormalizer::class)] +#[UsesClass(Normalizers\ComponentNormalizer::class)] +#[UsesClass(Normalizers\HashNormalizer::class)] +#[UsesClass(Normalizers\MetadataNormalizer::class)] +#[UsesClass(Normalizers\ToolRepositoryNormalizer::class)] +#[UsesClass(Normalizers\ToolNormalizer::class)] +#[UsesClass(Normalizers\ToolNormalizer::class)] +#[UsesClass(Normalizers\ExternalReferenceNormalizer::class)] +#[UsesClass(Normalizers\ExternalReferenceRepositoryNormalizer::class)] +#[UsesClass(Normalizers\PropertyNormalizer::class)] +#[UsesClass(Normalizers\PropertyRepositoryNormalizer::class)] class NormalizerFactoryTest extends TestCase { public function testConstructor(): NormalizerFactory @@ -82,7 +86,7 @@ public function testConstructThrowsWhenUnsupported(): void new NormalizerFactory($spec); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForComponentRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForComponentRepository(); @@ -90,7 +94,7 @@ public function testMakeForComponentRepository(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForBom(NormalizerFactory $factory): void { $normalizer = $factory->makeForBom(); @@ -98,7 +102,7 @@ public function testMakeForBom(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForLicense(NormalizerFactory $factory): void { $normalizer = $factory->makeForLicense(); @@ -106,7 +110,7 @@ public function testMakeForLicense(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForDisjunctiveLicense(NormalizerFactory $factory): void { $normalizer = $factory->makeForLicenseRepository(); @@ -114,7 +118,7 @@ public function testMakeForDisjunctiveLicense(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForHashDictionary(NormalizerFactory $factory): void { $normalizer = $factory->makeForHashDictionary(); @@ -122,7 +126,7 @@ public function testMakeForHashDictionary(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForComponent(NormalizerFactory $factory): void { $normalizer = $factory->makeForComponent(); @@ -130,7 +134,7 @@ public function testMakeForComponent(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForHash(NormalizerFactory $factory): void { $normalizer = $factory->makeForHash(); @@ -138,7 +142,7 @@ public function testMakeForHash(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForMetadata(NormalizerFactory $factory): void { $normalizer = $factory->makeForMetadata(); @@ -146,7 +150,7 @@ public function testMakeForMetadata(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForToolRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForToolRepository(); @@ -154,7 +158,7 @@ public function testMakeForToolRepository(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForTool(NormalizerFactory $factory): void { $normalizer = $factory->makeForTool(); @@ -162,7 +166,7 @@ public function testMakeForTool(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForDependencies(NormalizerFactory $factory): void { $normalizer = $factory->makeForDependencies(); @@ -170,7 +174,7 @@ public function testMakeForDependencies(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForExternalReference(NormalizerFactory $factory): void { $normalizer = $factory->makeForExternalReference(); @@ -178,7 +182,7 @@ public function testMakeForExternalReference(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForExternalReferenceRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForExternalReferenceRepository(); @@ -186,7 +190,7 @@ public function testMakeForExternalReferenceRepository(NormalizerFactory $factor self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForProperty(NormalizerFactory $factory): void { $normalizer = $factory->makeForProperty(); @@ -194,7 +198,7 @@ public function testMakeForProperty(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForPropertyRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForPropertyRepository(); diff --git a/tests/Core/Serialization/DOM/Normalizers/BomNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/BomNormalizerTest.php index 56fb8199..cfc852dc 100644 --- a/tests/Core/Serialization/DOM/Normalizers/BomNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/BomNormalizerTest.php @@ -23,6 +23,7 @@ namespace CycloneDX\Tests\Core\Serialization\DOM\Normalizers; +use CycloneDX\Core\_helpers\SimpleDOM; use CycloneDX\Core\Collections\ComponentRepository; use CycloneDX\Core\Collections\ExternalReferenceRepository; use CycloneDX\Core\Collections\PropertyRepository; @@ -30,19 +31,22 @@ use CycloneDX\Core\Models\Component; use CycloneDX\Core\Models\ExternalReference; use CycloneDX\Core\Models\Metadata; +use CycloneDX\Core\Serialization\DOM\_BaseNormalizer; use CycloneDX\Core\Serialization\DOM\NormalizerFactory; use CycloneDX\Core\Serialization\DOM\Normalizers; use CycloneDX\Core\Spec\Spec; use CycloneDX\Core\Spec\Version; use CycloneDX\Tests\_traits\DomNodeAssertionTrait; use DOMDocument; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\Normalizers\BomNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\_helpers\SimpleDOM::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\ExternalReferenceRepository::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\ExternalReferenceRepository::class)] +#[CoversClass(Normalizers\BomNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(SimpleDOM::class)] +#[UsesClass(ExternalReferenceRepository::class)] +#[UsesClass(ExternalReferenceRepository::class)] class BomNormalizerTest extends TestCase { use DomNodeAssertionTrait; diff --git a/tests/Core/Serialization/DOM/Normalizers/ComponentNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/ComponentNormalizerTest.php index 7df7b61c..d4cbe278 100644 --- a/tests/Core/Serialization/DOM/Normalizers/ComponentNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/ComponentNormalizerTest.php @@ -23,6 +23,7 @@ namespace CycloneDX\Tests\Core\Serialization\DOM\Normalizers; +use CycloneDX\Core\_helpers\SimpleDOM; use CycloneDX\Core\Collections\ExternalReferenceRepository; use CycloneDX\Core\Collections\HashDictionary; use CycloneDX\Core\Collections\LicenseRepository; @@ -31,21 +32,24 @@ use CycloneDX\Core\Models\BomRef; use CycloneDX\Core\Models\Component; use CycloneDX\Core\Models\License\NamedLicense; +use CycloneDX\Core\Serialization\DOM\_BaseNormalizer; use CycloneDX\Core\Serialization\DOM\NormalizerFactory; use CycloneDX\Core\Serialization\DOM\Normalizers; -use CycloneDX\Core\Serialization\DOM\Normalizers\PropertyRepositoryNormalizer; use CycloneDX\Core\Spec\Spec; use CycloneDX\Tests\_traits\DomNodeAssertionTrait; use DomainException; use DOMDocument; use Generator; use PackageUrl\PackageUrl; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ComponentNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\_helpers\SimpleDOM::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\BomRef::class)] +#[CoversClass(Normalizers\ComponentNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(SimpleDOM::class)] +#[UsesClass(BomRef::class)] class ComponentNormalizerTest extends TestCase { use DomNodeAssertionTrait; @@ -75,7 +79,7 @@ public function testNormalizeThrowsOnUnsupportedType(): void $normalizer->normalize($component); } - #[\PHPUnit\Framework\Attributes\DataProvider('dbNormalizeMinimal')] + #[DataProvider('dbNormalizeMinimal')] public function testNormalizeMinimal(string $expected, bool $requiresComponentVersion): void { $component = $this->createConfiguredMock( @@ -374,7 +378,7 @@ public function testNormalizeProperties(): void $spec = $this->createConfiguredMock(Spec::class, [ 'supportsComponentProperties' => true, ]); - $propertiesNormalizer = $this->createMock(PropertyRepositoryNormalizer::class); + $propertiesNormalizer = $this->createMock(Normalizers\PropertyRepositoryNormalizer::class); $factory = $this->createConfiguredMock( NormalizerFactory::class, [ @@ -416,7 +420,7 @@ public function testNormalizePropertiesOmitEmpty(): void $spec = $this->createConfiguredMock(Spec::class, [ 'supportsComponentProperties' => true, ]); - $propertiesNormalizer = $this->createMock(PropertyRepositoryNormalizer::class); + $propertiesNormalizer = $this->createMock(Normalizers\PropertyRepositoryNormalizer::class); $factory = $this->createConfiguredMock( NormalizerFactory::class, [ diff --git a/tests/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizerTest.php index 26f0aaef..fbe84ca9 100644 --- a/tests/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizerTest.php @@ -23,19 +23,23 @@ namespace CycloneDX\Tests\Core\Serialization\DOM\Normalizers; +use CycloneDX\Core\_helpers\SimpleDOM; use CycloneDX\Core\Collections\ComponentRepository; use CycloneDX\Core\Models\Component; +use CycloneDX\Core\Serialization\DOM\_BaseNormalizer; use CycloneDX\Core\Serialization\DOM\NormalizerFactory; use CycloneDX\Core\Serialization\DOM\Normalizers\ComponentNormalizer; use CycloneDX\Core\Serialization\DOM\Normalizers\ComponentRepositoryNormalizer; use CycloneDX\Core\Spec\Spec; use DomainException; use DOMElement; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ComponentRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\_helpers\SimpleDOM::class)] +#[CoversClass(ComponentRepositoryNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(SimpleDOM::class)] class ComponentRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void diff --git a/tests/Core/Serialization/DOM/Normalizers/DependenciesNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/DependenciesNormalizerTest.php index caad22db..e0d006e5 100644 --- a/tests/Core/Serialization/DOM/Normalizers/DependenciesNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/DependenciesNormalizerTest.php @@ -29,17 +29,21 @@ use CycloneDX\Core\Models\BomRef; use CycloneDX\Core\Models\Component; use CycloneDX\Core\Models\Metadata; +use CycloneDX\Core\Serialization\DOM\_BaseNormalizer; use CycloneDX\Core\Serialization\DOM\NormalizerFactory; use CycloneDX\Core\Serialization\DOM\Normalizers\DependenciesNormalizer; use CycloneDX\Tests\_traits\DomNodeAssertionTrait; use DOMDocument; use Exception; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\Normalizers\DependenciesNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\BomRef::class)] +#[CoversClass(DependenciesNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(BomRef::class)] class DependenciesNormalizerTest extends TestCase { use DomNodeAssertionTrait; @@ -68,7 +72,7 @@ protected function setUp(): void /** * @param string[] $expecteds */ - #[\PHPUnit\Framework\Attributes\DataProvider('dpNormalize')] + #[DataProvider('dpNormalize')] public function testNormalize(Bom $bom, array $expecteds): void { $actuals = $this->normalizer->normalize($bom); diff --git a/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizerTest.php index 0f53398c..410a2b65 100644 --- a/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizerTest.php @@ -26,18 +26,24 @@ use CycloneDX\Core\Collections\HashDictionary; use CycloneDX\Core\Enums\ExternalReferenceType; use CycloneDX\Core\Models\ExternalReference; +use CycloneDX\Core\Serialization\DOM\_BaseNormalizer; use CycloneDX\Core\Serialization\DOM\NormalizerFactory; use CycloneDX\Core\Serialization\DOM\Normalizers; use CycloneDX\Core\Spec\Spec; +use CycloneDX\Tests\_data\XmlAnyUriData; use CycloneDX\Tests\_traits\DomNodeAssertionTrait; use DomainException; use DOMDocument; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\DataProviderExternal; +use PHPUnit\Framework\TestCase; use UnexpectedValueException; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ExternalReferenceNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\_BaseNormalizer::class)] -class ExternalReferenceNormalizerTest extends \PHPUnit\Framework\TestCase +#[CoversClass(Normalizers\ExternalReferenceNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +class ExternalReferenceNormalizerTest extends TestCase { use DomNodeAssertionTrait; @@ -68,7 +74,7 @@ public function testNormalizeTypeAndUrl(): void ); } - #[\PHPUnit\Framework\Attributes\DataProvider('dpThrowOnUnsupportedUrl')] + #[DataProvider('dpThrowOnUnsupportedUrl')] public function testThrowOnUnsupportedUrl(string $unsupportedURL): void { $spec = $this->createMock(Spec::class); @@ -285,7 +291,7 @@ public function testNormalizeHashesOmitIfNotSupported(): void // endregion normalize hashes - #[\PHPUnit\Framework\Attributes\DataProviderExternal(\CycloneDX\Tests\_data\XmlAnyUriData::class, 'dpEncodeAnyUri')] + #[DataProviderExternal(XmlAnyUriData::class, 'dpEncodeAnyUri')] public function testNormalizeUrlEncodeAnyUri(string $rawUrl, string $encodedUrl): void { $spec = $this->createMock(Spec::class); diff --git a/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizerTest.php index 0f3e505d..25bc3f07 100644 --- a/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizerTest.php @@ -25,30 +25,37 @@ use CycloneDX\Core\Collections\ExternalReferenceRepository; use CycloneDX\Core\Models\ExternalReference; +use CycloneDX\Core\Serialization\DOM\_BaseNormalizer; use CycloneDX\Core\Serialization\DOM\NormalizerFactory; -use CycloneDX\Core\Serialization\DOM\Normalizers; +use CycloneDX\Core\Serialization\DOM\Normalizers\ExternalReferenceNormalizer; +use CycloneDX\Core\Serialization\DOM\Normalizers\ExternalReferenceRepositoryNormalizer; +use CycloneDX\Core\Serialization\DOM\Normalizers\ToolNormalizer; use CycloneDX\Core\Spec\Spec; use DomainException; use DOMElement; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\UsesClass; +use PHPUnit\Framework\TestCase; use UnexpectedValueException; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ExternalReferenceRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ExternalReferenceNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ToolNormalizer::class)] -class ExternalReferenceRepositoryNormalizerTest extends \PHPUnit\Framework\TestCase +#[CoversClass(ExternalReferenceRepositoryNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(ExternalReferenceNormalizer::class)] +#[UsesClass(ToolNormalizer::class)] +class ExternalReferenceRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void { $spec = $this->createStub(Spec::class); - $externalReferenceNormalizer = $this->createMock(Normalizers\ExternalReferenceNormalizer::class); + $externalReferenceNormalizer = $this->createMock(ExternalReferenceNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForExternalReference' => $externalReferenceNormalizer, ]); - $normalizer = new Normalizers\ExternalReferenceRepositoryNormalizer($factory); + $normalizer = new ExternalReferenceRepositoryNormalizer($factory); $repo = $this->createConfiguredMock(ExternalReferenceRepository::class, ['count' => 0]); $actual = $normalizer->normalize($repo); @@ -59,12 +66,12 @@ public function testNormalizeEmpty(): void public function testNormalize(): void { $spec = $this->createStub(Spec::class); - $externalReferenceNormalizer = $this->createMock(Normalizers\ExternalReferenceNormalizer::class); + $externalReferenceNormalizer = $this->createMock(ExternalReferenceNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForExternalReference' => $externalReferenceNormalizer, ]); - $normalizer = new Normalizers\ExternalReferenceRepositoryNormalizer($factory); + $normalizer = new ExternalReferenceRepositoryNormalizer($factory); $externalReference = $this->createStub(ExternalReference::class); $repo = $this->createConfiguredMock(ExternalReferenceRepository::class, [ 'count' => 1, @@ -85,16 +92,16 @@ public function testNormalize(): void /** * @psalm-param class-string<\Exception> $exceptionClass */ - #[\PHPUnit\Framework\Attributes\DataProvider('dpNormalizeSkipsOnThrow')] + #[DataProvider('dpNormalizeSkipsOnThrow')] public function testNormalizeSkipsOnThrow(string $exceptionClass): void { $spec = $this->createStub(Spec::class); - $externalReferenceNormalizer = $this->createMock(Normalizers\ExternalReferenceNormalizer::class); + $externalReferenceNormalizer = $this->createMock(ExternalReferenceNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForExternalReference' => $externalReferenceNormalizer, ]); - $normalizer = new Normalizers\ExternalReferenceRepositoryNormalizer($factory); + $normalizer = new ExternalReferenceRepositoryNormalizer($factory); $extRef1 = $this->createStub(ExternalReference::class); $extRef2 = $this->createStub(ExternalReference::class); $tools = $this->createConfiguredMock(ExternalReferenceRepository::class, [ diff --git a/tests/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizerTest.php index 02000873..b0ed9778 100644 --- a/tests/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizerTest.php @@ -23,20 +23,24 @@ namespace CycloneDX\Tests\Core\Serialization\DOM\Normalizers; +use CycloneDX\Core\_helpers\SimpleDOM; use CycloneDX\Core\Collections\HashDictionary; use CycloneDX\Core\Enums\HashAlgorithm; +use CycloneDX\Core\Serialization\DOM\_BaseNormalizer; use CycloneDX\Core\Serialization\DOM\NormalizerFactory; use CycloneDX\Core\Serialization\DOM\Normalizers\HashDictionaryNormalizer; use CycloneDX\Core\Serialization\DOM\Normalizers\HashNormalizer; use DomainException; use DOMDocument; use DOMElement; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\Normalizers\HashDictionaryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\_helpers\SimpleDOM::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\HashNormalizer::class)] +#[CoversClass(HashDictionaryNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(SimpleDOM::class)] +#[UsesClass(HashNormalizer::class)] class HashDictionaryNormalizerTest extends TestCase { public function testConstructor(): void diff --git a/tests/Core/Serialization/DOM/Normalizers/LicenseNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/LicenseNormalizerTest.php index 03c0eaa7..0f76c56d 100644 --- a/tests/Core/Serialization/DOM/Normalizers/LicenseNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/LicenseNormalizerTest.php @@ -26,16 +26,20 @@ use CycloneDX\Core\Models\License\LicenseExpression; use CycloneDX\Core\Models\License\NamedLicense; use CycloneDX\Core\Models\License\SpdxLicense; +use CycloneDX\Core\Serialization\DOM\_BaseNormalizer; use CycloneDX\Core\Serialization\DOM\NormalizerFactory; use CycloneDX\Core\Serialization\DOM\Normalizers\LicenseNormalizer; use CycloneDX\Core\Spec\Spec; use CycloneDX\Tests\_traits\DomNodeAssertionTrait; use DOMDocument; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\Normalizers\LicenseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\_BaseNormalizer::class)] -class LicenseNormalizerTest extends \PHPUnit\Framework\TestCase +#[CoversClass(LicenseNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +class LicenseNormalizerTest extends TestCase { use DomNodeAssertionTrait; @@ -43,7 +47,7 @@ class LicenseNormalizerTest extends \PHPUnit\Framework\TestCase * @psalm-param class-string $licenseClass * @psalm-param array $licenseConfig */ - #[\PHPUnit\Framework\Attributes\DataProvider('dpNormalize')] + #[DataProvider('dpNormalize')] public function testNormalize(string $licenseClass, array $licenseConfig, string $expectedXML): void { /** @var (LicenseExpression|SpdxLicense|NamedLicense)&\PHPUnit\Framework\MockObject\MockObject */ @@ -77,8 +81,8 @@ public static function dpNormalize(): Generator 'getUrl' => 'https://foo.bar', ], ''. - 'MIT'. - 'https://foo.bar'. + 'MIT'. + 'https://foo.bar'. '', ]; yield 'named license' => [ @@ -87,8 +91,8 @@ public static function dpNormalize(): Generator 'getUrl' => 'https://foo.bar', ], ''. - 'copyright by the crew'. - 'https://foo.bar'. + 'copyright by the crew'. + 'https://foo.bar'. '', ]; } diff --git a/tests/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizerTest.php index 18e53e7d..5093bdda 100644 --- a/tests/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizerTest.php @@ -25,16 +25,18 @@ use CycloneDX\Core\Collections\LicenseRepository; use CycloneDX\Core\Models\License\NamedLicense; +use CycloneDX\Core\Serialization\DOM\_BaseNormalizer; use CycloneDX\Core\Serialization\DOM\NormalizerFactory; use CycloneDX\Core\Serialization\DOM\Normalizers\LicenseNormalizer; use CycloneDX\Core\Serialization\DOM\Normalizers\LicenseRepositoryNormalizer; use CycloneDX\Core\Spec\Spec; use CycloneDX\Tests\_traits\DomNodeAssertionTrait; use DOMElement; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\Normalizers\LicenseRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\_BaseNormalizer::class)] +#[CoversClass(LicenseRepositoryNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] class LicenseRepositoryNormalizerTest extends TestCase { use DomNodeAssertionTrait; diff --git a/tests/Core/Serialization/DOM/Normalizers/MetadataNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/MetadataNormalizerTest.php index 269adbef..7aaf95af 100644 --- a/tests/Core/Serialization/DOM/Normalizers/MetadataNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/MetadataNormalizerTest.php @@ -27,6 +27,7 @@ use CycloneDX\Core\Collections\ToolRepository; use CycloneDX\Core\Models\Component; use CycloneDX\Core\Models\Metadata; +use CycloneDX\Core\Serialization\DOM\_BaseNormalizer; use CycloneDX\Core\Serialization\DOM\NormalizerFactory; use CycloneDX\Core\Serialization\DOM\Normalizers; use CycloneDX\Core\Spec\Spec; @@ -35,11 +36,13 @@ use DateTimeZone; use DomainException; use DOMDocument; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\Normalizers\MetadataNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ComponentNormalizer::class)] +#[CoversClass(Normalizers\MetadataNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(Normalizers\ComponentNormalizer::class)] class MetadataNormalizerTest extends TestCase { use DomNodeAssertionTrait; diff --git a/tests/Core/Serialization/DOM/Normalizers/PropertyNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/PropertyNormalizerTest.php new file mode 100644 index 00000000..4b2f73d4 --- /dev/null +++ b/tests/Core/Serialization/DOM/Normalizers/PropertyNormalizerTest.php @@ -0,0 +1,95 @@ +createConfiguredMock( + Property::class, + [ + 'getName' => 'myName', + 'getValue' => 'myValue', + ] + ); + $spec = $this->createMock(Spec::class); + $factory = $this->createConfiguredMock( + NormalizerFactory::class, + [ + 'getSpec' => $spec, + 'getDocument' => new DOMDocument(), + ] + ); + $normalizer = new PropertyNormalizer($factory); + + $actual = $normalizer->normalize($property); + + self::assertStringEqualsDomNode( + 'myValue', + $actual + ); + } + + public function testNormalizeThrowsWhenNameEmpty(): void + { + $property = $this->createConfiguredMock( + Property::class, + [ + 'getName' => '', + 'getValue' => 'myValue', + ] + ); + $spec = $this->createMock(Spec::class); + $factory = $this->createConfiguredMock( + NormalizerFactory::class, + [ + 'getSpec' => $spec, + 'getDocument' => new DOMDocument(), + ] + ); + $normalizer = new PropertyNormalizer($factory); + + $this->expectException(DomainException::class); + $this->expectExceptionMessageMatches('/name/'); + + $normalizer->normalize($property); + } +} diff --git a/tests/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizerTest.php new file mode 100644 index 00000000..79587ffa --- /dev/null +++ b/tests/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizerTest.php @@ -0,0 +1,117 @@ +createStub(Spec::class); + $propertyNormalizer = $this->createMock(PropertyNormalizer::class); + $factory = $this->createConfiguredMock(NormalizerFactory::class, [ + 'getSpec' => $spec, + 'getDocument' => new DOMDocument(), + 'makeForProperty' => $propertyNormalizer, + ]); + + $normalizer = new PropertyRepositoryNormalizer($factory); + $properties = $this->createConfiguredMock(PropertyRepository::class, ['count' => 0]); + + $actual = $normalizer->normalize($properties); + + self::assertSame([], $actual); + } + + public function testNormalize(): void + { + $spec = $this->createStub(Spec::class); + $propertyNormalizer = $this->createMock(PropertyNormalizer::class); + $factory = $this->createConfiguredMock(NormalizerFactory::class, [ + 'getSpec' => $spec, + 'getDocument' => new DOMDocument(), + 'makeForProperty' => $propertyNormalizer, + ]); + $normalizer = new PropertyRepositoryNormalizer($factory); + $property = $this->createStub(Property::class); + $properties = $this->createConfiguredMock(PropertyRepository::class, [ + 'count' => 1, + 'getItems' => [$property], + ]); + + $FakeProperty = $this->createStub(DOMElement::class); + + $propertyNormalizer->expects(self::once())->method('normalize') + ->with($property) + ->willReturn($FakeProperty); + + $actual = $normalizer->normalize($properties); + + self::assertSame([$FakeProperty], $actual); + } + + public function testNormalizeSkippedWhenThrown(): void + { + $spec = $this->createStub(Spec::class); + $propertyNormalizer = $this->createMock(PropertyNormalizer::class); + $factory = $this->createConfiguredMock(NormalizerFactory::class, [ + 'getSpec' => $spec, + 'getDocument' => new DOMDocument(), + 'makeForProperty' => $propertyNormalizer, + ]); + $normalizer = new PropertyRepositoryNormalizer($factory); + $property = $this->createStub(Property::class); + $properties = $this->createConfiguredMock(PropertyRepository::class, [ + 'count' => 1, + 'getItems' => [$property], + ]); + + $propertyNormalizer->expects(self::once())->method('normalize') + ->with($property) + ->willThrowException(new DomainException()); + + $actual = $normalizer->normalize($properties); + + self::assertSame([], $actual); + } +} diff --git a/tests/Core/Serialization/DOM/Normalizers/ToolNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/ToolNormalizerTest.php index dd2dfb7c..1d4c49e0 100644 --- a/tests/Core/Serialization/DOM/Normalizers/ToolNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/ToolNormalizerTest.php @@ -27,6 +27,7 @@ use CycloneDX\Core\Collections\ExternalReferenceRepository; use CycloneDX\Core\Collections\HashDictionary; use CycloneDX\Core\Models\Tool; +use CycloneDX\Core\Serialization\DOM\_BaseNormalizer; use CycloneDX\Core\Serialization\DOM\NormalizerFactory; use CycloneDX\Core\Serialization\DOM\Normalizers\ExternalReferenceRepositoryNormalizer; use CycloneDX\Core\Serialization\DOM\Normalizers\HashDictionaryNormalizer; @@ -34,11 +35,13 @@ use CycloneDX\Core\Spec\Spec; use CycloneDX\Tests\_traits\DomNodeAssertionTrait; use DOMDocument; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ToolNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\HashDictionaryNormalizer::class)] +#[CoversClass(ToolNormalizer::class)] +#[UsesClass(_BaseNormalizer::class)] +#[UsesClass(HashDictionaryNormalizer::class)] class ToolNormalizerTest extends TestCase { use DomNodeAssertionTrait; diff --git a/tests/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizerTest.php index e58682ee..fd31836f 100644 --- a/tests/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizerTest.php @@ -25,17 +25,20 @@ use CycloneDX\Core\Collections\ToolRepository; use CycloneDX\Core\Models\Tool; +use CycloneDX\Core\Serialization\DOM\_BaseNormalizer; use CycloneDX\Core\Serialization\DOM\NormalizerFactory; use CycloneDX\Core\Serialization\DOM\Normalizers\ToolNormalizer; use CycloneDX\Core\Serialization\DOM\Normalizers\ToolRepositoryNormalizer; use CycloneDX\Core\Spec\Spec; use DomainException; use DOMElement; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ToolRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\DOM\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\ToolNormalizer::class)] +#[CoversClass(ToolRepositoryNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(ToolNormalizer::class)] class ToolRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void diff --git a/tests/Core/Serialization/JSON/NormalizerFactoryTest.php b/tests/Core/Serialization/JSON/NormalizerFactoryTest.php index e04efb75..c393fe3f 100644 --- a/tests/Core/Serialization/JSON/NormalizerFactoryTest.php +++ b/tests/Core/Serialization/JSON/NormalizerFactoryTest.php @@ -23,31 +23,35 @@ namespace CycloneDX\Tests\Core\Serialization\JSON; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; use CycloneDX\Core\Serialization\JSON\Normalizers; use CycloneDX\Core\Spec\Spec; use CycloneDX\Core\Spec\Version; use DomainException; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Depends; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\NormalizerFactory::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ComponentRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\BomNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\LicenseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\LicenseRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\HashDictionaryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ComponentNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\HashNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\MetadataNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ToolRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ToolNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ToolNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\DependenciesNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ExternalReferenceNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ExternalReferenceRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\PropertyNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\PropertyRepositoryNormalizer::class)] +#[CoversClass(NormalizerFactory::class)] +#[UsesClass(_BaseNormalizer::class)] +#[UsesClass(Normalizers\ComponentRepositoryNormalizer::class)] +#[UsesClass(Normalizers\BomNormalizer::class)] +#[UsesClass(Normalizers\LicenseNormalizer::class)] +#[UsesClass(Normalizers\LicenseRepositoryNormalizer::class)] +#[UsesClass(Normalizers\HashDictionaryNormalizer::class)] +#[UsesClass(Normalizers\ComponentNormalizer::class)] +#[UsesClass(Normalizers\HashNormalizer::class)] +#[UsesClass(Normalizers\MetadataNormalizer::class)] +#[UsesClass(Normalizers\ToolRepositoryNormalizer::class)] +#[UsesClass(Normalizers\ToolNormalizer::class)] +#[UsesClass(Normalizers\ToolNormalizer::class)] +#[UsesClass(Normalizers\DependenciesNormalizer::class)] +#[UsesClass(Normalizers\ExternalReferenceNormalizer::class)] +#[UsesClass(Normalizers\ExternalReferenceRepositoryNormalizer::class)] +#[UsesClass(Normalizers\PropertyNormalizer::class)] +#[UsesClass(Normalizers\PropertyRepositoryNormalizer::class)] class NormalizerFactoryTest extends TestCase { public function testConstructor(): NormalizerFactory @@ -81,7 +85,7 @@ public function testConstructThrowsWhenUnsupported(): void new NormalizerFactory($spec); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForComponentRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForComponentRepository(); @@ -89,7 +93,7 @@ public function testMakeForComponentRepository(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForBom(NormalizerFactory $factory): void { $normalizer = $factory->makeForBom(); @@ -97,7 +101,7 @@ public function testMakeForBom(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForLicense(NormalizerFactory $factory): void { $normalizer = $factory->makeForLicense(); @@ -105,7 +109,7 @@ public function testMakeForLicense(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForLicenseRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForLicenseRepository(); @@ -113,7 +117,7 @@ public function testMakeForLicenseRepository(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForHashDictionary(NormalizerFactory $factory): void { $normalizer = $factory->makeForHashDictionary(); @@ -121,7 +125,7 @@ public function testMakeForHashDictionary(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForComponent(NormalizerFactory $factory): void { $normalizer = $factory->makeForComponent(); @@ -129,7 +133,7 @@ public function testMakeForComponent(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForHash(NormalizerFactory $factory): void { $normalizer = $factory->makeForHash(); @@ -137,7 +141,7 @@ public function testMakeForHash(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForMetadata(NormalizerFactory $factory): void { $normalizer = $factory->makeForMetadata(); @@ -145,7 +149,7 @@ public function testMakeForMetadata(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForToolRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForToolRepository(); @@ -153,7 +157,7 @@ public function testMakeForToolRepository(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForTool(NormalizerFactory $factory): void { $normalizer = $factory->makeForTool(); @@ -161,7 +165,7 @@ public function testMakeForTool(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForDependencies(NormalizerFactory $factory): void { $normalizer = $factory->makeForDependencies(); @@ -169,7 +173,7 @@ public function testMakeForDependencies(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForExternalReference(NormalizerFactory $factory): void { $normalizer = $factory->makeForExternalReference(); @@ -177,7 +181,7 @@ public function testMakeForExternalReference(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForExternalReferenceRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForExternalReferenceRepository(); @@ -185,7 +189,7 @@ public function testMakeForExternalReferenceRepository(NormalizerFactory $factor self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForProperty(NormalizerFactory $factory): void { $normalizer = $factory->makeForProperty(); @@ -193,7 +197,7 @@ public function testMakeForProperty(NormalizerFactory $factory): void self::assertSame($factory, $normalizer->getNormalizerFactory()); } - #[\PHPUnit\Framework\Attributes\Depends('testConstructor')] + #[Depends('testConstructor')] public function testMakeForPropertyRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForPropertyRepository(); diff --git a/tests/Core/Serialization/JSON/Normalizers/BomNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/BomNormalizerTest.php index 62ca44f6..92207939 100644 --- a/tests/Core/Serialization/JSON/Normalizers/BomNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/BomNormalizerTest.php @@ -23,25 +23,30 @@ namespace CycloneDX\Tests\Core\Serialization\JSON\Normalizers; +use CycloneDX\Core\_helpers\Assert as AssertHelper; use CycloneDX\Core\Collections\ComponentRepository; use CycloneDX\Core\Collections\ExternalReferenceRepository; +use CycloneDX\Core\Collections\PropertyRepository; use CycloneDX\Core\Models\Bom; use CycloneDX\Core\Models\Component; use CycloneDX\Core\Models\ExternalReference; use CycloneDX\Core\Models\Metadata; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; use CycloneDX\Core\Serialization\JSON\Normalizers; use CycloneDX\Core\Spec\Spec; use CycloneDX\Core\Spec\Version; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\Normalizers\BomNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\DependenciesNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\MetadataNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\_helpers\Assert::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\ExternalReferenceRepository::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\ExternalReferenceRepository::class)] +#[CoversClass(Normalizers\BomNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(Normalizers\DependenciesNormalizer::class)] +#[UsesClass(Normalizers\MetadataNormalizer::class)] +#[UsesClass(AssertHelper::class)] +#[UsesClass(ExternalReferenceRepository::class)] +#[UsesClass(ExternalReferenceRepository::class)] class BomNormalizerTest extends TestCase { public function testNormalize(): void @@ -450,4 +455,91 @@ public function testNormalizeExternalReferencesOmittedWHenEmpty(): void } // endregion external references + + // region properties + + public function testNormalizeProperties(): void + { + $bom = $this->createConfiguredMock( + Bom::class, + [ + 'getVersion' => 23, + 'getProperties' => $this->createConfiguredMock(PropertyRepository::class, ['count' => 2]), + ] + ); + $spec = $this->createConfiguredMock(Spec::class, [ + 'getVersion' => Version::v1dot4, + 'supportsBomProperties' => true, + ]); + $propertiesNormalizer = $this->createMock(Normalizers\PropertyRepositoryNormalizer::class); + $factory = $this->createConfiguredMock( + NormalizerFactory::class, + [ + 'getSpec' => $spec, + 'makeForPropertyRepository' => $propertiesNormalizer, + ] + ); + $normalizer = new Normalizers\BomNormalizer($factory); + + $propertiesNormalizer->expects(self::once()) + ->method('normalize') + ->with($bom->getProperties()) + ->willReturn( + ['FakeProperties' => 'dummy']); + + $actual = $normalizer->normalize($bom); + + self::assertSame( + [ + '$schema' => 'http://cyclonedx.org/schema/bom-1.4.schema.json', + 'bomFormat' => 'CycloneDX', + 'specVersion' => '1.4', + 'version' => 23, + 'components' => [], + 'properties' => ['FakeProperties' => 'dummy'], + ], + $actual + ); + } + + public function testNormalizePropertiesOmitEMpty(): void + { + $bom = $this->createConfiguredMock( + Bom::class, + [ + 'getVersion' => 23, + 'getProperties' => $this->createConfiguredMock(PropertyRepository::class, ['count' => 0]), + ] + ); + $spec = $this->createConfiguredMock(Spec::class, [ + 'getVersion' => Version::v1dot4, + 'supportsBomProperties' => true, + ]); + $propertiesNormalizer = $this->createMock(Normalizers\PropertyRepositoryNormalizer::class); + $factory = $this->createConfiguredMock( + NormalizerFactory::class, + [ + 'getSpec' => $spec, + 'makeForPropertyRepository' => $propertiesNormalizer, + ] + ); + $normalizer = new Normalizers\BomNormalizer($factory); + + $propertiesNormalizer->expects(self::never())->method('normalize'); + + $actual = $normalizer->normalize($bom); + + self::assertSame( + [ + '$schema' => 'http://cyclonedx.org/schema/bom-1.4.schema.json', + 'bomFormat' => 'CycloneDX', + 'specVersion' => '1.4', + 'version' => 23, + 'components' => [], + ], + $actual + ); + } + + // endregion properties } diff --git a/tests/Core/Serialization/JSON/Normalizers/ComponentNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/ComponentNormalizerTest.php index dc3d22a6..e12fc6d9 100644 --- a/tests/Core/Serialization/JSON/Normalizers/ComponentNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/ComponentNormalizerTest.php @@ -30,19 +30,24 @@ use CycloneDX\Core\Enums\ComponentType; use CycloneDX\Core\Models\BomRef; use CycloneDX\Core\Models\Component; +use CycloneDX\Core\Serialization\DOM\Normalizers\PropertyRepositoryNormalizer; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; use CycloneDX\Core\Serialization\JSON\Normalizers; use CycloneDX\Core\Spec\Spec; use DomainException; use Generator; use PackageUrl\PackageUrl; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ComponentNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\BomRef::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\DOM\Normalizers\PropertyRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\PropertyRepositoryNormalizer::class)] +#[CoversClass(Normalizers\ComponentNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(BomRef::class)] +#[UsesClass(PropertyRepositoryNormalizer::class)] +#[UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\PropertyRepositoryNormalizer::class)] class ComponentNormalizerTest extends TestCase { public function testNormalizeThrowsOnUnsupportedType(): void @@ -69,7 +74,7 @@ public function testNormalizeThrowsOnUnsupportedType(): void $normalizer->normalize($component); } - #[\PHPUnit\Framework\Attributes\DataProvider('dptNormalizeMinimal')] + #[DataProvider('dptNormalizeMinimal')] public function testNormalizeMinimal(array $expected, bool $requiresComponentVersion): void { $component = $this->createConfiguredMock( diff --git a/tests/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizerTest.php index 7d88fe59..48d3971a 100644 --- a/tests/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizerTest.php @@ -25,15 +25,17 @@ use CycloneDX\Core\Collections\ComponentRepository; use CycloneDX\Core\Models\Component; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; use CycloneDX\Core\Serialization\JSON\Normalizers\ComponentNormalizer; use CycloneDX\Core\Serialization\JSON\Normalizers\ComponentRepositoryNormalizer; use CycloneDX\Core\Spec\Spec; use DomainException; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ComponentRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] +#[CoversClass(ComponentRepositoryNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] class ComponentRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void diff --git a/tests/Core/Serialization/JSON/Normalizers/DependenciesNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/DependenciesNormalizerTest.php index 95235d10..7ef03bd5 100644 --- a/tests/Core/Serialization/JSON/Normalizers/DependenciesNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/DependenciesNormalizerTest.php @@ -29,15 +29,19 @@ use CycloneDX\Core\Models\BomRef; use CycloneDX\Core\Models\Component; use CycloneDX\Core\Models\Metadata; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; use CycloneDX\Core\Serialization\JSON\Normalizers\DependenciesNormalizer; use Exception; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\Normalizers\DependenciesNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\BomRef::class)] +#[CoversClass(DependenciesNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(BomRef::class)] class DependenciesNormalizerTest extends TestCase { /** @@ -59,7 +63,7 @@ protected function setUp(): void /** * @param string[] $expecteds */ - #[\PHPUnit\Framework\Attributes\DataProvider('dpNormalize')] + #[DataProvider('dpNormalize')] public function testNormalize(Bom $bom, array $expecteds): void { $actuals = $this->normalizer->normalize($bom); diff --git a/tests/Core/Serialization/JSON/Normalizers/ExternalReferenceNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/ExternalReferenceNormalizerTest.php index a6e1ff02..aa11aa68 100644 --- a/tests/Core/Serialization/JSON/Normalizers/ExternalReferenceNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/ExternalReferenceNormalizerTest.php @@ -26,16 +26,19 @@ use CycloneDX\Core\Collections\HashDictionary; use CycloneDX\Core\Enums\ExternalReferenceType; use CycloneDX\Core\Models\ExternalReference; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; use CycloneDX\Core\Serialization\JSON\Normalizers; use CycloneDX\Core\Spec\Spec; use DomainException; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\TestCase; use UnexpectedValueException; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ExternalReferenceNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] -class ExternalReferenceNormalizerTest extends \PHPUnit\Framework\TestCase +#[CoversClass(Normalizers\ExternalReferenceNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +class ExternalReferenceNormalizerTest extends TestCase { public function testNormalizeTypeAndUrl(): void { diff --git a/tests/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizerTest.php index d13cea2e..1dc17d41 100644 --- a/tests/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizerTest.php @@ -25,27 +25,33 @@ use CycloneDX\Core\Collections\ExternalReferenceRepository; use CycloneDX\Core\Models\ExternalReference; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; -use CycloneDX\Core\Serialization\JSON\Normalizers; +use CycloneDX\Core\Serialization\JSON\Normalizers\ExternalReferenceNormalizer; +use CycloneDX\Core\Serialization\JSON\Normalizers\ExternalReferenceRepositoryNormalizer; +use CycloneDX\Core\Serialization\JSON\Normalizers\ToolNormalizer; use CycloneDX\Core\Spec\Spec; use DomainException; - -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ExternalReferenceRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ExternalReferenceNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ToolNormalizer::class)] -class ExternalReferenceRepositoryNormalizerTest extends \PHPUnit\Framework\TestCase +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; +use PHPUnit\Framework\TestCase; + +#[CoversClass(ExternalReferenceRepositoryNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(ExternalReferenceNormalizer::class)] +#[UsesClass(ToolNormalizer::class)] +class ExternalReferenceRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void { $spec = $this->createStub(Spec::class); - $externalReferenceNormalizer = $this->createMock(Normalizers\ExternalReferenceNormalizer::class); + $externalReferenceNormalizer = $this->createMock(ExternalReferenceNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForExternalReference' => $externalReferenceNormalizer, ]); - $normalizer = new Normalizers\ExternalReferenceRepositoryNormalizer($factory); + $normalizer = new ExternalReferenceRepositoryNormalizer($factory); $repo = $this->createConfiguredMock(ExternalReferenceRepository::class, ['count' => 0]); $actual = $normalizer->normalize($repo); @@ -56,12 +62,12 @@ public function testNormalizeEmpty(): void public function testNormalize(): void { $spec = $this->createStub(Spec::class); - $externalReferenceNormalizer = $this->createMock(Normalizers\ExternalReferenceNormalizer::class); + $externalReferenceNormalizer = $this->createMock(ExternalReferenceNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForExternalReference' => $externalReferenceNormalizer, ]); - $normalizer = new Normalizers\ExternalReferenceRepositoryNormalizer($factory); + $normalizer = new ExternalReferenceRepositoryNormalizer($factory); $externalReference = $this->createStub(ExternalReference::class); $repo = $this->createConfiguredMock(ExternalReferenceRepository::class, [ 'count' => 1, @@ -81,12 +87,12 @@ public function testNormalize(): void public function testNormalizeSkipsOnThrow(): void { $spec = $this->createStub(Spec::class); - $externalReferenceNormalizer = $this->createMock(Normalizers\ExternalReferenceNormalizer::class); + $externalReferenceNormalizer = $this->createMock(ExternalReferenceNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForExternalReference' => $externalReferenceNormalizer, ]); - $normalizer = new Normalizers\ExternalReferenceRepositoryNormalizer($factory); + $normalizer = new ExternalReferenceRepositoryNormalizer($factory); $extRef1 = $this->createStub(ExternalReference::class); $extRef2 = $this->createStub(ExternalReference::class); $tools = $this->createConfiguredMock(ExternalReferenceRepository::class, [ diff --git a/tests/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizerTest.php index bca9bac2..72bafe75 100644 --- a/tests/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizerTest.php @@ -25,14 +25,16 @@ use CycloneDX\Core\Collections\HashDictionary; use CycloneDX\Core\Enums\HashAlgorithm; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; use CycloneDX\Core\Serialization\JSON\Normalizers\HashDictionaryNormalizer; use CycloneDX\Core\Serialization\JSON\Normalizers\HashNormalizer; use DomainException; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\Normalizers\HashDictionaryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] +#[CoversClass(HashDictionaryNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] class HashDictionaryNormalizerTest extends TestCase { public function testConstructor(): void diff --git a/tests/Core/Serialization/JSON/Normalizers/HashNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/HashNormalizerTest.php index 9dfd782f..2f91156b 100644 --- a/tests/Core/Serialization/JSON/Normalizers/HashNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/HashNormalizerTest.php @@ -24,14 +24,16 @@ namespace CycloneDX\Tests\Core\Serialization\JSON\Normalizers; use CycloneDX\Core\Enums\HashAlgorithm; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; use CycloneDX\Core\Serialization\JSON\Normalizers\HashNormalizer; use CycloneDX\Core\Spec\Spec; use DomainException; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\Normalizers\HashNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] +#[CoversClass(HashNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] class HashNormalizerTest extends TestCase { public function testConstructor(): void diff --git a/tests/Core/Serialization/JSON/Normalizers/LicenseNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/LicenseNormalizerTest.php index 5e2c8657..c45831e5 100644 --- a/tests/Core/Serialization/JSON/Normalizers/LicenseNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/LicenseNormalizerTest.php @@ -26,20 +26,23 @@ use CycloneDX\Core\Models\License\LicenseExpression; use CycloneDX\Core\Models\License\NamedLicense; use CycloneDX\Core\Models\License\SpdxLicense; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; use CycloneDX\Core\Serialization\JSON\Normalizers\LicenseNormalizer; use CycloneDX\Core\Spec\Spec; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\Normalizers\LicenseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] +#[CoversClass(LicenseNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] class LicenseNormalizerTest extends \PHPUnit\Framework\TestCase { /** * @psalm-param class-string $licenseClass * @psalm-param array $licenseMockConf */ - #[\PHPUnit\Framework\Attributes\DataProvider('dpNormalize')] + #[DataProvider('dpNormalize')] public function testNormalize(string $licenseClass, array $licenseMockConf, array $expected): void { /** @var (LicenseExpression|SpdxLicense|NamedLicense)&\PHPUnit\Framework\MockObject\MockObject */ diff --git a/tests/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizerTest.php index 77f87283..c6becff0 100644 --- a/tests/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizerTest.php @@ -25,14 +25,16 @@ use CycloneDX\Core\Collections\LicenseRepository; use CycloneDX\Core\Models\License\NamedLicense; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; use CycloneDX\Core\Serialization\JSON\Normalizers\LicenseNormalizer; use CycloneDX\Core\Serialization\JSON\Normalizers\LicenseRepositoryNormalizer; use CycloneDX\Core\Spec\Spec; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\Normalizers\LicenseRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] +#[CoversClass(LicenseRepositoryNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] class LicenseRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void diff --git a/tests/Core/Serialization/JSON/Normalizers/MetadataNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/MetadataNormalizerTest.php index 558eec2a..0265dd29 100644 --- a/tests/Core/Serialization/JSON/Normalizers/MetadataNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/MetadataNormalizerTest.php @@ -27,19 +27,22 @@ use CycloneDX\Core\Collections\ToolRepository; use CycloneDX\Core\Models\Component; use CycloneDX\Core\Models\Metadata; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; use CycloneDX\Core\Serialization\JSON\Normalizers; use CycloneDX\Core\Spec\Spec; use DateTime; use DateTimeZone; use DomainException; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\Normalizers\MetadataNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ComponentNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\PropertyRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\PropertyRepositoryNormalizer::class)] +#[CoversClass(Normalizers\MetadataNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(Normalizers\ComponentNormalizer::class)] +#[UsesClass(Normalizers\PropertyRepositoryNormalizer::class)] +#[UsesClass(Normalizers\PropertyRepositoryNormalizer::class)] class MetadataNormalizerTest extends TestCase { public function testNormalizeEmpty(): void diff --git a/tests/Core/Serialization/JSON/Normalizers/PropertyNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/PropertyNormalizerTest.php new file mode 100644 index 00000000..bfe3d5b6 --- /dev/null +++ b/tests/Core/Serialization/JSON/Normalizers/PropertyNormalizerTest.php @@ -0,0 +1,82 @@ +createConfiguredMock( + Property::class, + [ + 'getName' => 'myName', + 'getValue' => 'myValue', + ] + ); + $spec = $this->createMock(Spec::class); + $factory = $this->createConfiguredMock(NormalizerFactory::class, ['getSpec' => $spec]); + $normalizer = new PropertyNormalizer($factory); + + $actual = $normalizer->normalize($property); + + self::assertSame( + [ + 'name' => 'myName', + 'value' => 'myValue', + ], + $actual + ); + } + + public function testNormalizeNoNameThrows(): void + { + $property = $this->createConfiguredMock( + Property::class, + [ + 'getName' => '', + 'getValue' => 'myValue', + ] + ); + $spec = $this->createMock(Spec::class); + $factory = $this->createConfiguredMock(NormalizerFactory::class, ['getSpec' => $spec]); + $normalizer = new PropertyNormalizer($factory); + + $this->expectException(DomainException::class); + $this->expectExceptionMessageMatches('/name/'); + + $normalizer->normalize($property); + } +} diff --git a/tests/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizerTest.php new file mode 100644 index 00000000..4bfa6848 --- /dev/null +++ b/tests/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizerTest.php @@ -0,0 +1,107 @@ +createStub(Spec::class); + $propertyNormalizer = $this->createMock(PropertyNormalizer::class); + $factory = $this->createConfiguredMock(NormalizerFactory::class, [ + 'getSpec' => $spec, + 'makeForProperty' => $propertyNormalizer, + ]); + + $normalizer = new PropertyRepositoryNormalizer($factory); + $properties = $this->createConfiguredMock(PropertyRepository::class, ['count' => 0]); + + $actual = $normalizer->normalize($properties); + + self::assertSame([], $actual); + } + + public function testNormalize(): void + { + $spec = $this->createStub(Spec::class); + $propertyNormalizer = $this->createMock(PropertyNormalizer::class); + $factory = $this->createConfiguredMock(NormalizerFactory::class, [ + 'getSpec' => $spec, + 'makeForProperty' => $propertyNormalizer, + ]); + $normalizer = new PropertyRepositoryNormalizer($factory); + $property = $this->createStub(Property::class); + $properties = $this->createConfiguredMock(PropertyRepository::class, [ + 'count' => 1, + 'getItems' => [$property], + ]); + + $propertyNormalizer->expects(self::once())->method('normalize') + ->with($property) + ->willReturn(['FakeProperty' => 'dummy']); + + $actual = $normalizer->normalize($properties); + + self::assertSame([['FakeProperty' => 'dummy']], $actual); + } + + public function testNormalizeSkipWHenThrown(): void + { + $spec = $this->createStub(Spec::class); + $propertyNormalizer = $this->createMock(PropertyNormalizer::class); + $factory = $this->createConfiguredMock(NormalizerFactory::class, [ + 'getSpec' => $spec, + 'makeForProperty' => $propertyNormalizer, + ]); + $normalizer = new PropertyRepositoryNormalizer($factory); + $property = $this->createStub(Property::class); + $properties = $this->createConfiguredMock(PropertyRepository::class, [ + 'count' => 1, + 'getItems' => [$property], + ]); + + $propertyNormalizer->expects(self::once())->method('normalize') + ->with($property) + ->willThrowException(new DomainException()); + + $actual = $normalizer->normalize($properties); + + self::assertSame([], $actual); + } +} diff --git a/tests/Core/Serialization/JSON/Normalizers/ToolNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/ToolNormalizerTest.php index 6fd0c086..4607d226 100644 --- a/tests/Core/Serialization/JSON/Normalizers/ToolNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/ToolNormalizerTest.php @@ -27,15 +27,18 @@ use CycloneDX\Core\Collections\ExternalReferenceRepository; use CycloneDX\Core\Collections\HashDictionary; use CycloneDX\Core\Models\Tool; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; use CycloneDX\Core\Serialization\JSON\Normalizers\ExternalReferenceRepositoryNormalizer; use CycloneDX\Core\Serialization\JSON\Normalizers\HashDictionaryNormalizer; use CycloneDX\Core\Serialization\JSON\Normalizers\ToolNormalizer; use CycloneDX\Core\Spec\Spec; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ToolNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] +#[CoversClass(ToolNormalizer::class)] +#[UsesClass(_BaseNormalizer::class)] class ToolNormalizerTest extends TestCase { public function testNormalizeEmpty(): void diff --git a/tests/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizerTest.php index c6718464..8dd99798 100644 --- a/tests/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizerTest.php @@ -25,16 +25,19 @@ use CycloneDX\Core\Collections\ToolRepository; use CycloneDX\Core\Models\Tool; +use CycloneDX\Core\Serialization\JSON\_BaseNormalizer; use CycloneDX\Core\Serialization\JSON\NormalizerFactory; use CycloneDX\Core\Serialization\JSON\Normalizers\ToolNormalizer; use CycloneDX\Core\Serialization\JSON\Normalizers\ToolRepositoryNormalizer; use CycloneDX\Core\Spec\Spec; use DomainException; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ToolRepositoryNormalizer::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JSON\_BaseNormalizer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\JSON\Normalizers\ToolNormalizer::class)] +#[CoversClass(ToolRepositoryNormalizer::class)] +#[CoversClass(_BaseNormalizer::class)] +#[UsesClass(ToolNormalizer::class)] class ToolRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void diff --git a/tests/Core/Serialization/JsonSerializerTest.php b/tests/Core/Serialization/JsonSerializerTest.php index 18ae2bb7..d746b579 100644 --- a/tests/Core/Serialization/JsonSerializerTest.php +++ b/tests/Core/Serialization/JsonSerializerTest.php @@ -24,17 +24,22 @@ namespace CycloneDX\Tests\Core\Serialization; use CycloneDX\Core\Models\Bom; +use CycloneDX\Core\Serialization\BaseSerializer; +use CycloneDX\Core\Serialization\BomRefDiscriminator; use CycloneDX\Core\Serialization\JSON; use CycloneDX\Core\Serialization\JsonSerializer; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\JsonSerializer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\BaseSerializer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\BomRefDiscriminator::class)] +#[CoversClass(JsonSerializer::class)] +#[UsesClass(BaseSerializer::class)] +#[UsesClass(BomRefDiscriminator::class)] class JsonSerializerTest extends TestCase { - #[\PHPUnit\Framework\Attributes\DataProvider('dpSerializeStructure')] + #[DataProvider('dpSerializeStructure')] public function testSerialize(int $jsonEncodeFlags, ?bool $prettyPrint, array $normalized, string $expected): void { $bom = $this->createStub(Bom::class); diff --git a/tests/Core/Serialization/XmlSerializerTest.php b/tests/Core/Serialization/XmlSerializerTest.php index d149aa79..3698107f 100644 --- a/tests/Core/Serialization/XmlSerializerTest.php +++ b/tests/Core/Serialization/XmlSerializerTest.php @@ -24,19 +24,24 @@ namespace CycloneDX\Tests\Core\Serialization; use CycloneDX\Core\Models\Bom; +use CycloneDX\Core\Serialization\BaseSerializer; +use CycloneDX\Core\Serialization\BomRefDiscriminator; use CycloneDX\Core\Serialization\DOM; use CycloneDX\Core\Serialization\XmlSerializer; use DOMDocument; use DOMElement; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Serialization\XmlSerializer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\BaseSerializer::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Serialization\BomRefDiscriminator::class)] +#[CoversClass(XmlSerializer::class)] +#[UsesClass(BaseSerializer::class)] +#[UsesClass(BomRefDiscriminator::class)] class XmlSerializerTest extends TestCase { - #[\PHPUnit\Framework\Attributes\DataProvider('dpSerializeStructure')] + #[DataProvider('dpSerializeStructure')] public function testSerialize(string $xmlVersion, string $xmlEncoding, ?bool $prettyPrint, DOMElement $normalized, string $expected): void { $bom = $this->createStub(Bom::class); diff --git a/tests/Core/SerializeToJsonTest.php b/tests/Core/SerializeToJsonTest.php index b65f15b7..7c487338 100644 --- a/tests/Core/SerializeToJsonTest.php +++ b/tests/Core/SerializeToJsonTest.php @@ -28,7 +28,11 @@ use CycloneDX\Core\Serialization\JsonSerializer; use CycloneDX\Core\Spec\SpecFactory; use CycloneDX\Core\Validation\Validators\JsonStrictValidator; +use CycloneDX\Tests\_data\BomModelProvider; use DomainException; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\DataProviderExternal; +use PHPUnit\Framework\Attributes\Large; use PHPUnit\Framework\TestCase; /** @@ -36,8 +40,8 @@ * This test might require online-connectivity. * Tests functionality. */ -#[\PHPUnit\Framework\Attributes\Large] -#[\PHPUnit\Framework\Attributes\CoversNothing] +#[Large] +#[CoversNothing] class SerializeToJsonTest extends TestCase { // region Spec 1.0 @@ -65,7 +69,7 @@ public function testSerialization11(): void // region Spec 1.2 - #[\PHPUnit\Framework\Attributes\DataProviderExternal(\CycloneDX\Tests\_data\BomModelProvider::class, 'allBomTestData')] + #[DataProviderExternal(BomModelProvider::class, 'allBomTestData')] public function testSchema12(Bom $bom): void { $spec = SpecFactory::make1dot2(); @@ -83,7 +87,7 @@ public function testSchema12(Bom $bom): void // region Spec 1.3 - #[\PHPUnit\Framework\Attributes\DataProviderExternal(\CycloneDX\Tests\_data\BomModelProvider::class, 'allBomTestData')] + #[DataProviderExternal(BomModelProvider::class, 'allBomTestData')] public function testSchema13(Bom $bom): void { $spec = SpecFactory::make1dot3(); @@ -101,7 +105,7 @@ public function testSchema13(Bom $bom): void // region Spec 1.4 - #[\PHPUnit\Framework\Attributes\DataProviderExternal(\CycloneDX\Tests\_data\BomModelProvider::class, 'allBomTestData')] + #[DataProviderExternal(BomModelProvider::class, 'allBomTestData')] public function testSchema14(Bom $bom): void { $spec = SpecFactory::make1dot4(); diff --git a/tests/Core/SerializeToXmlTest.php b/tests/Core/SerializeToXmlTest.php index 879b2c12..c4a38abe 100644 --- a/tests/Core/SerializeToXmlTest.php +++ b/tests/Core/SerializeToXmlTest.php @@ -28,6 +28,10 @@ use CycloneDX\Core\Serialization\XmlSerializer; use CycloneDX\Core\Spec\SpecFactory; use CycloneDX\Core\Validation\Validators\XmlValidator; +use CycloneDX\Tests\_data\BomModelProvider; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\DataProviderExternal; +use PHPUnit\Framework\Attributes\Large; use PHPUnit\Framework\TestCase; /** @@ -35,8 +39,8 @@ * This test might require online-connectivity. * Tests functionality. */ -#[\PHPUnit\Framework\Attributes\Large] -#[\PHPUnit\Framework\Attributes\CoversNothing] +#[Large] +#[CoversNothing] class SerializeToXmlTest extends TestCase { // region Spec 1.0 @@ -45,7 +49,7 @@ class SerializeToXmlTest extends TestCase // region Spec 1.1 - #[\PHPUnit\Framework\Attributes\DataProviderExternal(\CycloneDX\Tests\_data\BomModelProvider::class, 'allBomTestData')] + #[DataProviderExternal(BomModelProvider::class, 'allBomTestData')] public function testSchema11(Bom $bom): void { $spec = SpecFactory::make1dot1(); @@ -62,7 +66,7 @@ public function testSchema11(Bom $bom): void // region Spec 1.2 - #[\PHPUnit\Framework\Attributes\DataProviderExternal(\CycloneDX\Tests\_data\BomModelProvider::class, 'allBomTestData')] + #[DataProviderExternal(BomModelProvider::class, 'allBomTestData')] public function testSchema12(Bom $bom): void { $spec = SpecFactory::make1dot2(); @@ -79,7 +83,7 @@ public function testSchema12(Bom $bom): void // region Spec 1.3 - #[\PHPUnit\Framework\Attributes\DataProviderExternal(\CycloneDX\Tests\_data\BomModelProvider::class, 'allBomTestData')] + #[DataProviderExternal(BomModelProvider::class, 'allBomTestData')] public function testSchema13(Bom $bom): void { $spec = SpecFactory::make1dot3(); @@ -96,7 +100,7 @@ public function testSchema13(Bom $bom): void // region Spec 1.4 - #[\PHPUnit\Framework\Attributes\DataProviderExternal(\CycloneDX\Tests\_data\BomModelProvider::class, 'allBomTestData')] + #[DataProviderExternal(BomModelProvider::class, 'allBomTestData')] public function testSchema14(Bom $bom): void { $spec = SpecFactory::make1dot4(); diff --git a/tests/Core/Spdx/LicenseValidatorTest.php b/tests/Core/Spdx/LicenseValidatorTest.php index 821b3148..99235642 100644 --- a/tests/Core/Spdx/LicenseValidatorTest.php +++ b/tests/Core/Spdx/LicenseValidatorTest.php @@ -25,10 +25,11 @@ use CycloneDX\Core\Spdx\LicenseValidator; use Generator; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use RuntimeException; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Spdx\LicenseValidator::class)] +#[CoversClass(LicenseValidator::class)] class LicenseValidatorTest extends TestCase { /** diff --git a/tests/Core/Spec/Spec1dot1Test.php b/tests/Core/Spec/Spec1dot1Test.php index 521b108c..bcd1122f 100644 --- a/tests/Core/Spec/Spec1dot1Test.php +++ b/tests/Core/Spec/Spec1dot1Test.php @@ -23,13 +23,16 @@ namespace CycloneDX\Tests\Core\Spec; +use CycloneDX\Core\Spec\_Spec; use CycloneDX\Core\Spec\Format; use CycloneDX\Core\Spec\Spec; use CycloneDX\Core\Spec\SpecFactory; use CycloneDX\Core\Spec\Version; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Spec\_Spec::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Spec\SpecFactory::class)] +#[CoversClass(_Spec::class)] +#[UsesClass(SpecFactory::class)] class Spec1dot1Test extends SpecBaseTestCase { protected static function getSpec(): Spec @@ -92,6 +95,11 @@ protected static function shouldSupportComponentProperties(): bool return false; } + protected static function shouldSupportsComponentAuthor(): bool + { + return false; + } + protected static function shouldSupportBomProperties(): array { return []; diff --git a/tests/Core/Spec/Spec1dot2Test.php b/tests/Core/Spec/Spec1dot2Test.php index 0d3238a1..4edc6082 100644 --- a/tests/Core/Spec/Spec1dot2Test.php +++ b/tests/Core/Spec/Spec1dot2Test.php @@ -23,13 +23,16 @@ namespace CycloneDX\Tests\Core\Spec; +use CycloneDX\Core\Spec\_Spec; use CycloneDX\Core\Spec\Format; use CycloneDX\Core\Spec\Spec; use CycloneDX\Core\Spec\SpecFactory; use CycloneDX\Core\Spec\Version; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Spec\_Spec::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Spec\SpecFactory::class)] +#[CoversClass(_Spec::class)] +#[UsesClass(SpecFactory::class)] class Spec1dot2Test extends SpecBaseTestCase { protected static function getSpec(): Spec @@ -92,6 +95,11 @@ protected static function shouldSupportComponentProperties(): bool return false; } + protected static function shouldSupportsComponentAuthor(): bool + { + return true; + } + protected static function shouldSupportBomProperties(): array { return []; diff --git a/tests/Core/Spec/Spec1dot3Test.php b/tests/Core/Spec/Spec1dot3Test.php index cba6d9b5..834b055a 100644 --- a/tests/Core/Spec/Spec1dot3Test.php +++ b/tests/Core/Spec/Spec1dot3Test.php @@ -27,9 +27,11 @@ use CycloneDX\Core\Spec\Spec; use CycloneDX\Core\Spec\SpecFactory; use CycloneDX\Core\Spec\Version; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Spec\_Spec::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Spec\SpecFactory::class)] +#[CoversClass(\CycloneDX\Core\Spec\_Spec::class)] +#[UsesClass(\CycloneDX\Core\Spec\SpecFactory::class)] class Spec1dot3Test extends SpecBaseTestCase { protected static function getSpec(): Spec @@ -92,6 +94,11 @@ protected static function shouldSupportComponentProperties(): bool return true; } + protected static function shouldSupportsComponentAuthor(): bool + { + return true; + } + protected static function shouldSupportBomProperties(): array { return [Format::XML]; diff --git a/tests/Core/Spec/Spec1dot4Test.php b/tests/Core/Spec/Spec1dot4Test.php index 78fac1d6..c7db32b2 100644 --- a/tests/Core/Spec/Spec1dot4Test.php +++ b/tests/Core/Spec/Spec1dot4Test.php @@ -23,13 +23,16 @@ namespace CycloneDX\Tests\Core\Spec; +use CycloneDX\Core\Spec\_Spec; use CycloneDX\Core\Spec\Format; use CycloneDX\Core\Spec\Spec; use CycloneDX\Core\Spec\SpecFactory; use CycloneDX\Core\Spec\Version; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Spec\_Spec::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Spec\SpecFactory::class)] +#[CoversClass(_Spec::class)] +#[UsesClass(SpecFactory::class)] class Spec1dot4Test extends SpecBaseTestCase { protected static function getSpec(): Spec @@ -92,6 +95,11 @@ protected static function shouldSupportComponentProperties(): bool return true; } + protected static function shouldSupportsComponentAuthor(): bool + { + return true; + } + protected static function shouldSupportBomProperties(): array { return [Format::XML]; diff --git a/tests/Core/Spec/SpecBaseTestCase.php b/tests/Core/Spec/SpecBaseTestCase.php index ae6e3149..6635c315 100644 --- a/tests/Core/Spec/SpecBaseTestCase.php +++ b/tests/Core/Spec/SpecBaseTestCase.php @@ -31,6 +31,7 @@ use CycloneDX\Core\Spec\Version; use CycloneDX\Tests\_data\BomSpecData; use Generator; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; abstract class SpecBaseTestCase extends TestCase @@ -57,7 +58,7 @@ final public function testKnownFormats(): array return $formats; } - #[\PHPUnit\Framework\Attributes\DataProvider('dpIsSupportsFormat')] + #[DataProvider('dpIsSupportsFormat')] final public function testIsSupportedFormat(Format $format, bool $expected): void { $isSupported = static::getSpec()->isSupportedFormat($format); @@ -72,7 +73,7 @@ final public static function dpIsSupportsFormat(): Generator } } - #[\PHPUnit\Framework\Attributes\DataProvider('dpIsSupportedComponentType')] + #[DataProvider('dpIsSupportedComponentType')] final public function testIsSupportedComponentType(ComponentType $value, bool $expected): void { $isSupported = static::getSpec()->isSupportedComponentType($value); @@ -88,7 +89,7 @@ final public static function dpIsSupportedComponentType(): Generator } } - #[\PHPUnit\Framework\Attributes\DataProvider('dpIsSupportedHashAlgorithm')] + #[DataProvider('dpIsSupportedHashAlgorithm')] final public function testIsSupportedHashAlgorithm(HashAlgorithm $value, bool $expected): void { $isSupported = static::getSpec()->isSupportedHashAlgorithm($value); @@ -104,7 +105,7 @@ final public static function dpIsSupportedHashAlgorithm(): Generator } } - #[\PHPUnit\Framework\Attributes\DataProvider('dpIsSupportedHashContent')] + #[DataProvider('dpIsSupportedHashContent')] final public function testIsSupportedHashContent(string $value, bool $expected): void { $isSupported = static::getSpec()->isSupportedHashContent($value); @@ -117,7 +118,7 @@ final public static function dpIsSupportedHashContent(): Generator yield 'valid sha1' => ['a052cfe45093f1c2d26bd854d06aa370ceca3b38', true]; } - #[\PHPUnit\Framework\Attributes\DataProvider('dpIsSupportedExternalReferenceType')] + #[DataProvider('dpIsSupportedExternalReferenceType')] final public function testIsSupportedExternalReferenceType(ExternalReferenceType $value, bool $expected): void { $isSupported = static::getSpec()->isSupportedExternalReferenceType($value); @@ -205,7 +206,15 @@ final public function testSupportsComponentProperties(): void abstract protected static function shouldSupportComponentProperties(): bool; - #[\PHPUnit\Framework\Attributes\DataProvider('dpSupportsBomProperties')] + final public function testSupportsComponentAuthor(): void + { + $isSupported = static::getSpec()->supportsComponentAuthor(); + self::assertSame(static::shouldSupportsComponentAuthor(), $isSupported); + } + + abstract protected static function shouldSupportsComponentAuthor(): bool; + + #[DataProvider('dpSupportsBomProperties')] final public function testSupportsBomProperties(Format $format, bool $shouldSupportBomProperties): void { $isSupported = static::getSpec()->supportsBomProperties($format); diff --git a/tests/Core/Spec/SpecFactoryTest.php b/tests/Core/Spec/SpecFactoryTest.php index afeafce1..eef25463 100644 --- a/tests/Core/Spec/SpecFactoryTest.php +++ b/tests/Core/Spec/SpecFactoryTest.php @@ -23,12 +23,15 @@ namespace CycloneDX\Tests\Core\Spec; +use CycloneDX\Core\Spec\_Spec; use CycloneDX\Core\Spec\SpecFactory; use CycloneDX\Core\Spec\Version; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Spec\SpecFactory::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Spec\_Spec::class)] +#[CoversClass(SpecFactory::class)] +#[UsesClass(_Spec::class)] class SpecFactoryTest extends TestCase { public function test11(): void diff --git a/tests/Core/Validation/Errors/JsonValidationErrorTest.php b/tests/Core/Validation/Errors/JsonValidationErrorTest.php index ca645c32..3c95cca5 100644 --- a/tests/Core/Validation/Errors/JsonValidationErrorTest.php +++ b/tests/Core/Validation/Errors/JsonValidationErrorTest.php @@ -24,23 +24,29 @@ namespace CycloneDX\Tests\Core\Validation\Errors; use CycloneDX\Core\Validation\Errors\JsonValidationError; +use CycloneDX\Core\Validation\ValidationError; use Opis\JsonSchema; +use Opis\JsonSchema\Info\DataInfo; +use Opis\JsonSchema\Info\SchemaInfo; +use Opis\JsonSchema\Schemas\EmptySchema; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Validation\Errors\JsonValidationError::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Validation\ValidationError::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\Opis\JsonSchema\Errors\ValidationError::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\Opis\JsonSchema\Schemas\EmptySchema::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\Opis\JsonSchema\Info\SchemaInfo::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\Opis\JsonSchema\Info\DataInfo::class)] +#[CoversClass(JsonValidationError::class)] +#[CoversClass(ValidationError::class)] +#[UsesClass(JsonSchema\Errors\ValidationError::class)] +#[UsesClass(EmptySchema::class)] +#[UsesClass(SchemaInfo::class)] +#[UsesClass(DataInfo::class)] class JsonValidationErrorTest extends TestCase { public function testFromJsonSchemaInvalidValue(): void { $errorJsonSchemaInvalidValue = new JsonSchema\Errors\ValidationError( 'foo', - new JsonSchema\Schemas\EmptySchema(new JsonSchema\Info\SchemaInfo(false, null)), - new JsonSchema\Info\DataInfo(null, null, null), + new EmptySchema(new SchemaInfo(false, null)), + new DataInfo(null, null, null), 'some error message' ); diff --git a/tests/Core/Validation/Errors/XmlValidationErrorTest.php b/tests/Core/Validation/Errors/XmlValidationErrorTest.php index 243318b4..d08ed7c4 100644 --- a/tests/Core/Validation/Errors/XmlValidationErrorTest.php +++ b/tests/Core/Validation/Errors/XmlValidationErrorTest.php @@ -24,11 +24,13 @@ namespace CycloneDX\Tests\Core\Validation\Errors; use CycloneDX\Core\Validation\Errors\XmlValidationError; +use CycloneDX\Core\Validation\ValidationError; use LibXMLError; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Validation\Errors\XmlValidationError::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Validation\ValidationError::class)] +#[CoversClass(XmlValidationError::class)] +#[CoversClass(ValidationError::class)] class XmlValidationErrorTest extends TestCase { public function testFromLibXMLError(): void diff --git a/tests/Core/Validation/ValidationErrorTest.php b/tests/Core/Validation/ValidationErrorTest.php index 77c50974..f0999d31 100644 --- a/tests/Core/Validation/ValidationErrorTest.php +++ b/tests/Core/Validation/ValidationErrorTest.php @@ -25,9 +25,10 @@ use CycloneDX\Core\Validation\ValidationError; use Exception; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Validation\ValidationError::class)] +#[CoversClass(ValidationError::class)] class ValidationErrorTest extends TestCase { public function testFromThrowable(): void diff --git a/tests/Core/Validation/Validators/JsonStrictValidatorTest.php b/tests/Core/Validation/Validators/JsonStrictValidatorTest.php index 0108c2ae..d088d6bc 100644 --- a/tests/Core/Validation/Validators/JsonStrictValidatorTest.php +++ b/tests/Core/Validation/Validators/JsonStrictValidatorTest.php @@ -25,19 +25,24 @@ use CycloneDX\Core\Spec\Spec; use CycloneDX\Core\Spec\Version; +use CycloneDX\Core\Validation\BaseValidator; use CycloneDX\Core\Validation\Errors\JsonValidationError; use CycloneDX\Core\Validation\Exceptions\FailedLoadingSchemaException; +use CycloneDX\Core\Validation\ValidationError; use CycloneDX\Core\Validation\Validators\JsonStrictValidator; +use CycloneDX\Core\Validation\Validators\JsonValidator; use JsonException; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\Constraint\IsInstanceOf; use PHPUnit\Framework\TestCase; use stdClass; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Validation\Validators\JsonStrictValidator::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Validation\Validators\JsonValidator::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Validation\BaseValidator::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Validation\Errors\JsonValidationError::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Validation\ValidationError::class)] +#[CoversClass(JsonStrictValidator::class)] +#[CoversClass(JsonValidator::class)] +#[CoversClass(BaseValidator::class)] +#[UsesClass(JsonValidationError::class)] +#[UsesClass(ValidationError::class)] class JsonStrictValidatorTest extends TestCase { public function testConstructor(): JsonStrictValidator diff --git a/tests/Core/Validation/Validators/JsonValidatorTest.php b/tests/Core/Validation/Validators/JsonValidatorTest.php index 4669d362..d1d8350a 100644 --- a/tests/Core/Validation/Validators/JsonValidatorTest.php +++ b/tests/Core/Validation/Validators/JsonValidatorTest.php @@ -25,18 +25,22 @@ use CycloneDX\Core\Spec\Spec; use CycloneDX\Core\Spec\Version; +use CycloneDX\Core\Validation\BaseValidator; use CycloneDX\Core\Validation\Errors\JsonValidationError; use CycloneDX\Core\Validation\Exceptions\FailedLoadingSchemaException; +use CycloneDX\Core\Validation\ValidationError; use CycloneDX\Core\Validation\Validators\JsonValidator; use JsonException; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\Constraint\IsInstanceOf; use PHPUnit\Framework\TestCase; use stdClass; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Validation\Validators\JsonValidator::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Validation\BaseValidator::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Validation\Errors\JsonValidationError::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Validation\ValidationError::class)] +#[CoversClass(JsonValidator::class)] +#[CoversClass(BaseValidator::class)] +#[UsesClass(JsonValidationError::class)] +#[UsesClass(ValidationError::class)] class JsonValidatorTest extends TestCase { public function testConstructor(): JsonValidator diff --git a/tests/Core/Validation/Validators/XmlValidatorTest.php b/tests/Core/Validation/Validators/XmlValidatorTest.php index 61ffed3e..1a34733d 100644 --- a/tests/Core/Validation/Validators/XmlValidatorTest.php +++ b/tests/Core/Validation/Validators/XmlValidatorTest.php @@ -25,18 +25,22 @@ use CycloneDX\Core\Spec\Spec; use CycloneDX\Core\Spec\Version; +use CycloneDX\Core\Validation\BaseValidator; use CycloneDX\Core\Validation\Errors\XmlValidationError; use CycloneDX\Core\Validation\Exceptions\FailedLoadingSchemaException; +use CycloneDX\Core\Validation\ValidationError; use CycloneDX\Core\Validation\Validators\XmlValidator; use DOMDocument; use DOMException; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\Constraint\IsInstanceOf; use PHPUnit\Framework\TestCase; -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Validation\Validators\XmlValidator::class)] -#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Validation\BaseValidator::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Validation\Errors\XmlValidationError::class)] -#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Validation\ValidationError::class)] +#[CoversClass(XmlValidator::class)] +#[CoversClass(BaseValidator::class)] +#[UsesClass(XmlValidationError::class)] +#[UsesClass(ValidationError::class)] class XmlValidatorTest extends TestCase { public function testConstructor(): XmlValidator diff --git a/tests/_traits/DomNodeAssertionTrait.php b/tests/_traits/DomNodeAssertionTrait.php index adb0ed3b..8e73e0c7 100644 --- a/tests/_traits/DomNodeAssertionTrait.php +++ b/tests/_traits/DomNodeAssertionTrait.php @@ -33,7 +33,7 @@ trait DomNodeAssertionTrait /** * @throws Exception */ - final protected static function assertDomNodeEqualsDomNode(DOMNode $expected, DomNode $actual): void + final protected static function assertDomNodeEqualsDomNode(DOMNode $expected, DOMNode $actual): void { $container = new DOMDocument(); @@ -46,7 +46,7 @@ final protected static function assertDomNodeEqualsDomNode(DOMNode $expected, Do /** * @throws Exception */ - final protected static function assertDomNodeEqualsString(DomNode $expected, string $actual): void + final protected static function assertDomNodeEqualsString(DOMNode $expected, string $actual): void { $container = new DOMDocument();