Skip to content

Commit ef95580

Browse files
committed
some test reworks
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 8daaed6 commit ef95580

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+396
-301
lines changed

src/Core/Serialization/DOM/NormalizerFactory.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@ class NormalizerFactory
4040

4141
public readonly Spec $spec;
4242

43-
public readonly DOMDocument $document;
44-
4543
/**
4644
* @throws DomainException when the spec does not support XML format
4745
*/
48-
public function __construct(Spec $spec)
49-
{
46+
public function __construct(
47+
Spec $spec,
48+
public readonly DOMDocument $document = new DOMDocument()
49+
) {
5050
$this->spec = $spec->isSupportedFormat(self::FORMAT)
5151
? $spec
5252
: throw new DomainException('Unsupported format "'.self::FORMAT->name.'" for spec '.$spec->getVersion()->name);
53-
$this->document = new DOMDocument();
5453
}
5554

5655
// intention: all factory methods return an instance of "_BaseNormalizer"

tests/Core/Collections/ComponentRepositoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public function testEmptyConstructor(): void
4343

4444
public function testConstructor(): void
4545
{
46-
$component1 = $this->createStub(Component::class);
47-
$component2 = $this->createStub(Component::class);
46+
$component1 = $this->createMock(Component::class);
47+
$component2 = $this->createMock(Component::class);
4848

4949
$repo = new ComponentRepository($component1, $component2, $component1, $component2);
5050

@@ -56,9 +56,9 @@ public function testConstructor(): void
5656

5757
public function testAddAndGetItems(): void
5858
{
59-
$component1 = $this->createStub(Component::class);
60-
$component2 = $this->createStub(Component::class);
61-
$component3 = $this->createStub(Component::class);
59+
$component1 = $this->createMock(Component::class);
60+
$component2 = $this->createMock(Component::class);
61+
$component3 = $this->createMock(Component::class);
6262
$repo = new ComponentRepository($component1, $component3);
6363

6464
$actual = $repo->addItems($component2, $component3, $component2);

tests/Core/Collections/ExternalReferenceRepositoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function testEmptyConstructor(): void
4141

4242
public function testConstructAndGet(): void
4343
{
44-
$externalReference1 = $this->createStub(ExternalReference::class);
45-
$externalReference2 = $this->createStub(ExternalReference::class);
44+
$externalReference1 = $this->createMock(ExternalReference::class);
45+
$externalReference2 = $this->createMock(ExternalReference::class);
4646

4747
$repo = new ExternalReferenceRepository(
4848
$externalReference1,
@@ -59,9 +59,9 @@ public function testConstructAndGet(): void
5959

6060
public function testAddAndGetItems(): void
6161
{
62-
$externalReference1 = $this->createStub(ExternalReference::class);
63-
$externalReference2 = $this->createStub(ExternalReference::class);
64-
$externalReference3 = $this->createStub(ExternalReference::class);
62+
$externalReference1 = $this->createMock(ExternalReference::class);
63+
$externalReference2 = $this->createMock(ExternalReference::class);
64+
$externalReference3 = $this->createMock(ExternalReference::class);
6565
$repo = new ExternalReferenceRepository($externalReference1, $externalReference2);
6666

6767
$actual = $repo->addItems($externalReference2, $externalReference3, $externalReference3);

tests/Core/Collections/LicenseRepositoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public function testEmptyConstructor(): void
4242

4343
public function testNonEmptyConstruct(): void
4444
{
45-
$license1 = $this->createStub(SpdxLicense::class);
46-
$license2 = $this->createStub(NamedLicense::class);
45+
$license1 = $this->createMock(SpdxLicense::class);
46+
$license2 = $this->createMock(NamedLicense::class);
4747

4848
$repo = new LicenseRepository($license1, $license2, $license1, $license2);
4949

@@ -55,9 +55,9 @@ public function testNonEmptyConstruct(): void
5555

5656
public function testAddAndGetItems(): void
5757
{
58-
$license1 = $this->createStub(NamedLicense::class);
59-
$license2 = $this->createStub(SpdxLicense::class);
60-
$license3 = $this->createStub(NamedLicense::class);
58+
$license1 = $this->createMock(NamedLicense::class);
59+
$license2 = $this->createMock(SpdxLicense::class);
60+
$license3 = $this->createMock(NamedLicense::class);
6161
$repo = new LicenseRepository($license1, $license2);
6262

6363
$actual = $repo->addItems($license2, $license3, $license3);

tests/Core/Collections/PropertyRepositoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function testEmptyConstructor(): void
4141

4242
public function testConstructAndGet(): void
4343
{
44-
$property1 = $this->createStub(Property::class);
45-
$property2 = $this->createStub(Property::class);
44+
$property1 = $this->createMock(Property::class);
45+
$property2 = $this->createMock(Property::class);
4646

4747
$repo = new PropertyRepository($property1, $property2, $property1, $property2);
4848

@@ -54,9 +54,9 @@ public function testConstructAndGet(): void
5454

5555
public function testAddAndGetItems(): void
5656
{
57-
$property1 = $this->createStub(Property::class);
58-
$property2 = $this->createStub(Property::class);
59-
$property3 = $this->createStub(Property::class);
57+
$property1 = $this->createMock(Property::class);
58+
$property2 = $this->createMock(Property::class);
59+
$property3 = $this->createMock(Property::class);
6060
$repo = new PropertyRepository($property1, $property2);
6161

6262
$actual = $repo->addItems($property2, $property3, $property3);

tests/Core/Collections/ToolRepositoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function testEmptyConstructor(): void
4141

4242
public function testConstructAndGet(): void
4343
{
44-
$tool1 = $this->createStub(Tool::class);
45-
$tool2 = $this->createStub(Tool::class);
44+
$tool1 = $this->createMock(Tool::class);
45+
$tool2 = $this->createMock(Tool::class);
4646

4747
$repo = new ToolRepository($tool1, $tool2, $tool1, $tool2);
4848

@@ -54,9 +54,9 @@ public function testConstructAndGet(): void
5454

5555
public function testAddAndGetItems(): void
5656
{
57-
$tool1 = $this->createStub(Tool::class);
58-
$tool2 = $this->createStub(Tool::class);
59-
$tool3 = $this->createStub(Tool::class);
57+
$tool1 = $this->createMock(Tool::class);
58+
$tool2 = $this->createMock(Tool::class);
59+
$tool3 = $this->createMock(Tool::class);
6060
$repo = new ToolRepository($tool1, $tool2);
6161

6262
$actual = $repo->addItems($tool2, $tool3, $tool3);

tests/Core/Factories/LicenseFactoryTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ protected function tearDown(): void
6767

6868
public function testConstructorWithArgs(): void
6969
{
70-
$licenseIdentifiers = $this->createStub(LicenseIdentifiers::class);
71-
$spdxLicenses = $this->createStub(SpdxLicenses::class);
70+
$licenseIdentifiers = $this->createMock(LicenseIdentifiers::class);
71+
$spdxLicenses = $this->createMock(SpdxLicenses::class);
7272
$factory = new LicenseFactory($licenseIdentifiers, $spdxLicenses);
73-
self::assertSame($licenseIdentifiers, $factory->getLicenseIdentifiers());
74-
self::assertSame($spdxLicenses, $factory->getSpdxLicenses());
73+
self::assertSame($licenseIdentifiers, $factory->licenseIdentifiers);
74+
self::assertSame($spdxLicenses, $factory->spdxLicenses);
7575
}
7676

7777
public function testMakeNamedLicense(): void
@@ -163,7 +163,7 @@ public function testMakeExpressionInvalidArgumentThrows(): void
163163
public function testMakeDisjunctiveSpdxLicense(): void
164164
{
165165
$license = uniqid('license', true);
166-
$expected = $this->createStub(SpdxLicense::class);
166+
$expected = $this->createMock(SpdxLicense::class);
167167
$factory = $this->createPartialMock(LicenseFactory::class, ['makeSpdxLicense']);
168168
$factory->method('makeSpdxLicense')
169169
->with($license)->willReturn($expected);
@@ -174,7 +174,7 @@ public function testMakeDisjunctiveSpdxLicense(): void
174174
public function testMakeDisjunctiveNamedLicense(): void
175175
{
176176
$license = uniqid('license', true);
177-
$expected = $this->createStub(NamedLicense::class);
177+
$expected = $this->createMock(NamedLicense::class);
178178
$factory = $this->createPartialMock(LicenseFactory::class, ['makeSpdxLicense', 'makeNamedLicense']);
179179
$factory->method('makeSpdxLicense')
180180
->with($license)->willThrowException(new DomainException());
@@ -191,7 +191,7 @@ public function testMakeDisjunctiveNamedLicense(): void
191191
public function testMakeFromStringSpdxLicense(): void
192192
{
193193
$license = uniqid('license', true);
194-
$expected = $this->createStub(SpdxLicense::class);
194+
$expected = $this->createMock(SpdxLicense::class);
195195
$factory = $this->createPartialMock(LicenseFactory::class, ['makeSpdxLicense']);
196196
$factory->method('makeSpdxLicense')
197197
->with($license)->willReturn($expected);
@@ -202,7 +202,7 @@ public function testMakeFromStringSpdxLicense(): void
202202
public function testMakeFromStringLicenseExpression(): void
203203
{
204204
$license = uniqid('license', true);
205-
$expected = $this->createStub(LicenseExpression::class);
205+
$expected = $this->createMock(LicenseExpression::class);
206206
$factory = $this->createPartialMock(LicenseFactory::class, ['makeSpdxLicense', 'makeExpression']);
207207
$factory->method('makeSpdxLicense')
208208
->with($license)->willThrowException(new DomainException());
@@ -215,7 +215,7 @@ public function testMakeFromStringLicenseExpression(): void
215215
public function testMakeFromStringNamedLicense(): void
216216
{
217217
$license = uniqid('license', true);
218-
$expected = $this->createStub(NamedLicense::class);
218+
$expected = $this->createMock(NamedLicense::class);
219219
$factory = $this->createPartialMock(LicenseFactory::class, ['makeSpdxLicense', 'makeExpression', 'makeNamedLicense']);
220220
$factory->method('makeSpdxLicense')
221221
->with($license)->willThrowException(new DomainException());

tests/Core/Models/BomTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function testSerialNumberEmptyStringInvalidValue(Bom $bom): void
9595
#[DependsUsingShallowClone('testConstruct')]
9696
public function testComponentsSetterGetter(Bom $bom): void
9797
{
98-
$components = $this->createStub(ComponentRepository::class);
98+
$components = $this->createMock(ComponentRepository::class);
9999
$actual = $bom->setComponents($components);
100100
self::assertSame($bom, $actual);
101101
self::assertSame($components, $bom->getComponents());
@@ -129,7 +129,7 @@ public function testVersionSetterInvalidValue(Bom $bom): void
129129
#[DependsUsingShallowClone('testConstruct')]
130130
public function testMetadataSetterGetter(Bom $bom): void
131131
{
132-
$metadata = $this->createStub(Metadata::class);
132+
$metadata = $this->createMock(Metadata::class);
133133
$actual = $bom->setMetadata($metadata);
134134
self::assertSame($bom, $actual);
135135
self::assertSame($metadata, $bom->getMetadata());
@@ -142,7 +142,7 @@ public function testMetadataSetterGetter(Bom $bom): void
142142
#[DependsUsingShallowClone('testConstruct')]
143143
public function testExternalReferenceRepositorySetterGetter(Bom $bom): void
144144
{
145-
$extRefRepo = $this->createStub(ExternalReferenceRepository::class);
145+
$extRefRepo = $this->createMock(ExternalReferenceRepository::class);
146146
$actual = $bom->setExternalReferences($extRefRepo);
147147
self::assertSame($bom, $actual);
148148
self::assertSame($extRefRepo, $bom->getExternalReferences());
@@ -155,7 +155,7 @@ public function testExternalReferenceRepositorySetterGetter(Bom $bom): void
155155
#[DependsUsingShallowClone('testConstruct')]
156156
public function testPropertiesSetterGetter(Bom $bom): void
157157
{
158-
$repo = $this->createStub(PropertyRepository::class);
158+
$repo = $this->createMock(PropertyRepository::class);
159159
$actual = $bom->setProperties($repo);
160160
self::assertSame($bom, $actual);
161161
self::assertSame($repo, $bom->getProperties());

tests/Core/Models/ComponentEvidenceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testConstructor(): ComponentEvidence
4949
#[DependsUsingShallowClone('testConstructor')]
5050
public function testLicensesSetterGetter(ComponentEvidence $evidence): void
5151
{
52-
$licenses = $this->createStub(LicenseRepository::class);
52+
$licenses = $this->createMock(LicenseRepository::class);
5353
$actual = $evidence->setLicenses($licenses);
5454
self::assertSame($evidence, $actual);
5555
self::assertSame($licenses, $evidence->getLicenses());
@@ -58,7 +58,7 @@ public function testLicensesSetterGetter(ComponentEvidence $evidence): void
5858
#[DependsUsingShallowClone('testConstructor')]
5959
public function testCopyrightSetterGetter(ComponentEvidence $evidence): void
6060
{
61-
$copyright = $this->createStub(CopyrightRepository::class);
61+
$copyright = $this->createMock(CopyrightRepository::class);
6262
$actual = $evidence->setCopyright($copyright);
6363
self::assertSame($evidence, $actual);
6464
self::assertSame($copyright, $evidence->getCopyright());

tests/Core/Models/ComponentTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testVersionSetterGetter(Component $component): void
118118
#[DependsUsingShallowClone('testConstructor')]
119119
public function testLicensesSetterGetter(Component $component): void
120120
{
121-
$licenses = $this->createStub(LicenseRepository::class);
121+
$licenses = $this->createMock(LicenseRepository::class);
122122
self::assertnotSame($licenses, $component->getLicenses());
123123
$actual = $component->setLicenses($licenses);
124124
self::assertSame($component, $actual);
@@ -132,7 +132,7 @@ public function testLicensesSetterGetter(Component $component): void
132132
#[DependsUsingShallowClone('testConstructor')]
133133
public function testHashesSetterGetter(Component $component): void
134134
{
135-
$hashes = $this->createStub(HashDictionary::class);
135+
$hashes = $this->createMock(HashDictionary::class);
136136
self::assertnotSame($hashes, $component->getHashes());
137137
$actual = $component->setHashes($hashes);
138138
self::assertSame($component, $actual);
@@ -237,7 +237,7 @@ public function testDependenciesBomRefRepositorySetterGetter(Component $componen
237237
#[DependsUsingShallowClone('testConstructor')]
238238
public function testExternalReferenceRepositorySetterGetter(Component $component): void
239239
{
240-
$extRefRepo = $this->createStub(ExternalReferenceRepository::class);
240+
$extRefRepo = $this->createMock(ExternalReferenceRepository::class);
241241
self::assertNotSame($extRefRepo, $component->getExternalReferences());
242242
$actual = $component->setExternalReferences($extRefRepo);
243243
self::assertSame($component, $actual);
@@ -251,7 +251,7 @@ public function testExternalReferenceRepositorySetterGetter(Component $component
251251
#[DependsUsingShallowClone('testConstructor')]
252252
public function testGetterSetterProperties(Component $component): void
253253
{
254-
$properties = $this->createStub(PropertyRepository::class);
254+
$properties = $this->createMock(PropertyRepository::class);
255255
self::assertNotSame($properties, $component->getProperties());
256256
$actual = $component->setProperties($properties);
257257
self::assertSame($component, $actual);
@@ -300,7 +300,7 @@ public static function dpCopyrightSetterGetter(): Generator
300300
#[DependsUsingShallowClone('testConstructor')]
301301
public function testEvidenceSetterGetter(Component $component): void
302302
{
303-
$evidence = $this->createStub(ComponentEvidence::class);
303+
$evidence = $this->createMock(ComponentEvidence::class);
304304
$actual = $component->setEvidence($evidence);
305305
self::assertSame($component, $actual);
306306
self::assertSame($evidence, $component->getEvidence());
@@ -309,7 +309,7 @@ public function testEvidenceSetterGetter(Component $component): void
309309
#[DependsUsingShallowClone('testConstructor')]
310310
public function testEvidenceSetterGetterNull(Component $component): void
311311
{
312-
$component->setEvidence($this->createStub(ComponentEvidence::class));
312+
$component->setEvidence($this->createMock(ComponentEvidence::class));
313313
self::assertNotNull($component->getEvidence());
314314
$component->setEvidence(null);
315315
self::assertNull($component->getEvidence());

tests/Core/Models/ExternalReferenceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function testCommentSetterAndGetter(ExternalReference $extRef): void
100100
#[DependsUsingShallowClone('testConstructor')]
101101
public function testHashesSetterAndGetter(ExternalReference $extRef): void
102102
{
103-
$hashes = $this->createStub(HashDictionary::class);
103+
$hashes = $this->createMock(HashDictionary::class);
104104
$this->assertNotSame($hashes, $extRef->getHashes());
105105
$got = $extRef->setHashes($hashes);
106106
$this->assertSame($extRef, $got);

tests/Core/Models/MetadataTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testConstructor(): Metadata
5353
#[DependsUsingShallowClone('testConstructor')]
5454
public function testGetterSetterTimestamp(Metadata $metadata): void
5555
{
56-
$timestamp = $this->createStub(DateTime::class);
56+
$timestamp = $this->createMock(DateTime::class);
5757
self::assertNotSame($timestamp, $metadata->getTimestamp());
5858
$actual = $metadata->setTimestamp($timestamp);
5959
self::assertSame($actual, $metadata);
@@ -63,7 +63,7 @@ public function testGetterSetterTimestamp(Metadata $metadata): void
6363
#[DependsUsingShallowClone('testConstructor')]
6464
public function testGetterSetterTools(Metadata $metadata): void
6565
{
66-
$tools = $this->createStub(ToolRepository::class);
66+
$tools = $this->createMock(ToolRepository::class);
6767
$actual = $metadata->setTools($tools);
6868
self::assertSame($actual, $metadata);
6969
self::assertSame($tools, $metadata->getTools());
@@ -72,7 +72,7 @@ public function testGetterSetterTools(Metadata $metadata): void
7272
#[DependsUsingShallowClone('testConstructor')]
7373
public function testGetterSetterComponent(Metadata $metadata): void
7474
{
75-
$component = $this->createStub(Component::class);
75+
$component = $this->createMock(Component::class);
7676
self::assertNotSame($component, $metadata->getComponent());
7777
$actual = $metadata->setComponent($component);
7878
self::assertSame($actual, $metadata);
@@ -82,7 +82,7 @@ public function testGetterSetterComponent(Metadata $metadata): void
8282
#[DependsUsingShallowClone('testConstructor')]
8383
public function testGetterSetterProperties(Metadata $metadata): void
8484
{
85-
$properties = $this->createStub(PropertyRepository::class);
85+
$properties = $this->createMock(PropertyRepository::class);
8686
self::assertNotSame($properties, $metadata->getProperties());
8787
$actual = $metadata->setProperties($properties);
8888
self::assertSame($actual, $metadata);

tests/Core/Models/ToolTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testSetterGetterName(Tool $tool): void
8282
#[DependsUsingShallowClone('testConstruct')]
8383
public function testSetterGetterHashDictionary(Tool $tool): void
8484
{
85-
$hashes = $this->createStub(HashDictionary::class);
85+
$hashes = $this->createMock(HashDictionary::class);
8686
self::assertNotSame($hashes, $tool->getHashes());
8787
$actual = $tool->setHashes($hashes);
8888
self::assertSame($actual, $tool);
@@ -92,7 +92,7 @@ public function testSetterGetterHashDictionary(Tool $tool): void
9292
#[DependsUsingShallowClone('testConstruct')]
9393
public function testSetterGetterExternalReferenceRepository(Tool $tool): void
9494
{
95-
$extRefs = $this->createStub(ExternalReferenceRepository::class);
95+
$extRefs = $this->createMock(ExternalReferenceRepository::class);
9696
self::assertNotSame($extRefs, $tool->getExternalReferences());
9797
$actual = $tool->setExternalReferences($extRefs);
9898
self::assertSame($actual, $tool);

0 commit comments

Comments
 (0)