diff --git a/src/Core/Factories/LicenseFactory.php b/src/Core/Factories/LicenseFactory.php index 9cb16234..ed776d0b 100644 --- a/src/Core/Factories/LicenseFactory.php +++ b/src/Core/Factories/LicenseFactory.php @@ -33,21 +33,11 @@ class LicenseFactory { public function __construct( - private readonly LicenseIdentifiers $licenseIdentifiers = new LicenseIdentifiers(), - private readonly SpdxLicenses $spdxLicenses = new SpdxLicenses() + public readonly LicenseIdentifiers $licenseIdentifiers = new LicenseIdentifiers(), + public readonly SpdxLicenses $spdxLicenses = new SpdxLicenses() ) { } - public function getLicenseIdentifiers(): LicenseIdentifiers - { - return $this->licenseIdentifiers; - } - - public function getSpdxLicenses(): SpdxLicenses - { - return $this->spdxLicenses; - } - public function makeFromString(string $license): SpdxLicense|LicenseExpression|NamedLicense { try { diff --git a/src/Core/Serialization/DOM/NormalizerFactory.php b/src/Core/Serialization/DOM/NormalizerFactory.php index 9279522b..925f02fd 100644 --- a/src/Core/Serialization/DOM/NormalizerFactory.php +++ b/src/Core/Serialization/DOM/NormalizerFactory.php @@ -38,33 +38,22 @@ class NormalizerFactory { public const FORMAT = Format::XML; - private readonly Spec $spec; - - private readonly DOMDocument $document; + public readonly Spec $spec; /** * @throws DomainException when the spec does not support XML format */ - public function __construct(Spec $spec) - { + public function __construct( + Spec $spec, + public readonly DOMDocument $document = new DOMDocument() + ) { $this->spec = $spec->isSupportedFormat(self::FORMAT) ? $spec : throw new DomainException('Unsupported format "'.self::FORMAT->name.'" for spec '.$spec->getVersion()->name); - $this->document = new DOMDocument(); } // intention: all factory methods return an instance of "_BaseNormalizer" - public function getSpec(): Spec - { - return $this->spec; - } - - public function getDocument(): DOMDocument - { - return $this->document; - } - public function makeForBom(): Normalizers\BomNormalizer { return new Normalizers\BomNormalizer($this); diff --git a/src/Core/Serialization/DOM/Normalizers/BomNormalizer.php b/src/Core/Serialization/DOM/Normalizers/BomNormalizer.php index d39f7924..f7744ba7 100644 --- a/src/Core/Serialization/DOM/Normalizers/BomNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/BomNormalizer.php @@ -41,11 +41,10 @@ class BomNormalizer extends _BaseNormalizer public function normalize(Bom $bom): DOMElement { - $factory = $this->getNormalizerFactory(); - $document = $factory->getDocument(); + $factory = $this->normalizerFactory; - $element = $document->createElementNS( - sprintf(self::XML_NAMESPACE_PATTERN, $factory->getSpec()->getVersion()->value), + $element = $factory->document->createElementNS( + sprintf(self::XML_NAMESPACE_PATTERN, $factory->spec->getVersion()->value), 'bom' // no namespace = defaultNS - so children w/o NS fall under this NS ); SimpleDOM::setAttributes( @@ -74,19 +73,19 @@ public function normalize(Bom $bom): DOMElement private function normalizeComponents(ComponentRepository $components): DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; return SimpleDOM::appendChildren( - $factory->getDocument()->createElement('components'), + $factory->document->createElement('components'), $factory->makeForComponentRepository()->normalize($components) ); } private function normalizeMetadata(Metadata $metadata): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsMetadata()) { + if (false === $factory->spec->supportsMetadata()) { return null; } @@ -99,11 +98,11 @@ private function normalizeMetadata(Metadata $metadata): ?DOMElement private function normalizeExternalReferences(Bom $bom): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; $extRefs = $bom->getExternalReferences(); - if (false === $factory->getSpec()->supportsMetadata()) { + if (false === $factory->spec->supportsMetadata()) { // prevent possible information loss: metadata cannot be rendered -> put it to bom $mcr = $bom->getMetadata()->getComponent()?->getExternalReferences(); if (null !== $mcr) { @@ -121,16 +120,16 @@ private function normalizeExternalReferences(Bom $bom): ?DOMElement return 0 === \count($refs) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('externalReferences'), + $factory->document->createElement('externalReferences'), $refs ); } private function normalizeDependencies(Bom $bom): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsDependencies()) { + if (false === $factory->spec->supportsDependencies()) { return null; } @@ -139,22 +138,22 @@ private function normalizeDependencies(Bom $bom): ?DOMElement return empty($deps) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('dependencies'), + $factory->document->createElement('dependencies'), $deps ); } private function normalizeProperties(PropertyRepository $properties): ?DOMElement { - if (false === $this->getNormalizerFactory()->getSpec()->supportsBomProperties(Format::XML)) { + if (false === $this->normalizerFactory->spec->supportsBomProperties(Format::XML)) { return null; } return 0 === \count($properties) ? null : SimpleDOM::appendChildren( - $this->getNormalizerFactory()->getDocument()->createElement('properties'), - $this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties) + $this->normalizerFactory->document->createElement('properties'), + $this->normalizerFactory->makeForPropertyRepository()->normalize($properties) ); } } diff --git a/src/Core/Serialization/DOM/Normalizers/ComponentEvidenceNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ComponentEvidenceNormalizer.php index b6ec1e9e..71e13098 100644 --- a/src/Core/Serialization/DOM/Normalizers/ComponentEvidenceNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ComponentEvidenceNormalizer.php @@ -35,8 +35,7 @@ class ComponentEvidenceNormalizer extends _BaseNormalizer { public function normalize(ComponentEvidence $evidence): DOMElement { - $factory = $this->getNormalizerFactory(); - $document = $factory->getDocument(); + $document = $this->normalizerFactory->document; $licenses = $evidence->getLicenses(); $copyright = $evidence->getCopyright(); @@ -48,7 +47,7 @@ public function normalize(ComponentEvidence $evidence): DOMElement ? null : SimpleDOM::appendChildren( $document->createElement('licenses'), - $this->getNormalizerFactory()->makeForLicenseRepository()->normalize($licenses) + $this->normalizerFactory->makeForLicenseRepository()->normalize($licenses) ), 0 === \count($copyright) ? null diff --git a/src/Core/Serialization/DOM/Normalizers/ComponentNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ComponentNormalizer.php index 3cf1f8c4..f80ad272 100644 --- a/src/Core/Serialization/DOM/Normalizers/ComponentNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ComponentNormalizer.php @@ -49,8 +49,7 @@ public function normalize(Component $component): DOMElement $group = $component->getGroup(); $version = $component->getVersion(); - $factory = $this->getNormalizerFactory(); - $spec = $factory->getSpec(); + $spec = $this->normalizerFactory->spec; $type = $component->getType(); if (false === $spec->isSupportedComponentType($type)) { @@ -68,7 +67,7 @@ public function normalize(Component $component): DOMElement ? $component->getEvidence() : null; - $document = $factory->getDocument(); + $document = $this->normalizerFactory->document; return SimpleDOM::appendChildren( SimpleDOM::setAttributes( @@ -106,31 +105,31 @@ public function normalize(Component $component): DOMElement // components null === $evidence ? null - : $this->getNormalizerFactory()->makeForComponentEvidence()->normalize($evidence), + : $this->normalizerFactory->makeForComponentEvidence()->normalize($evidence), ] ); } private function normalizeLicenses(LicenseRepository $licenses): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; return 0 === \count($licenses) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('licenses'), + $factory->document->createElement('licenses'), $factory->makeForLicenseRepository()->normalize($licenses) ); } private function normalizeHashes(HashDictionary $hashes): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; return 0 === \count($hashes) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('hashes'), + $factory->document->createElement('hashes'), $factory->makeForHashDictionary()->normalize($hashes) ); } @@ -140,7 +139,7 @@ private function normalizePurl(?PackageUrl $purl): ?DOMElement return null === $purl ? null : SimpleDOM::makeSafeTextElement( - $this->getNormalizerFactory()->getDocument(), + $this->normalizerFactory->document, 'purl', XML::encodeAnyUriBE((string) $purl) ); @@ -148,27 +147,27 @@ private function normalizePurl(?PackageUrl $purl): ?DOMElement private function normalizeExternalReferences(ExternalReferenceRepository $extRefs): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; return 0 === \count($extRefs) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('externalReferences'), + $factory->document->createElement('externalReferences'), $factory->makeForExternalReferenceRepository()->normalize($extRefs) ); } private function normalizeProperties(PropertyRepository $properties): ?DOMElement { - if (false === $this->getNormalizerFactory()->getSpec()->supportsComponentProperties()) { + if (false === $this->normalizerFactory->spec->supportsComponentProperties()) { return null; } return 0 === \count($properties) ? null : SimpleDOM::appendChildren( - $this->getNormalizerFactory()->getDocument()->createElement('properties'), - $this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties) + $this->normalizerFactory->document->createElement('properties'), + $this->normalizerFactory->makeForPropertyRepository()->normalize($properties) ); } } diff --git a/src/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizer.php index 6f2b99ec..91c777a0 100644 --- a/src/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizer.php @@ -39,7 +39,7 @@ class ComponentRepositoryNormalizer extends _BaseNormalizer */ public function normalize(ComponentRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForComponent(); + $normalizer = $this->normalizerFactory->makeForComponent(); $components = []; foreach ($repo->getItems() as $component) { diff --git a/src/Core/Serialization/DOM/Normalizers/DependenciesNormalizer.php b/src/Core/Serialization/DOM/Normalizers/DependenciesNormalizer.php index f9335b8c..03ad8a32 100644 --- a/src/Core/Serialization/DOM/Normalizers/DependenciesNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/DependenciesNormalizer.php @@ -79,7 +79,7 @@ private function normalizeDependency(BomRef $componentRef, BomRef ...$dependency return null; } - $doc = $this->getNormalizerFactory()->getDocument(); + $doc = $this->normalizerFactory->document; $dependency = SimpleDOM::setAttributes( $doc->createElement('dependency'), diff --git a/src/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizer.php index 8bf0cb2f..373f09a7 100644 --- a/src/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizer.php @@ -48,8 +48,7 @@ public function normalize(ExternalReference $externalReference): DOMElement $anyURI = XML::encodeAnyUriBE($refURI) ?? throw new UnexpectedValueException("unable to make 'anyURI' from: $refURI"); - $factory = $this->getNormalizerFactory(); - $spec = $factory->getSpec(); + $spec = $this->normalizerFactory->spec; $type = $externalReference->getType(); if (false === $spec->isSupportedExternalReferenceType($type)) { @@ -60,7 +59,7 @@ public function normalize(ExternalReference $externalReference): DOMElement } } - $doc = $factory->getDocument(); + $doc = $this->normalizerFactory->document; return SimpleDOM::appendChildren( SimpleDOM::setAttributes( @@ -83,13 +82,13 @@ private function normalizeHashes(HashDictionary $hashes): ?DOMElement return null; } - $factory = $this->getNormalizerFactory(); - if (false === $factory->getSpec()->supportsExternalReferenceHashes()) { + $factory = $this->normalizerFactory; + if (false === $factory->spec->supportsExternalReferenceHashes()) { return null; } return SimpleDOM::appendChildren( - $factory->getDocument()->createElement('hashes'), + $factory->document->createElement('hashes'), $factory->makeForHashDictionary()->normalize($hashes) ); } diff --git a/src/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizer.php index ee1f0ed7..854779c5 100644 --- a/src/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizer.php @@ -41,7 +41,7 @@ class ExternalReferenceRepositoryNormalizer extends _BaseNormalizer */ public function normalize(ExternalReferenceRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForExternalReference(); + $normalizer = $this->normalizerFactory->makeForExternalReference(); $externalReferences = []; foreach ($repo->getItems() as $externalReference) { diff --git a/src/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizer.php b/src/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizer.php index 073ee301..27a90165 100644 --- a/src/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizer.php @@ -41,7 +41,7 @@ public function normalize(HashDictionary $repo): array { $hashes = []; - $hashNormalizer = $this->getNormalizerFactory()->makeForHash(); + $hashNormalizer = $this->normalizerFactory->makeForHash(); foreach ($repo->getItems() as [$algorithm , $content]) { try { $hashes[] = $hashNormalizer->normalize($algorithm, $content); diff --git a/src/Core/Serialization/DOM/Normalizers/HashNormalizer.php b/src/Core/Serialization/DOM/Normalizers/HashNormalizer.php index 415febd5..b7f24eea 100644 --- a/src/Core/Serialization/DOM/Normalizers/HashNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/HashNormalizer.php @@ -39,7 +39,7 @@ class HashNormalizer extends _BaseNormalizer */ public function normalize(HashAlgorithm $algorithm, string $content): DOMElement { - $spec = $this->getNormalizerFactory()->getSpec(); + $spec = $this->normalizerFactory->spec; if (false === $spec->isSupportedHashAlgorithm($algorithm)) { throw new DomainException("Invalid hash algorithm: $algorithm->name", 1); } @@ -48,7 +48,7 @@ public function normalize(HashAlgorithm $algorithm, string $content): DOMElement } $element = SimpleDOM::makeSafeTextElement( - $this->getNormalizerFactory()->getDocument(), + $this->normalizerFactory->document, 'hash', $content ); diff --git a/src/Core/Serialization/DOM/Normalizers/LicenseNormalizer.php b/src/Core/Serialization/DOM/Normalizers/LicenseNormalizer.php index ea0a4319..a1fcad25 100644 --- a/src/Core/Serialization/DOM/Normalizers/LicenseNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/LicenseNormalizer.php @@ -46,10 +46,10 @@ public function normalize(LicenseExpression|SpdxLicense|NamedLicense $license): private function normalizeExpression(LicenseExpression $license): DOMElement { // TODO: IMPLEMENTED IF NEEDED: may throw, if not supported by the spec - // $this->getNormalizerFactory()->getSpec()->supportsLicenseExpression() + // $this->normalizerFactory->spec->supportsLicenseExpression() $element = SimpleDOM::makeSafeTextElement( - $this->getNormalizerFactory()->getDocument(), + $this->normalizerFactory->document, 'expression', $license->getExpression() ); @@ -63,17 +63,17 @@ private function normalizeExpression(LicenseExpression $license): DOMElement */ private function normalizeDisjunctive(SpdxLicense|NamedLicense $license): DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; [$id, $name] = $license instanceof SpdxLicense ? [$license->getId(), null] : [null, $license->getName()]; - if (null !== $id && !$factory->getSpec()->isSupportedLicenseIdentifier($id)) { + if (null !== $id && !$factory->spec->isSupportedLicenseIdentifier($id)) { [$id, $name] = [null, $id]; } - $document = $factory->getDocument(); + $document = $factory->document; return SimpleDOM::appendChildren( $document->createElement('license'), diff --git a/src/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizer.php b/src/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizer.php index d3f4952a..bc9e07c4 100644 --- a/src/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizer.php @@ -40,7 +40,7 @@ class LicenseRepositoryNormalizer extends _BaseNormalizer public function normalize(LicenseRepository $repo): array { return array_map( - $this->getNormalizerFactory()->makeForLicense()->normalize(...), + $this->normalizerFactory->makeForLicense()->normalize(...), $repo->getItems() ); } diff --git a/src/Core/Serialization/DOM/Normalizers/MetadataNormalizer.php b/src/Core/Serialization/DOM/Normalizers/MetadataNormalizer.php index 222482fe..2e27d695 100644 --- a/src/Core/Serialization/DOM/Normalizers/MetadataNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/MetadataNormalizer.php @@ -42,7 +42,7 @@ class MetadataNormalizer extends _BaseNormalizer public function normalize(Metadata $metadata): DOMElement { return SimpleDOM::appendChildren( - $this->getNormalizerFactory()->getDocument()->createElement('metadata'), + $this->normalizerFactory->document->createElement('metadata'), [ $this->normalizeTimestamp($metadata->getTimestamp()), $this->normalizeTools($metadata->getTools()), @@ -66,7 +66,7 @@ private function normalizeTimestamp(?DateTimeInterface $timestamp): ?DOMElement ->format('Y-m-d\\TH:i:sp'); return SimpleDOM::makeSafeTextElement( - $this->getNormalizerFactory()->getDocument(), + $this->normalizerFactory->document, 'timestamp', $dtZulu ); @@ -77,8 +77,8 @@ private function normalizeTools(ToolRepository $tools): ?DOMElement return 0 === \count($tools) ? null : SimpleDOM::appendChildren( - $this->getNormalizerFactory()->getDocument()->createElement('tools'), - $this->getNormalizerFactory()->makeForToolRepository()->normalize($tools) + $this->normalizerFactory->document->createElement('tools'), + $this->normalizerFactory->makeForToolRepository()->normalize($tools) ); } @@ -89,7 +89,7 @@ private function normalizeComponent(?Component $component): ?DOMElement } try { - return $this->getNormalizerFactory()->makeForComponent()->normalize($component); + return $this->normalizerFactory->makeForComponent()->normalize($component); } catch (\DomainException) { return null; } @@ -97,15 +97,15 @@ private function normalizeComponent(?Component $component): ?DOMElement private function normalizeProperties(PropertyRepository $properties): ?DOMElement { - if (false === $this->getNormalizerFactory()->getSpec()->supportsMetadataProperties()) { + if (false === $this->normalizerFactory->spec->supportsMetadataProperties()) { return null; } return 0 === \count($properties) ? null : SimpleDOM::appendChildren( - $this->getNormalizerFactory()->getDocument()->createElement('properties'), - $this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties) + $this->normalizerFactory->document->createElement('properties'), + $this->normalizerFactory->makeForPropertyRepository()->normalize($properties) ); } } diff --git a/src/Core/Serialization/DOM/Normalizers/PropertyNormalizer.php b/src/Core/Serialization/DOM/Normalizers/PropertyNormalizer.php index ec8b173b..7ab99bd6 100644 --- a/src/Core/Serialization/DOM/Normalizers/PropertyNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/PropertyNormalizer.php @@ -39,15 +39,16 @@ class PropertyNormalizer extends _BaseNormalizer */ public function normalize(Property $property): DOMElement { - $doc = $this->getNormalizerFactory()->getDocument(); - $name = $property->getName(); if ('' === $name) { // this implementation detail is optional throw new DomainException('empty name'); } - $element = SimpleDOM::makeSafeTextElement($doc, 'property', $property->getValue(), false); + $element = SimpleDOM::makeSafeTextElement( + $this->normalizerFactory->document, + 'property', + $property->getValue(), false); \assert(null !== $element); return SimpleDOM::setAttributes( diff --git a/src/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizer.php b/src/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizer.php index 3f7e6d09..72baadf6 100644 --- a/src/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizer.php @@ -39,7 +39,7 @@ class PropertyRepositoryNormalizer extends _BaseNormalizer */ public function normalize(PropertyRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForProperty(); + $normalizer = $this->normalizerFactory->makeForProperty(); $properties = []; foreach ($repo->getItems() as $property) { diff --git a/src/Core/Serialization/DOM/Normalizers/ToolNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ToolNormalizer.php index 3440c79b..91f4491f 100644 --- a/src/Core/Serialization/DOM/Normalizers/ToolNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ToolNormalizer.php @@ -37,7 +37,7 @@ class ToolNormalizer extends _BaseNormalizer { public function normalize(Tool $tool): DOMElement { - $doc = $this->getNormalizerFactory()->getDocument(); + $doc = $this->normalizerFactory->document; return SimpleDOM::appendChildren( $doc->createElement('tool'), @@ -53,28 +53,28 @@ public function normalize(Tool $tool): DOMElement private function normalizeHashes(HashDictionary $hashes): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; return 0 === \count($hashes) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('hashes'), + $factory->document->createElement('hashes'), $factory->makeForHashDictionary()->normalize($hashes) ); } private function normalizeExternalReferences(ExternalReferenceRepository $extRefs): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsToolExternalReferences()) { + if (false === $factory->spec->supportsToolExternalReferences()) { return null; } return 0 === \count($extRefs) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('externalReferences'), + $factory->document->createElement('externalReferences'), $factory->makeForExternalReferenceRepository()->normalize($extRefs) ); } diff --git a/src/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizer.php index 778c7544..7e86c5e5 100644 --- a/src/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizer.php @@ -39,7 +39,7 @@ class ToolRepositoryNormalizer extends _BaseNormalizer */ public function normalize(ToolRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForTool(); + $normalizer = $this->normalizerFactory->makeForTool(); $tools = []; foreach ($repo->getItems() as $tool) { diff --git a/src/Core/Serialization/DOM/_BaseNormalizer.php b/src/Core/Serialization/DOM/_BaseNormalizer.php index b59682a1..f8073dfa 100644 --- a/src/Core/Serialization/DOM/_BaseNormalizer.php +++ b/src/Core/Serialization/DOM/_BaseNormalizer.php @@ -33,17 +33,12 @@ */ abstract class _BaseNormalizer { - private readonly NormalizerFactory $normalizerFactory; + public readonly NormalizerFactory $normalizerFactory; public function __construct(NormalizerFactory $normalizerFactory) { $this->normalizerFactory = $normalizerFactory; } - public function getNormalizerFactory(): NormalizerFactory - { - return $this->normalizerFactory; - } - // intention to implement a "public function normalize" that accepts an object, and returns a normalized object } diff --git a/src/Core/Serialization/JSON/NormalizerFactory.php b/src/Core/Serialization/JSON/NormalizerFactory.php index c678f1f2..713edd5b 100644 --- a/src/Core/Serialization/JSON/NormalizerFactory.php +++ b/src/Core/Serialization/JSON/NormalizerFactory.php @@ -37,7 +37,7 @@ class NormalizerFactory { public const FORMAT = Format::JSON; - private readonly Spec $spec; + public readonly Spec $spec; /** * @throws DomainException when the spec does not support JSON format @@ -49,11 +49,6 @@ public function __construct(Spec $spec) : throw new DomainException('Unsupported format "'.self::FORMAT->name.'" for spec '.$spec->getVersion()->name); } - public function getSpec(): Spec - { - return $this->spec; - } - // intention: all factory methods return an instance of "_BaseNormalizer" public function makeForBom(): Normalizers\BomNormalizer diff --git a/src/Core/Serialization/JSON/Normalizers/BomNormalizer.php b/src/Core/Serialization/JSON/Normalizers/BomNormalizer.php index 5abe7ef8..54c6df13 100644 --- a/src/Core/Serialization/JSON/Normalizers/BomNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/BomNormalizer.php @@ -54,8 +54,8 @@ private function getSchema(Version $version): ?string */ public function normalize(Bom $bom): array { - $factory = $this->getNormalizerFactory(); - $specVersion = $factory->getSpec()->getVersion(); + $factory = $this->normalizerFactory; + $specVersion = $factory->spec->getVersion(); return array_filter( [ @@ -80,9 +80,9 @@ public function normalize(Bom $bom): array private function normalizeMetadata(Metadata $metadata): ?array { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsMetadata()) { + if (false === $factory->spec->supportsMetadata()) { return null; } @@ -95,11 +95,11 @@ private function normalizeMetadata(Metadata $metadata): ?array private function normalizeExternalReferences(Bom $bom): ?array { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; $extRefs = $bom->getExternalReferences(); - if (false === $factory->getSpec()->supportsMetadata()) { + if (false === $factory->spec->supportsMetadata()) { // prevent possible information loss: metadata cannot be rendered -> put it to bom $mcr = $bom->getMetadata()->getComponent()?->getExternalReferences(); if (null !== $mcr) { @@ -121,9 +121,9 @@ private function normalizeExternalReferences(Bom $bom): ?array private function normalizeDependencies(Bom $bom): ?array { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsDependencies()) { + if (false === $factory->spec->supportsDependencies()) { return null; } @@ -136,12 +136,12 @@ private function normalizeDependencies(Bom $bom): ?array private function normalizeProperties(PropertyRepository $properties): ?array { - if (false === $this->getNormalizerFactory()->getSpec()->supportsBomProperties(Format::JSON)) { + if (false === $this->normalizerFactory->spec->supportsBomProperties(Format::JSON)) { return null; } return 0 === \count($properties) ? null - : $this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties); + : $this->normalizerFactory->makeForPropertyRepository()->normalize($properties); } } diff --git a/src/Core/Serialization/JSON/Normalizers/ComponentEvidenceNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ComponentEvidenceNormalizer.php index e1604b7d..49ac9986 100644 --- a/src/Core/Serialization/JSON/Normalizers/ComponentEvidenceNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ComponentEvidenceNormalizer.php @@ -40,7 +40,7 @@ public function normalize(ComponentEvidence $evidence): array return array_filter([ 'licenses' => 0 === \count($license) ? null - : $this->getNormalizerFactory()->makeForLicenseRepository()->normalize($license), + : $this->normalizerFactory->makeForLicenseRepository()->normalize($license), 'copyright' => 0 === \count($copyright) ? null : array_map( diff --git a/src/Core/Serialization/JSON/Normalizers/ComponentNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ComponentNormalizer.php index 04a0f63f..ba04db35 100644 --- a/src/Core/Serialization/JSON/Normalizers/ComponentNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ComponentNormalizer.php @@ -43,7 +43,7 @@ class ComponentNormalizer extends _BaseNormalizer */ public function normalize(Component $component): array { - $spec = $this->getNormalizerFactory()->getSpec(); + $spec = $this->normalizerFactory->spec; $name = $component->getName(); $group = $component->getGroup(); @@ -80,7 +80,7 @@ public function normalize(Component $component): array 'copyright' => $component->getCopyright(), 'evidence' => null === $evidence ? null - : $this->getNormalizerFactory()->makeForComponentEvidence()->normalize($evidence), + : $this->normalizerFactory->makeForComponentEvidence()->normalize($evidence), 'hashes' => $this->normalizeHashes($component->getHashes()), 'purl' => $this->normalizePurl($component->getPackageUrl()), 'externalReferences' => $this->normalizeExternalReferences($component->getExternalReferences()), @@ -94,14 +94,14 @@ private function normalizeLicenses(LicenseRepository $licenses): ?array { return 0 === \count($licenses) ? null - : $this->getNormalizerFactory()->makeForLicenseRepository()->normalize($licenses); + : $this->normalizerFactory->makeForLicenseRepository()->normalize($licenses); } private function normalizeHashes(HashDictionary $hashes): ?array { return 0 === \count($hashes) ? null - : $this->getNormalizerFactory()->makeForHashDictionary()->normalize($hashes); + : $this->normalizerFactory->makeForHashDictionary()->normalize($hashes); } private function normalizePurl(?PackageUrl $purl): ?string @@ -115,17 +115,17 @@ private function normalizeExternalReferences(ExternalReferenceRepository $extRef { return 0 === \count($extRefs) ? null - : $this->getNormalizerFactory()->makeForExternalReferenceRepository()->normalize($extRefs); + : $this->normalizerFactory->makeForExternalReferenceRepository()->normalize($extRefs); } private function normalizeProperties(PropertyRepository $properties): ?array { - if (false === $this->getNormalizerFactory()->getSpec()->supportsComponentProperties()) { + if (false === $this->normalizerFactory->spec->supportsComponentProperties()) { return null; } return 0 === \count($properties) ? null - : $this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties); + : $this->normalizerFactory->makeForPropertyRepository()->normalize($properties); } } diff --git a/src/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizer.php index 8c585a45..89ea95de 100644 --- a/src/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizer.php @@ -38,7 +38,7 @@ public function normalize(ComponentRepository $repo): array { $components = []; - $normalizer = $this->getNormalizerFactory()->makeForComponent(); + $normalizer = $this->normalizerFactory->makeForComponent(); foreach ($repo->getItems() as $component) { try { $components[] = $normalizer->normalize($component); diff --git a/src/Core/Serialization/JSON/Normalizers/ExternalReferenceNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ExternalReferenceNormalizer.php index 083637f8..ce20ed9b 100644 --- a/src/Core/Serialization/JSON/Normalizers/ExternalReferenceNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ExternalReferenceNormalizer.php @@ -50,7 +50,7 @@ public function normalize(ExternalReference $externalReference): array throw new UnexpectedValueException("invalid to format 'IriReference': $url"); } - $spec = $this->getNormalizerFactory()->getSpec(); + $spec = $this->normalizerFactory->spec; $type = $externalReference->getType(); if (false === $spec->isSupportedExternalReferenceType($type)) { // prevent information-loss -> try transfer to OTHER @@ -73,9 +73,9 @@ public function normalize(ExternalReference $externalReference): array private function normalizeHashes(HashDictionary $hashes): ?array { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsExternalReferenceHashes()) { + if (false === $factory->spec->supportsExternalReferenceHashes()) { return null; } diff --git a/src/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizer.php index 07ddafca..cc934b2b 100644 --- a/src/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizer.php @@ -40,7 +40,7 @@ class ExternalReferenceRepositoryNormalizer extends _BaseNormalizer */ public function normalize(ExternalReferenceRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForExternalReference(); + $normalizer = $this->normalizerFactory->makeForExternalReference(); $externalReferences = []; foreach ($repo->getItems() as $externalReference) { diff --git a/src/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizer.php b/src/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizer.php index 61d5d5ac..1dbeeb05 100644 --- a/src/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizer.php @@ -35,7 +35,7 @@ public function normalize(HashDictionary $repo): array { $hashes = []; - $normalizer = $this->getNormalizerFactory()->makeForHash(); + $normalizer = $this->normalizerFactory->makeForHash(); foreach ($repo->getItems() as [$algorithm , $content]) { try { $hashes[] = $normalizer->normalize($algorithm, $content); diff --git a/src/Core/Serialization/JSON/Normalizers/HashNormalizer.php b/src/Core/Serialization/JSON/Normalizers/HashNormalizer.php index 53b699cf..7efef0e9 100644 --- a/src/Core/Serialization/JSON/Normalizers/HashNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/HashNormalizer.php @@ -37,7 +37,7 @@ class HashNormalizer extends _BaseNormalizer */ public function normalize(HashAlgorithm $algorithm, string $content): array { - $spec = $this->getNormalizerFactory()->getSpec(); + $spec = $this->normalizerFactory->spec; if (false === $spec->isSupportedHashAlgorithm($algorithm)) { throw new DomainException("Invalid hash algorithm: $algorithm->name", 1); } diff --git a/src/Core/Serialization/JSON/Normalizers/LicenseNormalizer.php b/src/Core/Serialization/JSON/Normalizers/LicenseNormalizer.php index b2f6b942..ac8befc5 100644 --- a/src/Core/Serialization/JSON/Normalizers/LicenseNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/LicenseNormalizer.php @@ -45,7 +45,7 @@ public function normalize(LicenseExpression|SpdxLicense|NamedLicense $license): private function normalizeExpression(LicenseExpression $license): array { // TODO: IMPLEMENTED IF NEEDED: may throw, if not supported by the spec - // $this->getNormalizerFactory()->getSpec()->supportsLicenseExpression() + // $this->normalizerFactory->spec->supportsLicenseExpression() return ['expression' => $license->getExpression()]; } @@ -59,7 +59,7 @@ private function normalizeDisjunctive(SpdxLicense|NamedLicense $license): array [$id, $name] = $license instanceof SpdxLicense ? [$license->getId(), null] : [null, $license->getName()]; - if (null !== $id && !$this->getNormalizerFactory()->getSpec()->isSupportedLicenseIdentifier($id)) { + if (null !== $id && !$this->normalizerFactory->spec->isSupportedLicenseIdentifier($id)) { [$id, $name] = [null, $id]; } diff --git a/src/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizer.php b/src/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizer.php index b40bc8be..516c918f 100644 --- a/src/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizer.php @@ -34,7 +34,7 @@ class LicenseRepositoryNormalizer extends _BaseNormalizer public function normalize(LicenseRepository $repo): array { return array_map( - $this->getNormalizerFactory()->makeForLicense()->normalize(...), + $this->normalizerFactory->makeForLicense()->normalize(...), $repo->getItems() ); } diff --git a/src/Core/Serialization/JSON/Normalizers/MetadataNormalizer.php b/src/Core/Serialization/JSON/Normalizers/MetadataNormalizer.php index aa0e990d..f0cea23e 100644 --- a/src/Core/Serialization/JSON/Normalizers/MetadataNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/MetadataNormalizer.php @@ -69,7 +69,7 @@ private function normalizeTools(ToolRepository $tools): ?array { return 0 === \count($tools) ? null - : $this->getNormalizerFactory()->makeForToolRepository()->normalize($tools); + : $this->normalizerFactory->makeForToolRepository()->normalize($tools); } private function normalizeComponent(?Component $component): ?array @@ -79,7 +79,7 @@ private function normalizeComponent(?Component $component): ?array } try { - return $this->getNormalizerFactory()->makeForComponent()->normalize($component); + return $this->normalizerFactory->makeForComponent()->normalize($component); } catch (\DomainException) { return null; } @@ -87,12 +87,12 @@ private function normalizeComponent(?Component $component): ?array private function normalizeProperties(PropertyRepository $properties): ?array { - if (false === $this->getNormalizerFactory()->getSpec()->supportsMetadataProperties()) { + if (false === $this->normalizerFactory->spec->supportsMetadataProperties()) { return null; } return 0 === \count($properties) ? null - : $this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties); + : $this->normalizerFactory->makeForPropertyRepository()->normalize($properties); } } diff --git a/src/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizer.php b/src/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizer.php index 20575726..da0f21ea 100644 --- a/src/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizer.php @@ -33,7 +33,7 @@ class PropertyRepositoryNormalizer extends _BaseNormalizer { public function normalize(PropertyRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForProperty(); + $normalizer = $this->normalizerFactory->makeForProperty(); $properties = []; foreach ($repo->getItems() as $property) { diff --git a/src/Core/Serialization/JSON/Normalizers/ToolNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ToolNormalizer.php index 1ed357ea..818922d5 100644 --- a/src/Core/Serialization/JSON/Normalizers/ToolNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ToolNormalizer.php @@ -52,14 +52,14 @@ private function normalizeHashes(HashDictionary $hashes): ?array { return 0 === \count($hashes) ? null - : $this->getNormalizerFactory()->makeForHashDictionary()->normalize($hashes); + : $this->normalizerFactory->makeForHashDictionary()->normalize($hashes); } private function normalizeExternalReferences(ExternalReferenceRepository $extRefs): ?array { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsToolExternalReferences()) { + if (false === $factory->spec->supportsToolExternalReferences()) { return null; } diff --git a/src/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizer.php index 9f413faf..8e306c56 100644 --- a/src/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizer.php @@ -38,7 +38,7 @@ class ToolRepositoryNormalizer extends _BaseNormalizer */ public function normalize(ToolRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForTool(); + $normalizer = $this->normalizerFactory->makeForTool(); $tools = []; foreach ($repo->getItems() as $tool) { diff --git a/src/Core/Serialization/JSON/_BaseNormalizer.php b/src/Core/Serialization/JSON/_BaseNormalizer.php index b5bea743..f04f82bc 100644 --- a/src/Core/Serialization/JSON/_BaseNormalizer.php +++ b/src/Core/Serialization/JSON/_BaseNormalizer.php @@ -33,17 +33,12 @@ */ abstract class _BaseNormalizer { - private readonly NormalizerFactory $normalizerFactory; + public readonly NormalizerFactory $normalizerFactory; public function __construct(NormalizerFactory $normalizerFactory) { $this->normalizerFactory = $normalizerFactory; } - public function getNormalizerFactory(): NormalizerFactory - { - return $this->normalizerFactory; - } - // intention to implement a "public function normalize" that accepts an object, and returns a normalized object } diff --git a/src/Core/Validation/BaseValidator.php b/src/Core/Validation/BaseValidator.php index 4df2f570..bdadd7b7 100644 --- a/src/Core/Validation/BaseValidator.php +++ b/src/Core/Validation/BaseValidator.php @@ -26,22 +26,19 @@ use CycloneDX\Core\Spec\Spec; /** + * @internal as this class may be affected by breaking changes without notice + * * @author jkowalleck */ abstract class BaseValidator implements Validator { - private readonly Spec $spec; + public readonly Spec $spec; public function __construct(Spec $spec) { $this->spec = $spec; } - public function getSpec(): Spec - { - return $this->spec; - } - /** * @throws Exceptions\FailedLoadingSchemaException when schema file unknown or not readable */ diff --git a/tests/Core/Collections/ComponentRepositoryTest.php b/tests/Core/Collections/ComponentRepositoryTest.php index 03d1a446..d4406427 100644 --- a/tests/Core/Collections/ComponentRepositoryTest.php +++ b/tests/Core/Collections/ComponentRepositoryTest.php @@ -43,8 +43,8 @@ public function testEmptyConstructor(): void public function testConstructor(): void { - $component1 = $this->createStub(Component::class); - $component2 = $this->createStub(Component::class); + $component1 = $this->createMock(Component::class); + $component2 = $this->createMock(Component::class); $repo = new ComponentRepository($component1, $component2, $component1, $component2); @@ -56,9 +56,9 @@ public function testConstructor(): void public function testAddAndGetItems(): void { - $component1 = $this->createStub(Component::class); - $component2 = $this->createStub(Component::class); - $component3 = $this->createStub(Component::class); + $component1 = $this->createMock(Component::class); + $component2 = $this->createMock(Component::class); + $component3 = $this->createMock(Component::class); $repo = new ComponentRepository($component1, $component3); $actual = $repo->addItems($component2, $component3, $component2); diff --git a/tests/Core/Collections/ExternalReferenceRepositoryTest.php b/tests/Core/Collections/ExternalReferenceRepositoryTest.php index 4a85e2a2..fb4e2dbc 100644 --- a/tests/Core/Collections/ExternalReferenceRepositoryTest.php +++ b/tests/Core/Collections/ExternalReferenceRepositoryTest.php @@ -41,8 +41,8 @@ public function testEmptyConstructor(): void public function testConstructAndGet(): void { - $externalReference1 = $this->createStub(ExternalReference::class); - $externalReference2 = $this->createStub(ExternalReference::class); + $externalReference1 = $this->createMock(ExternalReference::class); + $externalReference2 = $this->createMock(ExternalReference::class); $repo = new ExternalReferenceRepository( $externalReference1, @@ -59,9 +59,9 @@ public function testConstructAndGet(): void public function testAddAndGetItems(): void { - $externalReference1 = $this->createStub(ExternalReference::class); - $externalReference2 = $this->createStub(ExternalReference::class); - $externalReference3 = $this->createStub(ExternalReference::class); + $externalReference1 = $this->createMock(ExternalReference::class); + $externalReference2 = $this->createMock(ExternalReference::class); + $externalReference3 = $this->createMock(ExternalReference::class); $repo = new ExternalReferenceRepository($externalReference1, $externalReference2); $actual = $repo->addItems($externalReference2, $externalReference3, $externalReference3); diff --git a/tests/Core/Collections/LicenseRepositoryTest.php b/tests/Core/Collections/LicenseRepositoryTest.php index ba49036d..154d996c 100644 --- a/tests/Core/Collections/LicenseRepositoryTest.php +++ b/tests/Core/Collections/LicenseRepositoryTest.php @@ -42,8 +42,8 @@ public function testEmptyConstructor(): void public function testNonEmptyConstruct(): void { - $license1 = $this->createStub(SpdxLicense::class); - $license2 = $this->createStub(NamedLicense::class); + $license1 = $this->createMock(SpdxLicense::class); + $license2 = $this->createMock(NamedLicense::class); $repo = new LicenseRepository($license1, $license2, $license1, $license2); @@ -55,9 +55,9 @@ public function testNonEmptyConstruct(): void public function testAddAndGetItems(): void { - $license1 = $this->createStub(NamedLicense::class); - $license2 = $this->createStub(SpdxLicense::class); - $license3 = $this->createStub(NamedLicense::class); + $license1 = $this->createMock(NamedLicense::class); + $license2 = $this->createMock(SpdxLicense::class); + $license3 = $this->createMock(NamedLicense::class); $repo = new LicenseRepository($license1, $license2); $actual = $repo->addItems($license2, $license3, $license3); diff --git a/tests/Core/Collections/PropertyRepositoryTest.php b/tests/Core/Collections/PropertyRepositoryTest.php index 926a317f..ecf1a8a8 100644 --- a/tests/Core/Collections/PropertyRepositoryTest.php +++ b/tests/Core/Collections/PropertyRepositoryTest.php @@ -41,8 +41,8 @@ public function testEmptyConstructor(): void public function testConstructAndGet(): void { - $property1 = $this->createStub(Property::class); - $property2 = $this->createStub(Property::class); + $property1 = $this->createMock(Property::class); + $property2 = $this->createMock(Property::class); $repo = new PropertyRepository($property1, $property2, $property1, $property2); @@ -54,9 +54,9 @@ public function testConstructAndGet(): void public function testAddAndGetItems(): void { - $property1 = $this->createStub(Property::class); - $property2 = $this->createStub(Property::class); - $property3 = $this->createStub(Property::class); + $property1 = $this->createMock(Property::class); + $property2 = $this->createMock(Property::class); + $property3 = $this->createMock(Property::class); $repo = new PropertyRepository($property1, $property2); $actual = $repo->addItems($property2, $property3, $property3); diff --git a/tests/Core/Collections/ToolRepositoryTest.php b/tests/Core/Collections/ToolRepositoryTest.php index 94726ba4..2a63de59 100644 --- a/tests/Core/Collections/ToolRepositoryTest.php +++ b/tests/Core/Collections/ToolRepositoryTest.php @@ -41,8 +41,8 @@ public function testEmptyConstructor(): void public function testConstructAndGet(): void { - $tool1 = $this->createStub(Tool::class); - $tool2 = $this->createStub(Tool::class); + $tool1 = $this->createMock(Tool::class); + $tool2 = $this->createMock(Tool::class); $repo = new ToolRepository($tool1, $tool2, $tool1, $tool2); @@ -54,9 +54,9 @@ public function testConstructAndGet(): void public function testAddAndGetItems(): void { - $tool1 = $this->createStub(Tool::class); - $tool2 = $this->createStub(Tool::class); - $tool3 = $this->createStub(Tool::class); + $tool1 = $this->createMock(Tool::class); + $tool2 = $this->createMock(Tool::class); + $tool3 = $this->createMock(Tool::class); $repo = new ToolRepository($tool1, $tool2); $actual = $repo->addItems($tool2, $tool3, $tool3); diff --git a/tests/Core/Factories/LicenseFactoryTest.php b/tests/Core/Factories/LicenseFactoryTest.php index 723818f3..1b1bcf06 100644 --- a/tests/Core/Factories/LicenseFactoryTest.php +++ b/tests/Core/Factories/LicenseFactoryTest.php @@ -67,11 +67,11 @@ protected function tearDown(): void public function testConstructorWithArgs(): void { - $licenseIdentifiers = $this->createStub(LicenseIdentifiers::class); - $spdxLicenses = $this->createStub(SpdxLicenses::class); + $licenseIdentifiers = $this->createMock(LicenseIdentifiers::class); + $spdxLicenses = $this->createMock(SpdxLicenses::class); $factory = new LicenseFactory($licenseIdentifiers, $spdxLicenses); - self::assertSame($licenseIdentifiers, $factory->getLicenseIdentifiers()); - self::assertSame($spdxLicenses, $factory->getSpdxLicenses()); + self::assertSame($licenseIdentifiers, $factory->licenseIdentifiers); + self::assertSame($spdxLicenses, $factory->spdxLicenses); } public function testMakeNamedLicense(): void @@ -163,7 +163,7 @@ public function testMakeExpressionInvalidArgumentThrows(): void public function testMakeDisjunctiveSpdxLicense(): void { $license = uniqid('license', true); - $expected = $this->createStub(SpdxLicense::class); + $expected = $this->createMock(SpdxLicense::class); $factory = $this->createPartialMock(LicenseFactory::class, ['makeSpdxLicense']); $factory->method('makeSpdxLicense') ->with($license)->willReturn($expected); @@ -174,7 +174,7 @@ public function testMakeDisjunctiveSpdxLicense(): void public function testMakeDisjunctiveNamedLicense(): void { $license = uniqid('license', true); - $expected = $this->createStub(NamedLicense::class); + $expected = $this->createMock(NamedLicense::class); $factory = $this->createPartialMock(LicenseFactory::class, ['makeSpdxLicense', 'makeNamedLicense']); $factory->method('makeSpdxLicense') ->with($license)->willThrowException(new DomainException()); @@ -191,7 +191,7 @@ public function testMakeDisjunctiveNamedLicense(): void public function testMakeFromStringSpdxLicense(): void { $license = uniqid('license', true); - $expected = $this->createStub(SpdxLicense::class); + $expected = $this->createMock(SpdxLicense::class); $factory = $this->createPartialMock(LicenseFactory::class, ['makeSpdxLicense']); $factory->method('makeSpdxLicense') ->with($license)->willReturn($expected); @@ -202,7 +202,7 @@ public function testMakeFromStringSpdxLicense(): void public function testMakeFromStringLicenseExpression(): void { $license = uniqid('license', true); - $expected = $this->createStub(LicenseExpression::class); + $expected = $this->createMock(LicenseExpression::class); $factory = $this->createPartialMock(LicenseFactory::class, ['makeSpdxLicense', 'makeExpression']); $factory->method('makeSpdxLicense') ->with($license)->willThrowException(new DomainException()); @@ -215,7 +215,7 @@ public function testMakeFromStringLicenseExpression(): void public function testMakeFromStringNamedLicense(): void { $license = uniqid('license', true); - $expected = $this->createStub(NamedLicense::class); + $expected = $this->createMock(NamedLicense::class); $factory = $this->createPartialMock(LicenseFactory::class, ['makeSpdxLicense', 'makeExpression', 'makeNamedLicense']); $factory->method('makeSpdxLicense') ->with($license)->willThrowException(new DomainException()); diff --git a/tests/Core/Models/BomTest.php b/tests/Core/Models/BomTest.php index 7567d5a4..b4976fc7 100644 --- a/tests/Core/Models/BomTest.php +++ b/tests/Core/Models/BomTest.php @@ -95,7 +95,7 @@ public function testSerialNumberEmptyStringInvalidValue(Bom $bom): void #[DependsUsingShallowClone('testConstruct')] public function testComponentsSetterGetter(Bom $bom): void { - $components = $this->createStub(ComponentRepository::class); + $components = $this->createMock(ComponentRepository::class); $actual = $bom->setComponents($components); self::assertSame($bom, $actual); self::assertSame($components, $bom->getComponents()); @@ -129,7 +129,7 @@ public function testVersionSetterInvalidValue(Bom $bom): void #[DependsUsingShallowClone('testConstruct')] public function testMetadataSetterGetter(Bom $bom): void { - $metadata = $this->createStub(Metadata::class); + $metadata = $this->createMock(Metadata::class); $actual = $bom->setMetadata($metadata); self::assertSame($bom, $actual); self::assertSame($metadata, $bom->getMetadata()); @@ -142,7 +142,7 @@ public function testMetadataSetterGetter(Bom $bom): void #[DependsUsingShallowClone('testConstruct')] public function testExternalReferenceRepositorySetterGetter(Bom $bom): void { - $extRefRepo = $this->createStub(ExternalReferenceRepository::class); + $extRefRepo = $this->createMock(ExternalReferenceRepository::class); $actual = $bom->setExternalReferences($extRefRepo); self::assertSame($bom, $actual); self::assertSame($extRefRepo, $bom->getExternalReferences()); @@ -155,7 +155,7 @@ public function testExternalReferenceRepositorySetterGetter(Bom $bom): void #[DependsUsingShallowClone('testConstruct')] public function testPropertiesSetterGetter(Bom $bom): void { - $repo = $this->createStub(PropertyRepository::class); + $repo = $this->createMock(PropertyRepository::class); $actual = $bom->setProperties($repo); self::assertSame($bom, $actual); self::assertSame($repo, $bom->getProperties()); diff --git a/tests/Core/Models/ComponentEvidenceTest.php b/tests/Core/Models/ComponentEvidenceTest.php index 7018d30d..3f4286e6 100644 --- a/tests/Core/Models/ComponentEvidenceTest.php +++ b/tests/Core/Models/ComponentEvidenceTest.php @@ -49,7 +49,7 @@ public function testConstructor(): ComponentEvidence #[DependsUsingShallowClone('testConstructor')] public function testLicensesSetterGetter(ComponentEvidence $evidence): void { - $licenses = $this->createStub(LicenseRepository::class); + $licenses = $this->createMock(LicenseRepository::class); $actual = $evidence->setLicenses($licenses); self::assertSame($evidence, $actual); self::assertSame($licenses, $evidence->getLicenses()); @@ -58,7 +58,7 @@ public function testLicensesSetterGetter(ComponentEvidence $evidence): void #[DependsUsingShallowClone('testConstructor')] public function testCopyrightSetterGetter(ComponentEvidence $evidence): void { - $copyright = $this->createStub(CopyrightRepository::class); + $copyright = $this->createMock(CopyrightRepository::class); $actual = $evidence->setCopyright($copyright); self::assertSame($evidence, $actual); self::assertSame($copyright, $evidence->getCopyright()); diff --git a/tests/Core/Models/ComponentTest.php b/tests/Core/Models/ComponentTest.php index b0ef15c8..6d605235 100644 --- a/tests/Core/Models/ComponentTest.php +++ b/tests/Core/Models/ComponentTest.php @@ -118,7 +118,7 @@ public function testVersionSetterGetter(Component $component): void #[DependsUsingShallowClone('testConstructor')] public function testLicensesSetterGetter(Component $component): void { - $licenses = $this->createStub(LicenseRepository::class); + $licenses = $this->createMock(LicenseRepository::class); self::assertnotSame($licenses, $component->getLicenses()); $actual = $component->setLicenses($licenses); self::assertSame($component, $actual); @@ -132,7 +132,7 @@ public function testLicensesSetterGetter(Component $component): void #[DependsUsingShallowClone('testConstructor')] public function testHashesSetterGetter(Component $component): void { - $hashes = $this->createStub(HashDictionary::class); + $hashes = $this->createMock(HashDictionary::class); self::assertnotSame($hashes, $component->getHashes()); $actual = $component->setHashes($hashes); self::assertSame($component, $actual); @@ -237,7 +237,7 @@ public function testDependenciesBomRefRepositorySetterGetter(Component $componen #[DependsUsingShallowClone('testConstructor')] public function testExternalReferenceRepositorySetterGetter(Component $component): void { - $extRefRepo = $this->createStub(ExternalReferenceRepository::class); + $extRefRepo = $this->createMock(ExternalReferenceRepository::class); self::assertNotSame($extRefRepo, $component->getExternalReferences()); $actual = $component->setExternalReferences($extRefRepo); self::assertSame($component, $actual); @@ -251,7 +251,7 @@ public function testExternalReferenceRepositorySetterGetter(Component $component #[DependsUsingShallowClone('testConstructor')] public function testGetterSetterProperties(Component $component): void { - $properties = $this->createStub(PropertyRepository::class); + $properties = $this->createMock(PropertyRepository::class); self::assertNotSame($properties, $component->getProperties()); $actual = $component->setProperties($properties); self::assertSame($component, $actual); @@ -300,7 +300,7 @@ public static function dpCopyrightSetterGetter(): Generator #[DependsUsingShallowClone('testConstructor')] public function testEvidenceSetterGetter(Component $component): void { - $evidence = $this->createStub(ComponentEvidence::class); + $evidence = $this->createMock(ComponentEvidence::class); $actual = $component->setEvidence($evidence); self::assertSame($component, $actual); self::assertSame($evidence, $component->getEvidence()); @@ -309,7 +309,7 @@ public function testEvidenceSetterGetter(Component $component): void #[DependsUsingShallowClone('testConstructor')] public function testEvidenceSetterGetterNull(Component $component): void { - $component->setEvidence($this->createStub(ComponentEvidence::class)); + $component->setEvidence($this->createMock(ComponentEvidence::class)); self::assertNotNull($component->getEvidence()); $component->setEvidence(null); self::assertNull($component->getEvidence()); diff --git a/tests/Core/Models/ExternalReferenceTest.php b/tests/Core/Models/ExternalReferenceTest.php index 2834e304..d5cfb2cb 100644 --- a/tests/Core/Models/ExternalReferenceTest.php +++ b/tests/Core/Models/ExternalReferenceTest.php @@ -100,7 +100,7 @@ public function testCommentSetterAndGetter(ExternalReference $extRef): void #[DependsUsingShallowClone('testConstructor')] public function testHashesSetterAndGetter(ExternalReference $extRef): void { - $hashes = $this->createStub(HashDictionary::class); + $hashes = $this->createMock(HashDictionary::class); $this->assertNotSame($hashes, $extRef->getHashes()); $got = $extRef->setHashes($hashes); $this->assertSame($extRef, $got); diff --git a/tests/Core/Models/MetadataTest.php b/tests/Core/Models/MetadataTest.php index 2d1aad81..a86354c1 100644 --- a/tests/Core/Models/MetadataTest.php +++ b/tests/Core/Models/MetadataTest.php @@ -53,7 +53,7 @@ public function testConstructor(): Metadata #[DependsUsingShallowClone('testConstructor')] public function testGetterSetterTimestamp(Metadata $metadata): void { - $timestamp = $this->createStub(DateTime::class); + $timestamp = $this->createMock(DateTime::class); self::assertNotSame($timestamp, $metadata->getTimestamp()); $actual = $metadata->setTimestamp($timestamp); self::assertSame($actual, $metadata); @@ -63,7 +63,7 @@ public function testGetterSetterTimestamp(Metadata $metadata): void #[DependsUsingShallowClone('testConstructor')] public function testGetterSetterTools(Metadata $metadata): void { - $tools = $this->createStub(ToolRepository::class); + $tools = $this->createMock(ToolRepository::class); $actual = $metadata->setTools($tools); self::assertSame($actual, $metadata); self::assertSame($tools, $metadata->getTools()); @@ -72,7 +72,7 @@ public function testGetterSetterTools(Metadata $metadata): void #[DependsUsingShallowClone('testConstructor')] public function testGetterSetterComponent(Metadata $metadata): void { - $component = $this->createStub(Component::class); + $component = $this->createMock(Component::class); self::assertNotSame($component, $metadata->getComponent()); $actual = $metadata->setComponent($component); self::assertSame($actual, $metadata); @@ -82,7 +82,7 @@ public function testGetterSetterComponent(Metadata $metadata): void #[DependsUsingShallowClone('testConstructor')] public function testGetterSetterProperties(Metadata $metadata): void { - $properties = $this->createStub(PropertyRepository::class); + $properties = $this->createMock(PropertyRepository::class); self::assertNotSame($properties, $metadata->getProperties()); $actual = $metadata->setProperties($properties); self::assertSame($actual, $metadata); diff --git a/tests/Core/Models/ToolTest.php b/tests/Core/Models/ToolTest.php index 76f435db..98a77105 100644 --- a/tests/Core/Models/ToolTest.php +++ b/tests/Core/Models/ToolTest.php @@ -82,7 +82,7 @@ public function testSetterGetterName(Tool $tool): void #[DependsUsingShallowClone('testConstruct')] public function testSetterGetterHashDictionary(Tool $tool): void { - $hashes = $this->createStub(HashDictionary::class); + $hashes = $this->createMock(HashDictionary::class); self::assertNotSame($hashes, $tool->getHashes()); $actual = $tool->setHashes($hashes); self::assertSame($actual, $tool); @@ -92,7 +92,7 @@ public function testSetterGetterHashDictionary(Tool $tool): void #[DependsUsingShallowClone('testConstruct')] public function testSetterGetterExternalReferenceRepository(Tool $tool): void { - $extRefs = $this->createStub(ExternalReferenceRepository::class); + $extRefs = $this->createMock(ExternalReferenceRepository::class); self::assertNotSame($extRefs, $tool->getExternalReferences()); $actual = $tool->setExternalReferences($extRefs); self::assertSame($actual, $tool); diff --git a/tests/Core/Serialization/BaseSerializerTest.php b/tests/Core/Serialization/BaseSerializerTest.php index 06040f6a..d720c90e 100644 --- a/tests/Core/Serialization/BaseSerializerTest.php +++ b/tests/Core/Serialization/BaseSerializerTest.php @@ -48,7 +48,7 @@ public function testSerialize(): void $prettyPrint = [null, true, false][random_int(0, 2)]; $normalized = uniqid('normalized', true); $serialized = uniqid('serialized', true); - $bom = $this->createStub(Bom::class); + $bom = $this->createMock(Bom::class); $serializer = $this->getMockForAbstractClass(BaseSerializer::class); $serializer->expects(self::once()) ->method('realNormalize') @@ -66,8 +66,8 @@ public function testSerialize(): void public function testSerializeForwardsExceptionsFromRealNormalize(): void { - $bom = $this->createStub(Bom::class); - $exception = $this->createStub(Exception::class); + $bom = $this->createMock(Bom::class); + $exception = $this->createMock(Exception::class); $serializer = $this->getMockForAbstractClass(BaseSerializer::class); $serializer->expects(self::once()) ->method('realNormalize') @@ -82,8 +82,8 @@ public function testSerializeForwardsExceptionsFromRealNormalize(): void public function testSerializeForwardsExceptionsFromRealSerializer(): void { - $exception = $this->createStub(Exception::class); - $bom = $this->createStub(Bom::class); + $exception = $this->createMock(Exception::class); + $bom = $this->createMock(Bom::class); $serializer = $this->getMockForAbstractClass(BaseSerializer::class); $serializer->expects(self::once()) ->method('realNormalize'); @@ -156,7 +156,7 @@ public function testSerializeUsesUniqueBomRefsAndResetThemOnThrow(Bom $bom, arra $allBomRefsValuesOriginal[] = [$bomRef, $bomRef->getValue()]; } $allBomRefsValuesOnNormalize = []; - $exception = $this->createStub(Exception::class); + $exception = $this->createMock(Exception::class); $serializer = $this->getMockForAbstractClass(BaseSerializer::class); $serializer->expects(self::once()) ->method('realNormalize') @@ -196,7 +196,7 @@ function () use ($allBomRefsValuesOriginal, &$allBomRefsValuesOnNormalize, $exce public function dpBomWithRefs(): Generator { - $dependencies = $this->createStub(BomRefRepository::class); + $dependencies = $this->createMock(BomRefRepository::class); foreach (['null' => null, 'common string' => 'foo'] as $name => $bomRefValue) { $componentNullDeps = $this->createConfiguredMock( diff --git a/tests/Core/Serialization/DOM/NormalizerFactoryTest.php b/tests/Core/Serialization/DOM/NormalizerFactoryTest.php index 8b8ec61b..3f4c4ebc 100644 --- a/tests/Core/Serialization/DOM/NormalizerFactoryTest.php +++ b/tests/Core/Serialization/DOM/NormalizerFactoryTest.php @@ -64,8 +64,8 @@ public function testConstructor(): NormalizerFactory ); $factory = new NormalizerFactory($spec); - self::assertSame($spec, $factory->getSpec()); - self::assertInstanceOf(DOMDocument::class, $factory->getDocument()); + self::assertSame($spec, $factory->spec); + self::assertInstanceOf(DOMDocument::class, $factory->document); return $factory; } @@ -91,7 +91,7 @@ public function testMakeForComponentRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForComponentRepository(); self::assertInstanceOf(Normalizers\ComponentRepositoryNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -99,7 +99,7 @@ public function testMakeForBom(NormalizerFactory $factory): void { $normalizer = $factory->makeForBom(); self::assertInstanceOf(Normalizers\BomNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -107,7 +107,7 @@ public function testMakeForLicense(NormalizerFactory $factory): void { $normalizer = $factory->makeForLicense(); self::assertInstanceOf(Normalizers\LicenseNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -115,7 +115,7 @@ public function testMakeForDisjunctiveLicense(NormalizerFactory $factory): void { $normalizer = $factory->makeForLicenseRepository(); self::assertInstanceOf(Normalizers\LicenseRepositoryNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -123,7 +123,7 @@ public function testMakeForHashDictionary(NormalizerFactory $factory): void { $normalizer = $factory->makeForHashDictionary(); self::assertInstanceOf(Normalizers\HashDictionaryNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -131,7 +131,7 @@ public function testMakeForComponent(NormalizerFactory $factory): void { $normalizer = $factory->makeForComponent(); self::assertInstanceOf(Normalizers\ComponentNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -139,7 +139,7 @@ public function testMakeForHash(NormalizerFactory $factory): void { $normalizer = $factory->makeForHash(); self::assertInstanceOf(Normalizers\HashNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -147,7 +147,7 @@ public function testMakeForMetadata(NormalizerFactory $factory): void { $normalizer = $factory->makeForMetadata(); self::assertInstanceOf(Normalizers\MetadataNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -155,7 +155,7 @@ public function testMakeForToolRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForToolRepository(); self::assertInstanceOf(Normalizers\ToolRepositoryNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -163,7 +163,7 @@ public function testMakeForTool(NormalizerFactory $factory): void { $normalizer = $factory->makeForTool(); self::assertInstanceOf(Normalizers\ToolNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -171,7 +171,7 @@ public function testMakeForDependencies(NormalizerFactory $factory): void { $normalizer = $factory->makeForDependencies(); self::assertInstanceOf(Normalizers\DependenciesNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -179,7 +179,7 @@ public function testMakeForExternalReference(NormalizerFactory $factory): void { $normalizer = $factory->makeForExternalReference(); self::assertInstanceOf(Normalizers\ExternalReferenceNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -187,7 +187,7 @@ public function testMakeForExternalReferenceRepository(NormalizerFactory $factor { $normalizer = $factory->makeForExternalReferenceRepository(); self::assertInstanceOf(Normalizers\ExternalReferenceRepositoryNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -195,7 +195,7 @@ public function testMakeForProperty(NormalizerFactory $factory): void { $normalizer = $factory->makeForProperty(); self::assertInstanceOf(Normalizers\PropertyNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -203,7 +203,7 @@ public function testMakeForPropertyRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForPropertyRepository(); self::assertInstanceOf(Normalizers\PropertyRepositoryNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -211,6 +211,6 @@ public function testMakeForComponentEvidence(NormalizerFactory $factory): void { $normalizer = $factory->makeForComponentEvidence(); self::assertInstanceOf(Normalizers\ComponentEvidenceNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } } diff --git a/tests/Core/Serialization/DOM/Normalizers/BomNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/BomNormalizerTest.php index cfc852dc..d5a2be8a 100644 --- a/tests/Core/Serialization/DOM/Normalizers/BomNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/BomNormalizerTest.php @@ -37,31 +37,53 @@ use CycloneDX\Core\Spec\Spec; use CycloneDX\Core\Spec\Version; use CycloneDX\Tests\_traits\DomNodeAssertionTrait; +use CycloneDX\Tests\_traits\MockOCTrait; use DOMDocument; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\UsesClass; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use function pcov\memory; #[CoversClass(Normalizers\BomNormalizer::class)] #[CoversClass(_BaseNormalizer::class)] +#[UsesClass(NormalizerFactory::class)] #[UsesClass(SimpleDOM::class)] #[UsesClass(ExternalReferenceRepository::class)] #[UsesClass(ExternalReferenceRepository::class)] class BomNormalizerTest extends TestCase { use DomNodeAssertionTrait; + use MockOCTrait; - public function testNormalize(): void + private NormalizerFactory & MockObject $factory; + private Spec&MockObject $spec; + + protected function setUp(): void { - $spec = $this->createConfiguredMock(Spec::class, ['getVersion' => Version::v1dot2]); - $factory = $this->createConfiguredMock( - NormalizerFactory::class, + $this->spec = $this->createConfiguredMock( + Spec::class, [ - 'getSpec' => $spec, - 'getDocument' => new DOMDocument(), - ] + 'isSupportedFormat' => true, + 'getVersion' => Version::v1dot2] ); - $normalizer = new Normalizers\BomNormalizer($factory); + $this->factory = $this->createMockOC( + NormalizerFactory::class, + [$this->spec, new DOMDocument()] + ); + } + + protected function tearDown(): void + { + unset( + $this->factory, + $this->spec + ); + } + + public function testNormalize(): void + { + $normalizer = new Normalizers\BomNormalizer($this->factory); $bom = $this->createConfiguredMock( Bom::class, [ @@ -74,7 +96,7 @@ public function testNormalize(): void self::assertStringEqualsDomNode( ''. - ''. + ''. '', $actual ); @@ -82,35 +104,27 @@ public function testNormalize(): void public function testNormalizeComponents(): void { - $spec = $this->createConfiguredMock(Spec::class, ['getVersion' => Version::v1dot2]); $componentsNormalizer = $this->createMock(Normalizers\ComponentRepositoryNormalizer::class); - $factory = $this->createConfiguredMock( - NormalizerFactory::class, - [ - 'getSpec' => $spec, - 'getDocument' => new DOMDocument(), - 'makeForComponentRepository' => $componentsNormalizer, - ] - ); - $normalizer = new Normalizers\BomNormalizer($factory); + $this->factory->method('makeForComponentRepository')->willReturn($componentsNormalizer); + $normalizer = new Normalizers\BomNormalizer($this->factory); $bom = $this->createConfiguredMock( Bom::class, [ 'getVersion' => 42, - 'getComponents' => $this->createStub(ComponentRepository::class), + 'getComponents' => $this->createMock(ComponentRepository::class), ] ); $componentsNormalizer->expects(self::once()) ->method('normalize') ->with($bom->getComponents()) - ->willReturn([$factory->getDocument()->createElement('FakeComponent', 'dummy')]); + ->willReturn([$this->factory->document->createElement('FakeComponent', 'dummy')]); $actual = $normalizer->normalize($bom); self::assertStringEqualsDomNode( ''. - 'dummy'. + 'dummy'. '', $actual ); @@ -120,42 +134,29 @@ public function testNormalizeComponents(): void public function testNormalizeMetadata(): void { - $spec = $this->createConfiguredMock( - Spec::class, - [ - 'getVersion' => Version::v1dot2, - 'supportsMetadata' => true, - ] - ); + $this->spec->method('supportsMetadata')->willReturn(true); $metadataNormalizer = $this->createMock(Normalizers\MetadataNormalizer::class); - $factory = $this->createConfiguredMock( - NormalizerFactory::class, - [ - 'getSpec' => $spec, - 'getDocument' => new DOMDocument(), - 'makeForMetadata' => $metadataNormalizer, - ] - ); - $normalizer = new Normalizers\BomNormalizer($factory); + $this->factory->method( 'makeForMetadata')->willReturn($metadataNormalizer); + $normalizer = new Normalizers\BomNormalizer($this->factory); $bom = $this->createConfiguredMock( Bom::class, [ 'getVersion' => 1337, - 'getMetadata' => $this->createStub(Metadata::class), + 'getMetadata' => $this->createMock(Metadata::class), ] ); $metadataNormalizer->expects(self::once()) ->method('normalize') ->with($bom->getMetadata()) - ->willReturn($factory->getDocument()->createElement('metadata', 'FakeMetadata')); + ->willReturn($this->factory->document->createElement('metadata', 'FakeMetadata')); $actual = $normalizer->normalize($bom); self::assertStringEqualsDomNode( ''. - 'FakeMetadata'. - ''. + 'FakeMetadata'. + ''. '', $actual ); @@ -163,40 +164,27 @@ public function testNormalizeMetadata(): void public function testNormalizeMetadataNotSupported(): void { - $spec = $this->createConfiguredMock( - Spec::class, - [ - 'getVersion' => Version::v1dot2, - 'supportsMetadata' => false, - ] - ); + $this->spec->method('supportsMetadata')->willReturn(false); $metadataNormalizer = $this->createMock(Normalizers\MetadataNormalizer::class); - $factory = $this->createConfiguredMock( - NormalizerFactory::class, - [ - 'getSpec' => $spec, - 'getDocument' => new DOMDocument(), - 'makeForMetadata' => $metadataNormalizer, - ] - ); - $normalizer = new Normalizers\BomNormalizer($factory); + $this->factory->method('makeForMetadata')->willReturn($metadataNormalizer); + $normalizer = new Normalizers\BomNormalizer($this->factory); $bom = $this->createConfiguredMock( Bom::class, [ 'getVersion' => 1, - 'getMetadata' => $this->createStub(Metadata::class), + 'getMetadata' => $this->createMock(Metadata::class), ] ); $metadataNormalizer->method('normalize') ->with($bom->getMetadata()) - ->willReturn($factory->getDocument()->createElement('metadata', 'FakeMetadata')); + ->willReturn($this->factory->document->createElement('metadata', 'FakeMetadata')); $actual = $normalizer->normalize($bom); self::assertStringEqualsDomNode( ''. - ''. + ''. '', $actual ); @@ -211,16 +199,18 @@ public function testNormalizeDependencies(): void $spec = $this->createConfiguredMock( Spec::class, [ + 'isSupportedFormat' => true, 'getVersion' => Version::v1dot2, 'supportsDependencies' => true, ] ); $dependencyNormalizer = $this->createMock(Normalizers\DependenciesNormalizer::class); - $factory = $this->createConfiguredMock( + $factory = $this->createConfiguredMockOC( NormalizerFactory::class, [ - 'getSpec' => $spec, - 'getDocument' => new DOMDocument(), + 'spec' => $spec, + 'document' => new DOMDocument(), + ], [ 'makeForDependencies' => $dependencyNormalizer, ] ); @@ -229,14 +219,14 @@ public function testNormalizeDependencies(): void Bom::class, [ 'getVersion' => 23, - 'getMetadata' => $this->createStub(Metadata::class), + 'getMetadata' => $this->createMock(Metadata::class), ] ); $dependencyNormalizer->expects(self::once()) ->method('normalize') ->with($bom) - ->willReturn([$factory->getDocument()->createElement('FakeDependencies', 'faked')]); + ->willReturn([$factory->document->createElement('FakeDependencies', 'faked')]); $actual = $normalizer->normalize($bom); @@ -254,16 +244,18 @@ public function testNormalizeDependenciesOmitWhenEmpty(): void $spec = $this->createConfiguredMock( Spec::class, [ + 'isSupportedFormat' => true, 'getVersion' => Version::v1dot2, 'supportsDependencies' => true, ] ); $dependencyNormalizer = $this->createMock(Normalizers\DependenciesNormalizer::class); - $factory = $this->createConfiguredMock( + $factory = $this->createConfiguredMockOC( NormalizerFactory::class, [ - 'getSpec' => $spec, - 'getDocument' => new DOMDocument(), + 'spec' => $spec, + 'document' => new DOMDocument(), + ], [ 'makeForDependencies' => $dependencyNormalizer, ] ); @@ -272,7 +264,7 @@ public function testNormalizeDependenciesOmitWhenEmpty(): void Bom::class, [ 'getVersion' => 23, - 'getMetadata' => $this->createStub(Metadata::class), + 'getMetadata' => $this->createMock(Metadata::class), ] ); @@ -299,18 +291,20 @@ public function testNormalizeDependenciesOmitWhenEmpty(): void public function testNormalizeExternalReferencesMergedIfUnsupportedMetadata(): void { $spec = $this->createConfiguredMock(Spec::class, [ + 'isSupportedFormat' => true, 'getVersion' => Version::v1dot2, 'supportsMetadata' => false, ]); $extRefNormalizer = $this->createMock(Normalizers\ExternalReferenceRepositoryNormalizer::class); - $factory = $this->createConfiguredMock(NormalizerFactory::class, [ - 'getSpec' => $spec, - 'getDocument' => new DOMDocument(), + $factory = $this->createConfiguredMockOC(NormalizerFactory::class, [ + 'spec' => $spec, + 'document' => new DOMDocument(), + ], [ 'makeForExternalReferenceRepository' => $extRefNormalizer, ]); $normalizer = new Normalizers\BomNormalizer($factory); - $extRef1 = $this->createStub(ExternalReference::class); - $extRef2 = $this->createStub(ExternalReference::class); + $extRef1 = $this->createMock(ExternalReference::class); + $extRef2 = $this->createMock(ExternalReference::class); $bom = $this->createConfiguredMock( Bom::class, [ @@ -336,7 +330,7 @@ public function testNormalizeExternalReferencesMergedIfUnsupportedMetadata(): vo return true; })) - ->willReturn([$factory->getDocument()->createElement('FakeexternalReference', 'faked')]); + ->willReturn([$factory->document->createElement('FakeexternalReference', 'faked')]); $actual = $normalizer->normalize($bom); @@ -352,18 +346,21 @@ public function testNormalizeExternalReferencesMergedIfUnsupportedMetadata(): vo public function testNormalizeExternalReferencesOmittedWHenEmpty(): void { $spec = $this->createConfiguredMock(Spec::class, [ + 'isSupportedFormat' => true, 'getVersion' => Version::v1dot2, 'supportsMetadata' => false, ]); $extRefNormalizer = $this->createMock(Normalizers\ExternalReferenceRepositoryNormalizer::class); - $factory = $this->createConfiguredMock(NormalizerFactory::class, [ - 'getSpec' => $spec, - 'getDocument' => new DOMDocument(), + $factory = $this->createConfiguredMockOC(NormalizerFactory::class, + [ + 'spec' => $spec, + 'document' => new DOMDocument(), + ], [ 'makeForExternalReferenceRepository' => $extRefNormalizer, ]); $normalizer = new Normalizers\BomNormalizer($factory); - $extRef1 = $this->createStub(ExternalReference::class); - $extRef2 = $this->createStub(ExternalReference::class); + $extRef1 = $this->createMock(ExternalReference::class); + $extRef2 = $this->createMock(ExternalReference::class); $bom = $this->createConfiguredMock( Bom::class, [ @@ -401,15 +398,17 @@ public function testNormalizeProperties(): void ] ); $spec = $this->createConfiguredMock(Spec::class, [ + 'isSupportedFormat' => true, 'getVersion' => Version::v1dot4, 'supportsBomProperties' => true, ]); $propertiesNormalizer = $this->createMock(Normalizers\PropertyRepositoryNormalizer::class); - $factory = $this->createConfiguredMock( + $factory = $this->createConfiguredMockOC( NormalizerFactory::class, [ - 'getSpec' => $spec, - 'getDocument' => new DOMDocument(), + 'spec' => $spec, + 'document' => new DOMDocument(), + ], [ 'makeForPropertyRepository' => $propertiesNormalizer, ] ); @@ -419,7 +418,7 @@ public function testNormalizeProperties(): void ->method('normalize') ->with($bom->getProperties()) ->willReturn( - [$factory->getDocument()->createElement('FakeProperties', 'dummy')]); + [$factory->document->createElement('FakeProperties', 'dummy')]); $actual = $normalizer->normalize($bom); @@ -440,15 +439,17 @@ public function testNormalizePropertiesOmitEmpty(): void ] ); $spec = $this->createConfiguredMock(Spec::class, [ + 'isSupportedFormat' => true, 'getVersion' => Version::v1dot4, 'supportsBomProperties' => true, ]); $propertiesNormalizer = $this->createMock(Normalizers\PropertyRepositoryNormalizer::class); - $factory = $this->createConfiguredMock( + $factory = $this->createConfiguredMockOC( NormalizerFactory::class, [ - 'getSpec' => $spec, - 'getDocument' => new DOMDocument(), + 'spec' => $spec, + 'document' => new DOMDocument(), + ], [ 'makeForPropertyRepository' => $propertiesNormalizer, ] ); diff --git a/tests/Core/Serialization/DOM/Normalizers/ComponentEvidenceNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/ComponentEvidenceNormalizerTest.php index 42788708..74616650 100644 --- a/tests/Core/Serialization/DOM/Normalizers/ComponentEvidenceNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/ComponentEvidenceNormalizerTest.php @@ -90,7 +90,7 @@ public function testNormalizeFull(): void $licenseRepoNormalizer->expects(self::once()) ->method('normalize') ->with($evidence->getLicenses()) - ->willReturn([$factory->getDocument()->createElement('FakeLicense', 'dummy')]); + ->willReturn([$factory->document->createElement('FakeLicense', 'dummy')]); $actual = $normalizer->normalize($evidence); diff --git a/tests/Core/Serialization/DOM/Normalizers/ComponentNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/ComponentNormalizerTest.php index c5b3ac62..b193d2fe 100644 --- a/tests/Core/Serialization/DOM/Normalizers/ComponentNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/ComponentNormalizerTest.php @@ -92,8 +92,8 @@ public function testNormalizeMinimal(string $expected, bool $requiresComponentVe 'getGroup' => null, 'getDescription' => null, 'getAuthor' => null, - 'getLicenses' => $this->createStub(LicenseRepository::class), - 'getHashes' => $this->createStub(HashDictionary::class), + 'getLicenses' => $this->createMock(LicenseRepository::class), + 'getHashes' => $this->createMock(HashDictionary::class), 'getPackageUrl' => null, ] ); @@ -180,15 +180,15 @@ public function testNormalizeFull(): void $licenseRepoNormalizer->expects(self::once()) ->method('normalize') ->with($component->getLicenses()) - ->willReturn([$factory->getDocument()->createElement('FakeLicense', 'dummy')]); + ->willReturn([$factory->document->createElement('FakeLicense', 'dummy')]); $hashDictionaryNormalizer->expects(self::once()) ->method('normalize') ->with($component->getHashes()) - ->willReturn([$factory->getDocument()->createElement('FakeHash', 'dummy')]); + ->willReturn([$factory->document->createElement('FakeHash', 'dummy')]); $evidenceNormalizer->expects(self::once()) ->method('normalize') ->with($component->getEvidence()) - ->willReturn($factory->getDocument()->createElement('FakeEvidence', 'dummy')); + ->willReturn($factory->document->createElement('FakeEvidence', 'dummy')); $actual = $normalizer->normalize($component); @@ -238,7 +238,7 @@ public function testNormalizeLicenses(): void $licenseRepoNormalizer->expects(self::once()) ->method('normalize') ->with($component->getLicenses()) - ->willReturn([$factory->getDocument()->createElement('FakeLicense', 'dummy')]); + ->willReturn([$factory->document->createElement('FakeLicense', 'dummy')]); $got = $normalizer->normalize($component); @@ -321,7 +321,7 @@ public function testNormalizeExternalReferences(): void $externalReferenceRepositoryNormalizer->expects(self::once()) ->method('normalize') ->with($component->getExternalReferences()) - ->willReturn([$factory->getDocument()->createElement('FakeExternalReference', 'dummy')]); + ->willReturn([$factory->document->createElement('FakeExternalReference', 'dummy')]); $actual = $normalizer->normalize($component); @@ -405,7 +405,7 @@ public function testNormalizeProperties(): void ->method('normalize') ->with($component->getProperties()) ->willReturn( - [$factory->getDocument()->createElement('FakeProperties', 'dummy')]); + [$factory->document->createElement('FakeProperties', 'dummy')]); $spec->expects(self::once()) ->method('isSupportedComponentType') ->with(ComponentType::LIBRARY) diff --git a/tests/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizerTest.php index fbe84ca9..57226050 100644 --- a/tests/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizerTest.php @@ -44,7 +44,7 @@ class ComponentRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, ['getSpec' => $spec]); $normalizer = new ComponentRepositoryNormalizer($factory); $components = $this->createConfiguredMock(ComponentRepository::class, ['count' => 0]); @@ -56,19 +56,19 @@ public function testNormalizeEmpty(): void public function testNormalize(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $componentNormalizer = $this->createMock(ComponentNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForComponent' => $componentNormalizer, ]); $normalizer = new ComponentRepositoryNormalizer($factory); - $component = $this->createStub(Component::class); + $component = $this->createMock(Component::class); $components = $this->createConfiguredMock(ComponentRepository::class, [ 'count' => 1, 'getItems' => [$component], ]); - $FakeComponent = $this->createStub(DOMElement::class); + $FakeComponent = $this->createMock(DOMElement::class); $componentNormalizer->expects(self::once())->method('normalize') ->with($component) @@ -81,15 +81,15 @@ public function testNormalize(): void public function testNormalizeSkipsOnThrow(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $componentNormalizer = $this->createMock(ComponentNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForComponent' => $componentNormalizer, ]); $normalizer = new ComponentRepositoryNormalizer($factory); - $component1 = $this->createStub(Component::class); - $component2 = $this->createStub(Component::class); + $component1 = $this->createMock(Component::class); + $component2 = $this->createMock(Component::class); $components = $this->createConfiguredMock(ComponentRepository::class, [ 'count' => 1, 'getItems' => [$component1, $component2], diff --git a/tests/Core/Serialization/DOM/Normalizers/DependenciesNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/DependenciesNormalizerTest.php index e0d006e5..d7b03adf 100644 --- a/tests/Core/Serialization/DOM/Normalizers/DependenciesNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/DependenciesNormalizerTest.php @@ -104,7 +104,7 @@ public function testNormalize(Bom $bom, array $expecteds): void public function dpNormalize(): Generator { - $dependencies = $this->createStub(BomRefRepository::class); + $dependencies = $this->createMock(BomRefRepository::class); $componentWithoutBomRefValue = $this->createConfiguredMock( Component::class, diff --git a/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizerTest.php index 410a2b65..9ecd3698 100644 --- a/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizerTest.php @@ -59,7 +59,7 @@ public function testNormalizeTypeAndUrl(): void 'getUrl' => 'someUrl', 'getType' => ExternalReferenceType::BOM, 'getComment' => null, - 'getHashes' => $this->createStub(HashDictionary::class), + 'getHashes' => $this->createMock(HashDictionary::class), ]); $spec->method('isSupportedExternalReferenceType') @@ -110,7 +110,7 @@ public function testThrowOnUnsupportedRefType(): void 'getUrl' => '..', 'getType' => ExternalReferenceType::BOM, 'getComment' => null, - 'getHashes' => $this->createStub(HashDictionary::class), + 'getHashes' => $this->createMock(HashDictionary::class), ]); $spec->expects(self::exactly(2)) @@ -166,7 +166,7 @@ public function testNormalizeComment(): void 'getUrl' => 'someUrl', 'getType' => ExternalReferenceType::BOM, 'getComment' => 'someComment', - 'getHashes' => $this->createStub(HashDictionary::class), + 'getHashes' => $this->createMock(HashDictionary::class), ]); $spec->method('isSupportedExternalReferenceType') @@ -208,7 +208,7 @@ public function testNormalizeHashes(): void $HashDictionaryNormalizer->expects(self::once()) ->method('normalize') ->with($extRef->getHashes()) - ->willReturn([$normalizerFactory->getDocument()->createElement('FakeHash', 'dummy')]); + ->willReturn([$normalizerFactory->document->createElement('FakeHash', 'dummy')]); $actual = $normalizer->normalize($extRef); @@ -237,7 +237,7 @@ public function testNormalizeHashesOmitIfEmpty(): void 'getUrl' => 'someUrl', 'getType' => ExternalReferenceType::BOM, 'getComment' => null, - 'getHashes' => $this->createStub(HashDictionary::class), + 'getHashes' => $this->createMock(HashDictionary::class), ]); $spec->method('isSupportedExternalReferenceType') @@ -304,7 +304,7 @@ public function testNormalizeUrlEncodeAnyUri(string $rawUrl, string $encodedUrl) 'getUrl' => $rawUrl, 'getType' => ExternalReferenceType::BOM, 'getComment' => null, - 'getHashes' => $this->createStub(HashDictionary::class), + 'getHashes' => $this->createMock(HashDictionary::class), ]); $spec->expects(self::atLeastOnce()) diff --git a/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizerTest.php index 25bc3f07..ea3b83ad 100644 --- a/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizerTest.php @@ -48,7 +48,7 @@ class ExternalReferenceRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $externalReferenceNormalizer = $this->createMock(ExternalReferenceNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, @@ -65,19 +65,19 @@ public function testNormalizeEmpty(): void public function testNormalize(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $externalReferenceNormalizer = $this->createMock(ExternalReferenceNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForExternalReference' => $externalReferenceNormalizer, ]); $normalizer = new ExternalReferenceRepositoryNormalizer($factory); - $externalReference = $this->createStub(ExternalReference::class); + $externalReference = $this->createMock(ExternalReference::class); $repo = $this->createConfiguredMock(ExternalReferenceRepository::class, [ 'count' => 1, 'getItems' => [$externalReference], ]); - $FakeExtRef = $this->createStub(DOMElement::class); + $FakeExtRef = $this->createMock(DOMElement::class); $externalReferenceNormalizer->expects(self::once()) ->method('normalize') @@ -95,15 +95,15 @@ public function testNormalize(): void #[DataProvider('dpNormalizeSkipsOnThrow')] public function testNormalizeSkipsOnThrow(string $exceptionClass): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $externalReferenceNormalizer = $this->createMock(ExternalReferenceNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForExternalReference' => $externalReferenceNormalizer, ]); $normalizer = new ExternalReferenceRepositoryNormalizer($factory); - $extRef1 = $this->createStub(ExternalReference::class); - $extRef2 = $this->createStub(ExternalReference::class); + $extRef1 = $this->createMock(ExternalReference::class); + $extRef2 = $this->createMock(ExternalReference::class); $tools = $this->createConfiguredMock(ExternalReferenceRepository::class, [ 'count' => 1, 'getItems' => [$extRef1, $extRef2], diff --git a/tests/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizerTest.php index b0ed9778..7cb6a99f 100644 --- a/tests/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizerTest.php @@ -47,7 +47,7 @@ public function testConstructor(): void { $factory = $this->createMock(NormalizerFactory::class); $normalizer = new HashDictionaryNormalizer($factory); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } public function testNormalize(): void @@ -60,10 +60,10 @@ public function testNormalize(): void 'getDocument' => new DOMDocument(), ] ); - $dummy1 = $this->createStub(DOMElement::class); - $dummy2 = $this->createStub(DOMElement::class); + $dummy1 = $this->createMock(DOMElement::class); + $dummy2 = $this->createMock(DOMElement::class); $normalizer = new HashDictionaryNormalizer($factory); - $repo = $this->createStub(HashDictionary::class); + $repo = $this->createMock(HashDictionary::class); $repo->method('getItems')->willReturn([[HashAlgorithm::MD5, 'content1'], [HashAlgorithm::SHA_1, 'content2']]); $hashNormalizer->expects(self::exactly(2)) diff --git a/tests/Core/Serialization/DOM/Normalizers/HashNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/HashNormalizerTest.php index 9b08ffa8..4d5c1293 100644 --- a/tests/Core/Serialization/DOM/Normalizers/HashNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/HashNormalizerTest.php @@ -43,7 +43,7 @@ public function testConstructor(): void { $factory = $this->createMock(NormalizerFactory::class); $normalizer = new HashNormalizer($factory); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } public function testNormalize(): void diff --git a/tests/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizerTest.php index 5093bdda..f89fd035 100644 --- a/tests/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizerTest.php @@ -43,7 +43,7 @@ class LicenseRepositoryNormalizerTest extends TestCase public function testNormalizeEmpty(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $licenseNormalizer = $this->createMock(LicenseNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, @@ -59,19 +59,19 @@ public function testNormalizeEmpty(): void public function testNormalize(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $licenseNormalizer = $this->createMock(LicenseNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForLicense' => $licenseNormalizer, ]); $normalizer = new LicenseRepositoryNormalizer($factory); - $license = $this->createStub(NamedLicense::class); + $license = $this->createMock(NamedLicense::class); $licenses = $this->createConfiguredMock(LicenseRepository::class, [ 'count' => 1, 'getItems' => [$license], ]); - $FakeLicense = $this->createStub(DOMElement::class); + $FakeLicense = $this->createMock(DOMElement::class); $licenseNormalizer->expects(self::once())->method('normalize') ->with($license) diff --git a/tests/Core/Serialization/DOM/Normalizers/MetadataNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/MetadataNormalizerTest.php index 7aaf95af..b2ca5b91 100644 --- a/tests/Core/Serialization/DOM/Normalizers/MetadataNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/MetadataNormalizerTest.php @@ -117,7 +117,7 @@ public function testNormalizeTools(): void $toolsRepoFactory->expects(self::once()) ->method('normalize') ->with($metadata->getTools()) - ->willReturn([$factory->getDocument()->createElement('FakeTool', 'dummy')]); + ->willReturn([$factory->document->createElement('FakeTool', 'dummy')]); $actual = $normalizer->normalize($metadata); @@ -151,7 +151,7 @@ public function testNormalizeComponent(): void ->method('normalize') ->with($metadata->getComponent()) ->willReturn( - $factory->getDocument()->createElement('FakeComponent', 'dummy')); + $factory->document->createElement('FakeComponent', 'dummy')); $actual = $normalizer->normalize($metadata); @@ -222,7 +222,7 @@ public function testNormalizeProperties(): void ->method('normalize') ->with($metadata->getProperties()) ->willReturn( - [$factory->getDocument()->createElement('FakeProperties', 'dummy')]); + [$factory->document->createElement('FakeProperties', 'dummy')]); $actual = $normalizer->normalize($metadata); diff --git a/tests/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizerTest.php index 79587ffa..85e12d3a 100644 --- a/tests/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizerTest.php @@ -47,7 +47,7 @@ class PropertyRepositoryNormalizerTest extends TestCase public function testNormalizeEmpty(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $propertyNormalizer = $this->createMock(PropertyNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, @@ -65,7 +65,7 @@ public function testNormalizeEmpty(): void public function testNormalize(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $propertyNormalizer = $this->createMock(PropertyNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, @@ -73,13 +73,13 @@ public function testNormalize(): void 'makeForProperty' => $propertyNormalizer, ]); $normalizer = new PropertyRepositoryNormalizer($factory); - $property = $this->createStub(Property::class); + $property = $this->createMock(Property::class); $properties = $this->createConfiguredMock(PropertyRepository::class, [ 'count' => 1, 'getItems' => [$property], ]); - $FakeProperty = $this->createStub(DOMElement::class); + $FakeProperty = $this->createMock(DOMElement::class); $propertyNormalizer->expects(self::once())->method('normalize') ->with($property) @@ -92,7 +92,7 @@ public function testNormalize(): void public function testNormalizeSkippedWhenThrown(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $propertyNormalizer = $this->createMock(PropertyNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, @@ -100,7 +100,7 @@ public function testNormalizeSkippedWhenThrown(): void 'makeForProperty' => $propertyNormalizer, ]); $normalizer = new PropertyRepositoryNormalizer($factory); - $property = $this->createStub(Property::class); + $property = $this->createMock(Property::class); $properties = $this->createConfiguredMock(PropertyRepository::class, [ 'count' => 1, 'getItems' => [$property], diff --git a/tests/Core/Serialization/DOM/Normalizers/ToolNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/ToolNormalizerTest.php index 1d4c49e0..af5994fb 100644 --- a/tests/Core/Serialization/DOM/Normalizers/ToolNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/ToolNormalizerTest.php @@ -98,11 +98,11 @@ public function testNormalizeFull(): void $HashDictNormalizer->expects(self::once()) ->method('normalize') ->with($tool->getHashes()) - ->willReturn([$factory->getDocument()->createElement('FakeHash', 'dummyHash')]); + ->willReturn([$factory->document->createElement('FakeHash', 'dummyHash')]); $extRefRepoNormalizer->expects(self::once()) ->method('normalize') ->with($tool->getExternalReferences()) - ->willReturn([$factory->getDocument()->createElement('FakeExtRefs', 'dummyRef')]); + ->willReturn([$factory->document->createElement('FakeExtRefs', 'dummyRef')]); $actual = $normalizer->normalize($tool); @@ -126,8 +126,8 @@ public function testNormalizeMinimal(): void 'getVendor' => null, 'getName' => null, 'getVersion' => null, - 'getHashes' => $this->createStub(HashDictionary::class), - 'getExternalReferences' => $this->createStub(ExternalReferenceRepository::class), + 'getHashes' => $this->createMock(HashDictionary::class), + 'getExternalReferences' => $this->createMock(ExternalReferenceRepository::class), ] ); $spec = $this->createConfiguredMock(Spec::class, [ diff --git a/tests/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizerTest.php b/tests/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizerTest.php index fd31836f..680e7124 100644 --- a/tests/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizerTest.php @@ -43,7 +43,7 @@ class ToolRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $toolNormalizer = $this->createMock(ToolNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, @@ -59,19 +59,19 @@ public function testNormalizeEmpty(): void public function testNormalize(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $toolNormalizer = $this->createMock(ToolNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForTool' => $toolNormalizer, ]); $normalizer = new ToolRepositoryNormalizer($factory); - $tool = $this->createStub(Tool::class); + $tool = $this->createMock(Tool::class); $tools = $this->createConfiguredMock(ToolRepository::class, [ 'count' => 1, 'getItems' => [$tool], ]); - $FakeTool = $this->createStub(DOMElement::class); + $FakeTool = $this->createMock(DOMElement::class); $toolNormalizer->expects(self::once())->method('normalize') ->with($tool) @@ -84,15 +84,15 @@ public function testNormalize(): void public function testNormalizeSkipsOnThrow(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $toolNormalizer = $this->createMock(ToolNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForTool' => $toolNormalizer, ]); $normalizer = new ToolRepositoryNormalizer($factory); - $tool1 = $this->createStub(Tool::class); - $tool2 = $this->createStub(Tool::class); + $tool1 = $this->createMock(Tool::class); + $tool2 = $this->createMock(Tool::class); $tools = $this->createConfiguredMock(ToolRepository::class, [ 'count' => 1, 'getItems' => [$tool1, $tool2], diff --git a/tests/Core/Serialization/JSON/NormalizerFactoryTest.php b/tests/Core/Serialization/JSON/NormalizerFactoryTest.php index 9ed7d43c..a936046f 100644 --- a/tests/Core/Serialization/JSON/NormalizerFactoryTest.php +++ b/tests/Core/Serialization/JSON/NormalizerFactoryTest.php @@ -63,7 +63,7 @@ public function testConstructor(): NormalizerFactory ); $factory = new NormalizerFactory($spec); - self::assertSame($spec, $factory->getSpec()); + self::assertSame($spec, $factory->spec); return $factory; } @@ -89,7 +89,7 @@ public function testMakeForComponentRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForComponentRepository(); self::assertInstanceOf(Normalizers\ComponentRepositoryNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -97,7 +97,7 @@ public function testMakeForBom(NormalizerFactory $factory): void { $normalizer = $factory->makeForBom(); self::assertInstanceOf(Normalizers\BomNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -105,7 +105,7 @@ public function testMakeForLicense(NormalizerFactory $factory): void { $normalizer = $factory->makeForLicense(); self::assertInstanceOf(Normalizers\LicenseNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -113,7 +113,7 @@ public function testMakeForLicenseRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForLicenseRepository(); self::assertInstanceOf(Normalizers\LicenseRepositoryNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -121,7 +121,7 @@ public function testMakeForHashDictionary(NormalizerFactory $factory): void { $normalizer = $factory->makeForHashDictionary(); self::assertInstanceOf(Normalizers\HashDictionaryNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -129,7 +129,7 @@ public function testMakeForComponent(NormalizerFactory $factory): void { $normalizer = $factory->makeForComponent(); self::assertInstanceOf(Normalizers\ComponentNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -137,7 +137,7 @@ public function testMakeForHash(NormalizerFactory $factory): void { $normalizer = $factory->makeForHash(); self::assertInstanceOf(Normalizers\HashNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -145,7 +145,7 @@ public function testMakeForMetadata(NormalizerFactory $factory): void { $normalizer = $factory->makeForMetadata(); self::assertInstanceOf(Normalizers\MetadataNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -153,7 +153,7 @@ public function testMakeForToolRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForToolRepository(); self::assertInstanceOf(Normalizers\ToolRepositoryNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -161,7 +161,7 @@ public function testMakeForTool(NormalizerFactory $factory): void { $normalizer = $factory->makeForTool(); self::assertInstanceOf(Normalizers\ToolNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -169,7 +169,7 @@ public function testMakeForDependencies(NormalizerFactory $factory): void { $normalizer = $factory->makeForDependencies(); self::assertInstanceOf(Normalizers\DependenciesNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -177,7 +177,7 @@ public function testMakeForExternalReference(NormalizerFactory $factory): void { $normalizer = $factory->makeForExternalReference(); self::assertInstanceOf(Normalizers\ExternalReferenceNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -185,7 +185,7 @@ public function testMakeForExternalReferenceRepository(NormalizerFactory $factor { $normalizer = $factory->makeForExternalReferenceRepository(); self::assertInstanceOf(Normalizers\ExternalReferenceRepositoryNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -193,7 +193,7 @@ public function testMakeForProperty(NormalizerFactory $factory): void { $normalizer = $factory->makeForProperty(); self::assertInstanceOf(Normalizers\PropertyNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -201,7 +201,7 @@ public function testMakeForPropertyRepository(NormalizerFactory $factory): void { $normalizer = $factory->makeForPropertyRepository(); self::assertInstanceOf(Normalizers\PropertyRepositoryNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } #[Depends('testConstructor')] @@ -209,6 +209,6 @@ public function testMakeForComponentEvidence(NormalizerFactory $factory): void { $normalizer = $factory->makeForComponentEvidence(); self::assertInstanceOf(Normalizers\ComponentEvidenceNormalizer::class, $normalizer); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } } diff --git a/tests/Core/Serialization/JSON/Normalizers/BomNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/BomNormalizerTest.php index ab13b149..446b33c0 100644 --- a/tests/Core/Serialization/JSON/Normalizers/BomNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/BomNormalizerTest.php @@ -98,7 +98,7 @@ public function testNormalizeComponents(): void Bom::class, [ 'getVersion' => 42, - 'getComponents' => $this->createStub(ComponentRepository::class), + 'getComponents' => $this->createMock(ComponentRepository::class), ] ); @@ -145,7 +145,7 @@ public function testNormalizeMetadata(): void Bom::class, [ 'getVersion' => 1337, - 'getMetadata' => $this->createStub(Metadata::class), + 'getMetadata' => $this->createMock(Metadata::class), ] ); @@ -191,7 +191,7 @@ public function testNormalizeMetadataEmpty(): void Bom::class, [ 'getVersion' => 1, - 'getMetadata' => $this->createStub(Metadata::class), + 'getMetadata' => $this->createMock(Metadata::class), ] ); @@ -235,7 +235,7 @@ public function testNormalizeMetadataSkipped(): void Bom::class, [ 'getVersion' => 1, - 'getMetadata' => $this->createStub(Metadata::class), + 'getMetadata' => $this->createMock(Metadata::class), ] ); @@ -283,7 +283,7 @@ public function testNormalizeDependencies(): void Bom::class, [ 'getVersion' => 1, - 'getMetadata' => $this->createStub(Metadata::class), + 'getMetadata' => $this->createMock(Metadata::class), ] ); @@ -329,7 +329,7 @@ public function testNormalizeDependenciesOmitWhenEmpty(): void Bom::class, [ 'getVersion' => 1, - 'getMetadata' => $this->createStub(Metadata::class), + 'getMetadata' => $this->createMock(Metadata::class), ] ); @@ -369,8 +369,8 @@ public function testNormalizeExternalReferencesMergedIfUnsupportedMetadata(): vo 'makeForExternalReferenceRepository' => $extRefNormalizer, ]); $normalizer = new Normalizers\BomNormalizer($factory); - $extRef1 = $this->createStub(ExternalReference::class); - $extRef2 = $this->createStub(ExternalReference::class); + $extRef1 = $this->createMock(ExternalReference::class); + $extRef2 = $this->createMock(ExternalReference::class); $bom = $this->createConfiguredMock( Bom::class, [ @@ -425,8 +425,8 @@ public function testNormalizeExternalReferencesOmittedWHenEmpty(): void 'makeForExternalReferenceRepository' => $extRefNormalizer, ]); $normalizer = new Normalizers\BomNormalizer($factory); - $extRef1 = $this->createStub(ExternalReference::class); - $extRef2 = $this->createStub(ExternalReference::class); + $extRef1 = $this->createMock(ExternalReference::class); + $extRef2 = $this->createMock(ExternalReference::class); $bom = $this->createConfiguredMock( Bom::class, [ diff --git a/tests/Core/Serialization/JSON/Normalizers/ComponentNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/ComponentNormalizerTest.php index 1ff6b326..00e77d26 100644 --- a/tests/Core/Serialization/JSON/Normalizers/ComponentNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/ComponentNormalizerTest.php @@ -84,8 +84,8 @@ public function testNormalizeMinimal(array $expected, bool $requiresComponentVer 'getGroup' => null, 'getDescription' => null, 'getAuthor' => null, - 'getLicenses' => $this->createStub(LicenseRepository::class), - 'getHashes' => $this->createStub(HashDictionary::class), + 'getLicenses' => $this->createMock(LicenseRepository::class), + 'getHashes' => $this->createMock(HashDictionary::class), 'getPackageUrl' => null, ] ); diff --git a/tests/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizerTest.php index 48d3971a..ff959b95 100644 --- a/tests/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizerTest.php @@ -40,8 +40,8 @@ class ComponentRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void { - $spec = $this->createStub(Spec::class); - $factory = $this->createConfiguredMock(NormalizerFactory::class, ['getSpec' => $spec]); + $spec = $this->createMock(Spec::class); + $factory = $this->createdMockOC(NormalizerFactory::class, ['spec' => $spec]); $normalizer = new ComponentRepositoryNormalizer($factory); $components = $this->createConfiguredMock(ComponentRepository::class, ['count' => 0]); @@ -52,14 +52,14 @@ public function testNormalizeEmpty(): void public function testNormalize(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $componentNormalizer = $this->createMock(ComponentNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForComponent' => $componentNormalizer, ]); $normalizer = new ComponentRepositoryNormalizer($factory); - $component = $this->createStub(Component::class); + $component = $this->createMock(Component::class); $components = $this->createConfiguredMock(ComponentRepository::class, [ 'count' => 1, 'getItems' => [$component], @@ -76,15 +76,15 @@ public function testNormalize(): void public function testNormalizeSkipsOnThrow(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $componentNormalizer = $this->createMock(ComponentNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForComponent' => $componentNormalizer, ]); $normalizer = new ComponentRepositoryNormalizer($factory); - $component1 = $this->createStub(Component::class); - $component2 = $this->createStub(Component::class); + $component1 = $this->createMock(Component::class); + $component2 = $this->createMock(Component::class); $components = $this->createConfiguredMock(ComponentRepository::class, [ 'count' => 1, 'getItems' => [$component1, $component2], diff --git a/tests/Core/Serialization/JSON/Normalizers/DependenciesNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/DependenciesNormalizerTest.php index 7ef03bd5..b13343de 100644 --- a/tests/Core/Serialization/JSON/Normalizers/DependenciesNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/DependenciesNormalizerTest.php @@ -95,7 +95,7 @@ public function testNormalize(Bom $bom, array $expecteds): void public function dpNormalize(): Generator { - $dependencies = $this->createStub(BomRefRepository::class); + $dependencies = $this->createMock(BomRefRepository::class); $componentWithoutBomRefValue = $this->createConfiguredMock( Component::class, diff --git a/tests/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizerTest.php index 1dc17d41..be338ac2 100644 --- a/tests/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizerTest.php @@ -44,7 +44,7 @@ class ExternalReferenceRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $externalReferenceNormalizer = $this->createMock(ExternalReferenceNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, @@ -61,14 +61,14 @@ public function testNormalizeEmpty(): void public function testNormalize(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $externalReferenceNormalizer = $this->createMock(ExternalReferenceNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForExternalReference' => $externalReferenceNormalizer, ]); $normalizer = new ExternalReferenceRepositoryNormalizer($factory); - $externalReference = $this->createStub(ExternalReference::class); + $externalReference = $this->createMock(ExternalReference::class); $repo = $this->createConfiguredMock(ExternalReferenceRepository::class, [ 'count' => 1, 'getItems' => [$externalReference], @@ -86,15 +86,15 @@ public function testNormalize(): void public function testNormalizeSkipsOnThrow(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $externalReferenceNormalizer = $this->createMock(ExternalReferenceNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForExternalReference' => $externalReferenceNormalizer, ]); $normalizer = new ExternalReferenceRepositoryNormalizer($factory); - $extRef1 = $this->createStub(ExternalReference::class); - $extRef2 = $this->createStub(ExternalReference::class); + $extRef1 = $this->createMock(ExternalReference::class); + $extRef2 = $this->createMock(ExternalReference::class); $tools = $this->createConfiguredMock(ExternalReferenceRepository::class, [ 'count' => 1, 'getItems' => [$extRef1, $extRef2], diff --git a/tests/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizerTest.php index 72bafe75..8eb9a1bb 100644 --- a/tests/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizerTest.php @@ -41,7 +41,7 @@ public function testConstructor(): void { $factory = $this->createMock(NormalizerFactory::class); $normalizer = new HashDictionaryNormalizer($factory); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } public function testNormalize(): void @@ -49,7 +49,7 @@ public function testNormalize(): void $hashNormalizer = $this->createMock(HashNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, ['makeForHash' => $hashNormalizer]); $normalizer = new HashDictionaryNormalizer($factory); - $repo = $this->createStub(HashDictionary::class); + $repo = $this->createMock(HashDictionary::class); $repo->method('getItems')->willReturn([[HashAlgorithm::MD5, 'content1'], [HashAlgorithm::SHA_1, 'content2']]); $hashNormalizer->expects(self::exactly(2)) diff --git a/tests/Core/Serialization/JSON/Normalizers/HashNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/HashNormalizerTest.php index 2f91156b..2a51aedb 100644 --- a/tests/Core/Serialization/JSON/Normalizers/HashNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/HashNormalizerTest.php @@ -40,7 +40,7 @@ public function testConstructor(): void { $factory = $this->createMock(NormalizerFactory::class); $normalizer = new HashNormalizer($factory); - self::assertSame($factory, $normalizer->getNormalizerFactory()); + self::assertSame($factory, $normalizer->normalizerFactory); } public function testNormalize(): void diff --git a/tests/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizerTest.php index c6becff0..04940d3d 100644 --- a/tests/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizerTest.php @@ -39,7 +39,7 @@ class LicenseRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $licenseNormalizer = $this->createMock(LicenseNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, @@ -55,14 +55,14 @@ public function testNormalizeEmpty(): void public function testNormalize(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $licenseNormalizer = $this->createMock(LicenseNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForLicense' => $licenseNormalizer, ]); $normalizer = new LicenseRepositoryNormalizer($factory); - $license = $this->createStub(NamedLicense::class); + $license = $this->createMock(NamedLicense::class); $licenses = $this->createConfiguredMock(LicenseRepository::class, [ 'count' => 1, 'getItems' => [$license], diff --git a/tests/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizerTest.php index 4bfa6848..152360c5 100644 --- a/tests/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizerTest.php @@ -42,7 +42,7 @@ class PropertyRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $propertyNormalizer = $this->createMock(PropertyNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, @@ -59,14 +59,14 @@ public function testNormalizeEmpty(): void public function testNormalize(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(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); + $property = $this->createMock(Property::class); $properties = $this->createConfiguredMock(PropertyRepository::class, [ 'count' => 1, 'getItems' => [$property], @@ -83,14 +83,14 @@ public function testNormalize(): void public function testNormalizeSkipWHenThrown(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(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); + $property = $this->createMock(Property::class); $properties = $this->createConfiguredMock(PropertyRepository::class, [ 'count' => 1, 'getItems' => [$property], diff --git a/tests/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizerTest.php b/tests/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizerTest.php index 8dd99798..c2369321 100644 --- a/tests/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizerTest.php +++ b/tests/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizerTest.php @@ -42,7 +42,7 @@ class ToolRepositoryNormalizerTest extends TestCase { public function testNormalizeEmpty(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $toolNormalizer = $this->createMock(ToolNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, @@ -59,14 +59,14 @@ public function testNormalizeEmpty(): void public function testNormalize(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $toolNormalizer = $this->createMock(ToolNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForTool' => $toolNormalizer, ]); $normalizer = new ToolRepositoryNormalizer($factory); - $tool = $this->createStub(Tool::class); + $tool = $this->createMock(Tool::class); $tools = $this->createConfiguredMock(ToolRepository::class, [ 'count' => 1, 'getItems' => [$tool], @@ -83,15 +83,15 @@ public function testNormalize(): void public function testNormalizeSkipsOnThrow(): void { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $toolNormalizer = $this->createMock(ToolNormalizer::class); $factory = $this->createConfiguredMock(NormalizerFactory::class, [ 'getSpec' => $spec, 'makeForTool' => $toolNormalizer, ]); $normalizer = new ToolRepositoryNormalizer($factory); - $tool1 = $this->createStub(Tool::class); - $tool2 = $this->createStub(Tool::class); + $tool1 = $this->createMock(Tool::class); + $tool2 = $this->createMock(Tool::class); $tools = $this->createConfiguredMock(ToolRepository::class, [ 'count' => 1, 'getItems' => [$tool1, $tool2], diff --git a/tests/Core/Serialization/JsonSerializerTest.php b/tests/Core/Serialization/JsonSerializerTest.php index d746b579..8ef8ddc3 100644 --- a/tests/Core/Serialization/JsonSerializerTest.php +++ b/tests/Core/Serialization/JsonSerializerTest.php @@ -42,7 +42,7 @@ class JsonSerializerTest extends TestCase #[DataProvider('dpSerializeStructure')] public function testSerialize(int $jsonEncodeFlags, ?bool $prettyPrint, array $normalized, string $expected): void { - $bom = $this->createStub(Bom::class); + $bom = $this->createMock(Bom::class); $bomNormalizer = $this->createMock(JSON\Normalizers\BomNormalizer::class); $normalizerFactory = $this->createConfiguredMock(JSON\NormalizerFactory::class, [ 'makeForBom' => $bomNormalizer, diff --git a/tests/Core/Serialization/XmlSerializerTest.php b/tests/Core/Serialization/XmlSerializerTest.php index 3698107f..5009619d 100644 --- a/tests/Core/Serialization/XmlSerializerTest.php +++ b/tests/Core/Serialization/XmlSerializerTest.php @@ -44,7 +44,7 @@ class XmlSerializerTest extends TestCase #[DataProvider('dpSerializeStructure')] public function testSerialize(string $xmlVersion, string $xmlEncoding, ?bool $prettyPrint, DOMElement $normalized, string $expected): void { - $bom = $this->createStub(Bom::class); + $bom = $this->createMock(Bom::class); $bomNormalizer = $this->createMock(DOM\Normalizers\BomNormalizer::class); $normalizerFactory = $this->createConfiguredMock(DOM\NormalizerFactory::class, [ 'makeForBom' => $bomNormalizer, diff --git a/tests/Core/Validation/Validators/JsonStrictValidatorTest.php b/tests/Core/Validation/Validators/JsonStrictValidatorTest.php index d088d6bc..5319b862 100644 --- a/tests/Core/Validation/Validators/JsonStrictValidatorTest.php +++ b/tests/Core/Validation/Validators/JsonStrictValidatorTest.php @@ -47,9 +47,9 @@ class JsonStrictValidatorTest extends TestCase { public function testConstructor(): JsonStrictValidator { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $validator = new JsonStrictValidator($spec); - self::assertSame($spec, $validator->getSpec()); + self::assertSame($spec, $validator->spec); return $validator; } @@ -72,7 +72,7 @@ public function testValidateStringError(): void { $validator = $this->createPartialMock(JsonStrictValidator::class, ['validateData']); $json = '{"dummy": "true"}'; - $expectedError = $this->createStub(JsonValidationError::class); + $expectedError = $this->createMock(JsonValidationError::class); $validator->expects(self::once())->method('validateData') ->with(new IsInstanceOf(stdClass::class)) diff --git a/tests/Core/Validation/Validators/JsonValidatorTest.php b/tests/Core/Validation/Validators/JsonValidatorTest.php index d1d8350a..57da95fd 100644 --- a/tests/Core/Validation/Validators/JsonValidatorTest.php +++ b/tests/Core/Validation/Validators/JsonValidatorTest.php @@ -45,9 +45,9 @@ class JsonValidatorTest extends TestCase { public function testConstructor(): JsonValidator { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $validator = new JsonValidator($spec); - self::assertSame($spec, $validator->getSpec()); + self::assertSame($spec, $validator->spec); return $validator; } @@ -71,7 +71,7 @@ public function testValidateStringError(): void { $validator = $this->createPartialMock(JsonValidator::class, ['validateData']); $json = '{"dummy": "true"}'; - $expectedError = $this->createStub(JsonValidationError::class); + $expectedError = $this->createMock(JsonValidationError::class); $validator->expects(self::once())->method('validateData') ->with(new IsInstanceOf(stdClass::class)) diff --git a/tests/Core/Validation/Validators/XmlValidatorTest.php b/tests/Core/Validation/Validators/XmlValidatorTest.php index 1a34733d..83383edf 100644 --- a/tests/Core/Validation/Validators/XmlValidatorTest.php +++ b/tests/Core/Validation/Validators/XmlValidatorTest.php @@ -45,9 +45,9 @@ class XmlValidatorTest extends TestCase { public function testConstructor(): XmlValidator { - $spec = $this->createStub(Spec::class); + $spec = $this->createMock(Spec::class); $validator = new XmlValidator($spec); - self::assertSame($spec, $validator->getSpec()); + self::assertSame($spec, $validator->spec); return $validator; } @@ -70,7 +70,7 @@ public function testValidateStringError(): void { $validator = $this->createPartialMock(XmlValidator::class, ['validateDom']); $xml = ''; - $expectedError = $this->createStub(XmlValidationError::class); + $expectedError = $this->createMock(XmlValidationError::class); $validator->expects(self::once())->method('validateDom') ->with(new IsInstanceOf(DOMDocument::class)) diff --git a/tests/_traits/MockOCTrait.php b/tests/_traits/MockOCTrait.php new file mode 100644 index 00000000..3ee87c65 --- /dev/null +++ b/tests/_traits/MockOCTrait.php @@ -0,0 +1,95 @@ + $originalClassName + * + * @psalm-return MockObject&RealInstanceType + * + * @throws \PHPUnit\Framework\MockObject\Exception + * @throws InvalidArgumentException + * @throws NoPreviousThrowableException + */ + private function createMockObjectOC(string $originalClassName, array $constructorArgs, bool $register = true): MockObject + { + /* @var \PHPUnit\Framework\TestCase $this */ + return $this->getMockBuilder($originalClassName) + ->enableOriginalConstructor() + ->setConstructorArgs($constructorArgs) + ->disableOriginalClone() + ->disableArgumentCloning() + ->disallowMockingUnknownTypes() + ->getMock($register); + } + + /** + * @psalm-template RealInstanceType of object + * + * @psalm-param class-string $originalClassName + * + * @psalm-return MockObject&RealInstanceType + * + * @throws \PHPUnit\Framework\MockObject\Exception + * @throws InvalidArgumentException + * @throws NoPreviousThrowableException + */ + protected function createMockOC(string $originalClassName, array $constructorArgs): MockObject + { + return $this->createConfiguredMockOC($originalClassName, $constructorArgs, []); + } + + /** + * @psalm-template RealInstanceType of object + * + * @psalm-param class-string $originalClassName + * + * @psalm-return MockObject&RealInstanceType + * + * @throws \PHPUnit\Framework\MockObject\Exception + * @throws InvalidArgumentException + * @throws NoPreviousThrowableException + */ + protected function createConfiguredMockOC(string $originalClassName, array $constructorArgs, array $configuration): MockObject + { + $o = $this->createMockObjectOC($originalClassName, $constructorArgs); + + foreach ($configuration as $method => $return) { + $o->method($method)->willReturn($return); + } + + return $o; + } +}