Skip to content

Commit

Permalink
some test reworks
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <[email protected]>
  • Loading branch information
jkowalleck committed Mar 10, 2023
1 parent 00de098 commit 62d145b
Show file tree
Hide file tree
Showing 46 changed files with 396 additions and 301 deletions.
9 changes: 4 additions & 5 deletions src/Core/Serialization/DOM/NormalizerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions tests/Core/Collections/ComponentRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions tests/Core/Collections/ExternalReferenceRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions tests/Core/Collections/LicenseRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions tests/Core/Collections/PropertyRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions tests/Core/Collections/ToolRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions tests/Core/Factories/LicenseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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());
Expand All @@ -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());
Expand Down
8 changes: 4 additions & 4 deletions tests/Core/Models/BomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions tests/Core/Models/ComponentEvidenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down
12 changes: 6 additions & 6 deletions tests/Core/Models/ComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion tests/Core/Models/ExternalReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions tests/Core/Models/MetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/Core/Models/ToolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 62d145b

Please sign in to comment.