Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more tests and coverage #232

Merged
merged 13 commits into from
Feb 19, 2023
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Code of v1 is in branch "[1.x](https://github.com/CycloneDX/cyclonedx-php-librar
* `HashDictionary`
* `LicenseExpression`, `NamedLicense`, `SpdxLicense`, `LicenseRepository`
* `Metadata`
* `Property`, `PropertyRepository`
* `Tool`, `ToolRepository`
* Factories for the following use cases:
* Create data models from any license descriptor string
Expand Down
8 changes: 5 additions & 3 deletions tests/Core/Collections/BomRefRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
use CycloneDX\Core\Collections\BomRefRepository;
use CycloneDX\Core\Models\BomRef;
use Generator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\BomRefRepository::class)]
#[CoversClass(BomRefRepository::class)]
class BomRefRepositoryTest extends TestCase
{
public function testEmptyConstructor(): void
Expand All @@ -43,7 +45,7 @@ public function testEmptyConstructor(): void
* @param BomRef[] $bomRefs
* @param BomRef[] $expectedContains
*/
#[\PHPUnit\Framework\Attributes\DataProvider('dpNonEmptyConstructor')]
#[DataProvider('dpNonEmptyConstructor')]
public function testNonEmptyConstructor(array $bomRefs, array $expectedContains): void
{
$repo = new BomRefRepository(...$bomRefs);
Expand Down Expand Up @@ -79,7 +81,7 @@ public static function dpNonEmptyConstructor(): Generator
* @param BomRef[] $add
* @param BomRef[] $expectedContains
*/
#[\PHPUnit\Framework\Attributes\DataProvider('dpAddBomRef')]
#[DataProvider('dpAddBomRef')]
public function testAddAndGetItems(array $initial, array $add, array $expectedContains): void
{
$repo = new BomRefRepository(...$initial);
Expand Down
6 changes: 4 additions & 2 deletions tests/Core/Collections/ComponentRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
use CycloneDX\Core\Collections\ComponentRepository;
use CycloneDX\Core\Models\Component;
use Generator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\ComponentRepository::class)]
#[CoversClass(ComponentRepository::class)]
class ComponentRepositoryTest extends TestCase
{
public function testEmptyConstructor(): void
Expand Down Expand Up @@ -72,7 +74,7 @@ public function testAddAndGetItems(): void
/**
* @param Component[] $expectedFindings
*/
#[\PHPUnit\Framework\Attributes\DataProvider('dpFindComponents')]
#[DataProvider('dpFindComponents')]
public function testFindItem(
ComponentRepository $repo,
string $findName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@

use CycloneDX\Core\Collections\ExternalReferenceRepository;
use CycloneDX\Core\Models\ExternalReference;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\ExternalReferenceRepository::class)]
#[CoversClass(ExternalReferenceRepository::class)]
class ExternalReferenceRepositoryTest extends TestCase
{
public function testEmptyConstructor(): void
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Collections/HashDictionaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@

use CycloneDX\Core\Collections\HashDictionary;
use CycloneDX\Core\Enums\HashAlgorithm;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\HashDictionary::class)]
#[CoversClass(HashDictionary::class)]
class HashDictionaryTest extends TestCase
{
public function testNonEmptyConstructor(): void
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Collections/LicenseRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
use CycloneDX\Core\Collections\LicenseRepository;
use CycloneDX\Core\Models\License\NamedLicense;
use CycloneDX\Core\Models\License\SpdxLicense;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\LicenseRepository::class)]
#[CoversClass(LicenseRepository::class)]
class LicenseRepositoryTest extends TestCase
{
public function testEmptyConstructor(): void
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Collections/PropertyRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@

use CycloneDX\Core\Collections\PropertyRepository;
use CycloneDX\Core\Models\Property;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\PropertyRepository::class)]
#[CoversClass(PropertyRepository::class)]
class PropertyRepositoryTest extends TestCase
{
public function testEmptyConstructor(): void
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Collections/ToolRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@

use CycloneDX\Core\Collections\ToolRepository;
use CycloneDX\Core\Models\Tool;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Collections\ToolRepository::class)]
#[CoversClass(ToolRepository::class)]
class ToolRepositoryTest extends TestCase
{
public function testEmptyConstructor(): void
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Enums/ComponentTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
use CycloneDX\Core\Enums\ComponentType;
use CycloneDX\Tests\_data\BomSpecData;
use Generator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Enums\ComponentType::class)]
#[CoversClass(ComponentType::class)]
class ComponentTypeTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('dpSchemaValues')]
Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Enums/ExternalReferenceTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
use CycloneDX\Core\Enums\ExternalReferenceType;
use CycloneDX\Tests\_data\BomSpecData;
use Generator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Enums\ExternalReferenceType::class)]
#[CoversClass(ExternalReferenceType::class)]
class ExternalReferenceTypeTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('dpSchemaValues')]
Expand Down
6 changes: 4 additions & 2 deletions tests/Core/Enums/HashAlgorithmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
use CycloneDX\Core\Enums\HashAlgorithm;
use CycloneDX\Tests\_data\BomSpecData;
use Generator;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Enums\HashAlgorithm::class)]
#[CoversClass(HashAlgorithm::class)]
class HashAlgorithmTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('dpSchemaValues')]
#[DataProvider('dpSchemaValues')]
public function testHaseCaseForSchemaValue(string $value): void
{
self::assertNotNull(HashAlgorithm::tryFrom($value));
Expand Down
13 changes: 8 additions & 5 deletions tests/Core/Factories/LicenseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@
use CycloneDX\Core\Spdx\LicenseValidator as SpdxLicenseValidator;
use DomainException;
use Exception;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DependsUsingShallowClone;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use UnexpectedValueException;

#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Factories\LicenseFactory::class)]
#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\License\LicenseExpression::class)]
#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\License\SpdxLicense::class)]
#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\License\NamedLicense::class)]
#[CoversClass(LicenseFactory::class)]
#[UsesClass(LicenseExpression::class)]
#[UsesClass(SpdxLicense::class)]
#[UsesClass(NamedLicense::class)]
class LicenseFactoryTest extends TestCase
{
public function testConstructorWithValidator(): LicenseFactory
Expand Down Expand Up @@ -66,7 +69,7 @@ public function testConstructor(): LicenseFactory
return $factory;
}

#[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructor')]
#[DependsUsingShallowClone('testConstructor')]
public function testSetSpdxLicenseValidator(LicenseFactory $factory): void
{
$spdxLicenseValidator = $this->createStub(SpdxLicenseValidator::class);
Expand Down
10 changes: 6 additions & 4 deletions tests/Core/Models/BomRefTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
namespace CycloneDX\Tests\Core\Models;

use CycloneDX\Core\Models\BomRef;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DependsUsingShallowClone;
use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Models\BomRef::class)]
#[CoversClass(BomRef::class)]
class BomRefTest extends TestCase
{
public function testConstructValueDefaultsToNull(): BomRef
Expand All @@ -47,21 +49,21 @@ public function testConstructSetsValue(): BomRef
return $bomRef;
}

#[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructSetsValue')]
#[DependsUsingShallowClone('testConstructSetsValue')]
public function testSetValueNull(BomRef $bomRef): void
{
$bomRef->setValue(null);
self::assertNull($bomRef->getValue());
}

#[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructSetsValue')]
#[DependsUsingShallowClone('testConstructSetsValue')]
public function testSetValueEmptyIsNull(BomRef $bomRef): void
{
$bomRef->setValue('');
self::assertNull($bomRef->getValue());
}

#[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstructValueDefaultsToNull')]
#[DependsUsingShallowClone('testConstructValueDefaultsToNull')]
public function testSetValue(BomRef $bomRef): void
{
$bomRef->setValue('asdewqe');
Expand Down
34 changes: 19 additions & 15 deletions tests/Core/Models/BomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@
use CycloneDX\Core\Collections\ComponentRepository;
use CycloneDX\Core\Collections\ExternalReferenceRepository;
use CycloneDX\Core\Collections\PropertyRepository;
use CycloneDX\Core\Collections\ToolRepository;
use CycloneDX\Core\Models\Bom;
use CycloneDX\Core\Models\Metadata;
use DomainException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DependsUsingShallowClone;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;

#[\PHPUnit\Framework\Attributes\CoversClass(\CycloneDX\Core\Models\Bom::class)]
#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\ComponentRepository::class)]
#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Models\Metadata::class)]
#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\ToolRepository::class)]
#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\ExternalReferenceRepository::class)]
#[\PHPUnit\Framework\Attributes\UsesClass(\CycloneDX\Core\Collections\PropertyRepository::class)]
#[CoversClass(Bom::class)]
#[UsesClass(ComponentRepository::class)]
#[UsesClass(Metadata::class)]
#[UsesClass(ToolRepository::class)]
#[UsesClass(ExternalReferenceRepository::class)]
#[UsesClass(PropertyRepository::class)]
class BomTest extends TestCase
{
public function testConstruct(): Bom
Expand All @@ -55,7 +59,7 @@ public function testConstruct(): Bom

// region serialNumber setter&getter

#[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')]
#[DependsUsingShallowClone('testConstruct')]
public function testSerialNumber(Bom $bom): Bom
{
$serialNumber = 'urn:uuid:3e671687-395b-41f5-a30f-a58921a69b79';
Expand All @@ -67,7 +71,7 @@ public function testSerialNumber(Bom $bom): Bom
return $bom;
}

#[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testSerialNumber')]
#[DependsUsingShallowClone('testSerialNumber')]
public function testSerialNumberEmptyString(Bom $bom): void
{
$setOn = $bom->setSerialNumber('');
Expand All @@ -76,7 +80,7 @@ public function testSerialNumberEmptyString(Bom $bom): void
self::assertNull($bom->getSerialNumber());
}

#[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testSerialNumber')]
#[DependsUsingShallowClone('testSerialNumber')]
public function testSerialNumberEmptyStringInvalidValue(Bom $bom): void
{
$serialNumber = uniqid('invalid-value', true);
Expand All @@ -88,7 +92,7 @@ public function testSerialNumberEmptyStringInvalidValue(Bom $bom): void

// region components setter&getter&modifiers

#[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')]
#[DependsUsingShallowClone('testConstruct')]
public function testComponentsSetterGetter(Bom $bom): void
{
$components = $this->createStub(ComponentRepository::class);
Expand All @@ -101,7 +105,7 @@ public function testComponentsSetterGetter(Bom $bom): void

// region version setter&getter

#[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')]
#[DependsUsingShallowClone('testConstruct')]
public function testVersionSetterGetter(Bom $bom): void
{
$version = random_int(1, 255);
Expand All @@ -110,7 +114,7 @@ public function testVersionSetterGetter(Bom $bom): void
self::assertSame($version, $bom->getVersion());
}

#[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')]
#[DependsUsingShallowClone('testConstruct')]
public function testVersionSetterInvalidValue(Bom $bom): void
{
$version = 0 - random_int(1, 255);
Expand All @@ -122,7 +126,7 @@ public function testVersionSetterInvalidValue(Bom $bom): void

// region metadata setter&getter

#[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')]
#[DependsUsingShallowClone('testConstruct')]
public function testMetadataSetterGetter(Bom $bom): void
{
$metadata = $this->createStub(Metadata::class);
Expand All @@ -135,7 +139,7 @@ public function testMetadataSetterGetter(Bom $bom): void

// region externalReferenceRepository setter&getter

#[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')]
#[DependsUsingShallowClone('testConstruct')]
public function testExternalReferenceRepositorySetterGetter(Bom $bom): void
{
$extRefRepo = $this->createStub(ExternalReferenceRepository::class);
Expand All @@ -148,7 +152,7 @@ public function testExternalReferenceRepositorySetterGetter(Bom $bom): void

// region externalReferenceRepository setter&getter

#[\PHPUnit\Framework\Attributes\DependsUsingShallowClone('testConstruct')]
#[DependsUsingShallowClone('testConstruct')]
public function testPropertiesSetterGetter(Bom $bom): void
{
$repo = $this->createStub(PropertyRepository::class);
Expand Down
Loading