diff --git a/src/Core/Serialization/DOM/NormalizerFactory.php b/src/Core/Serialization/DOM/NormalizerFactory.php
index b0a965aa..925f02fd 100644
--- a/src/Core/Serialization/DOM/NormalizerFactory.php
+++ b/src/Core/Serialization/DOM/NormalizerFactory.php
@@ -40,17 +40,16 @@ class NormalizerFactory
public readonly Spec $spec;
- public readonly DOMDocument $document;
-
/**
* @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"
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;
+ }
+}