From f9bf9b61904792d473b22679f2d8454a1c239a1f Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Thu, 4 Jul 2024 11:07:55 +0200 Subject: [PATCH] refs #488. Testing --- src/Dto/Input/HardwareInput.php | 1 + src/Entity/HardwareProfile.php | 1 + src/Entity/SoftwareProfile.php | 1 - src/Factory/ClientFactory.php | 5 - src/Factory/HardwareFactory.php | 61 ++++++++ src/Factory/HardwareProfileFactory.php | 2 + src/Factory/HardwareTypeFactory.php | 21 --- src/Factory/ImageFactory.php | 60 ++++++++ src/Factory/MenuFactory.php | 5 - src/Factory/PartitionFactory.php | 4 +- src/Factory/SoftwareFactory.php | 60 ++++++++ src/Factory/SoftwareProfileFactory.php | 57 ++++++++ src/State/Processor/HardwareProcessor.php | 2 +- .../Processor/HardwareProfileProcessor.php | 2 +- src/State/Processor/ImageProcessor.php | 2 +- src/State/Processor/SoftwareProcessor.php | 2 +- .../Processor/SoftwareProfileProcessor.php | 2 +- tests/Functional/ClientTest.php | 2 + tests/Functional/HardwareProfileTest.php | 124 ++++++++++++++++ tests/Functional/HardwareTest.php | 125 ++++++++++++++++ tests/Functional/ImageTest.php | 136 ++++++++++++++++++ tests/Functional/PartitionTest.php | 33 ++++- tests/Functional/SoftwareProfileTest.php | 124 ++++++++++++++++ tests/Functional/SoftwareTest.php | 118 +++++++++++++++ 24 files changed, 906 insertions(+), 44 deletions(-) create mode 100644 src/Factory/HardwareFactory.php create mode 100644 src/Factory/ImageFactory.php create mode 100644 src/Factory/SoftwareFactory.php create mode 100644 src/Factory/SoftwareProfileFactory.php create mode 100644 tests/Functional/HardwareProfileTest.php create mode 100644 tests/Functional/HardwareTest.php create mode 100644 tests/Functional/ImageTest.php create mode 100644 tests/Functional/SoftwareProfileTest.php create mode 100644 tests/Functional/SoftwareTest.php diff --git a/src/Dto/Input/HardwareInput.php b/src/Dto/Input/HardwareInput.php index 0e41d38..7674310 100644 --- a/src/Dto/Input/HardwareInput.php +++ b/src/Dto/Input/HardwareInput.php @@ -19,6 +19,7 @@ final class HardwareInput #[ApiProperty(description: 'The description of the hardware', example: "Hardware 1 description")] public ?string $description = null; + #[Assert\NotNull] #[Groups(['hardware:write'])] #[ApiProperty(description: 'The type of the hardware', example: "Server")] public ?HardwareTypeOutput $type = null; diff --git a/src/Entity/HardwareProfile.php b/src/Entity/HardwareProfile.php index 253a7fd..3538baf 100644 --- a/src/Entity/HardwareProfile.php +++ b/src/Entity/HardwareProfile.php @@ -17,6 +17,7 @@ class HardwareProfile extends AbstractEntity private ?string $comments = null; #[ORM\ManyToOne(targetEntity: OrganizationalUnit::class)] + #[ORM\JoinColumn(nullable: false)] private ?OrganizationalUnit $organizationalUnit = null; /** diff --git a/src/Entity/SoftwareProfile.php b/src/Entity/SoftwareProfile.php index 4ac75b8..bc0f968 100644 --- a/src/Entity/SoftwareProfile.php +++ b/src/Entity/SoftwareProfile.php @@ -20,7 +20,6 @@ class SoftwareProfile extends AbstractEntity #[ORM\JoinColumn(nullable: false)] private ?OrganizationalUnit $organizationalUnit = null; - /** * @var Collection */ diff --git a/src/Factory/ClientFactory.php b/src/Factory/ClientFactory.php index a967161..56e28da 100644 --- a/src/Factory/ClientFactory.php +++ b/src/Factory/ClientFactory.php @@ -21,11 +21,6 @@ final class ClientFactory extends ModelFactory parent::__construct(); } - public static function class(): string - { - return Client::class; - } - /** * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories * diff --git a/src/Factory/HardwareFactory.php b/src/Factory/HardwareFactory.php new file mode 100644 index 0000000..24f68c2 --- /dev/null +++ b/src/Factory/HardwareFactory.php @@ -0,0 +1,61 @@ + + */ +final class HardwareFactory extends ModelFactory +{ + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services + * + * @todo inject services if required + */ + public function __construct() + { + parent::__construct(); + } + + public static function class(): string + { + return Hardware::class; + } + + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories + * + * @todo add your default values here + */ + protected function getDefaults(): array + { + return [ + 'createdAt' => self::faker()->dateTime(), + 'name' => self::faker()->text(255), + 'updatedAt' => self::faker()->dateTime(), + 'type' => HardwareTypeFactory::new() + ]; + } + + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization + */ + protected function initialize(): self + { + return $this + // ->afterInstantiate(function(Hardware $hardware): void {}) + ; + } + + protected static function getClass(): string + { + return Hardware::class; + } +} diff --git a/src/Factory/HardwareProfileFactory.php b/src/Factory/HardwareProfileFactory.php index eacb105..fe3148b 100644 --- a/src/Factory/HardwareProfileFactory.php +++ b/src/Factory/HardwareProfileFactory.php @@ -3,6 +3,7 @@ namespace App\Factory; use App\Entity\HardwareProfile; +use App\Model\OrganizationalUnitTypes; use Zenstruck\Foundry\ModelFactory; use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory; @@ -37,6 +38,7 @@ final class HardwareProfileFactory extends ModelFactory 'createdAt' => self::faker()->dateTime(), 'updatedAt' => self::faker()->dateTime(), 'description' => self::faker()->text(255), + 'organizationalUnit' => OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT])->_save(), ]; } diff --git a/src/Factory/HardwareTypeFactory.php b/src/Factory/HardwareTypeFactory.php index b307824..10788fe 100644 --- a/src/Factory/HardwareTypeFactory.php +++ b/src/Factory/HardwareTypeFactory.php @@ -11,22 +11,6 @@ use Zenstruck\Foundry\Persistence\ProxyRepositoryDecorator; /** * @extends PersistentProxyObjectFactory - * - * @method HardwareType|Proxy create(array|callable $attributes = []) - * @method static HardwareType|Proxy createOne(array $attributes = []) - * @method static HardwareType|Proxy find(object|array|mixed $criteria) - * @method static HardwareType|Proxy findOrCreate(array $attributes) - * @method static HardwareType|Proxy first(string $sortedField = 'id') - * @method static HardwareType|Proxy last(string $sortedField = 'id') - * @method static HardwareType|Proxy random(array $attributes = []) - * @method static HardwareType|Proxy randomOrCreate(array $attributes = []) - * @method static HardwareTypeRepository|ProxyRepositoryDecorator repository() - * @method static HardwareType[]|Proxy[] all() - * @method static HardwareType[]|Proxy[] createMany(int $number, array|callable $attributes = []) - * @method static HardwareType[]|Proxy[] createSequence(iterable|callable $sequence) - * @method static HardwareType[]|Proxy[] findBy(array $attributes) - * @method static HardwareType[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) - * @method static HardwareType[]|Proxy[] randomSet(int $number, array $attributes = []) */ final class HardwareTypeFactory extends ModelFactory { @@ -40,11 +24,6 @@ final class HardwareTypeFactory extends ModelFactory parent::__construct(); } - public static function class(): string - { - return HardwareType::class; - } - /** * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories * diff --git a/src/Factory/ImageFactory.php b/src/Factory/ImageFactory.php new file mode 100644 index 0000000..3a4962d --- /dev/null +++ b/src/Factory/ImageFactory.php @@ -0,0 +1,60 @@ + + */ +final class ImageFactory extends ModelFactory +{ + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services + * + * @todo inject services if required + */ + public function __construct() + { + parent::__construct(); + } + + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories + * + * @todo add your default values here + */ + protected function getDefaults(): array + { + return [ + 'client' => ClientFactory::new(), + 'createdAt' => self::faker()->dateTime(), + 'name' => self::faker()->text(255), + 'path' => self::faker()->text(255), + 'size' => self::faker()->randomNumber(), + 'softwareProfile' => SoftwareProfileFactory::new(), + 'type' => self::faker()->text(255), + 'updatedAt' => self::faker()->dateTime(), + ]; + } + + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization + */ + protected function initialize(): self + { + return $this + // ->afterInstantiate(function(Image $image): void {}) + ; + } + + protected static function getClass(): string + { + return Image::class; + } +} diff --git a/src/Factory/MenuFactory.php b/src/Factory/MenuFactory.php index e5762ca..37f8125 100644 --- a/src/Factory/MenuFactory.php +++ b/src/Factory/MenuFactory.php @@ -24,11 +24,6 @@ final class MenuFactory extends ModelFactory parent::__construct(); } - public static function class(): string - { - return Menu::class; - } - /** * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories */ diff --git a/src/Factory/PartitionFactory.php b/src/Factory/PartitionFactory.php index 397ef82..bb3d736 100644 --- a/src/Factory/PartitionFactory.php +++ b/src/Factory/PartitionFactory.php @@ -40,7 +40,9 @@ final class PartitionFactory extends ModelFactory 'createdAt' => self::faker()->dateTime(), 'memoryUsage' => self::faker()->randomNumber(), 'size' => self::faker()->randomNumber(), - 'updatedAt' => self::faker()->dateTime() + 'updatedAt' => self::faker()->dateTime(), + 'operativeSystem' => OperativeSystemFactory::new(), + 'client' => ClientFactory::new(), ]; } diff --git a/src/Factory/SoftwareFactory.php b/src/Factory/SoftwareFactory.php new file mode 100644 index 0000000..7d59325 --- /dev/null +++ b/src/Factory/SoftwareFactory.php @@ -0,0 +1,60 @@ + + */ +final class SoftwareFactory extends ModelFactory +{ + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services + * + * @todo inject services if required + */ + public function __construct() + { + parent::__construct(); + } + + public static function class(): string + { + return Software::class; + } + + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories + * + * @todo add your default values here + */ + protected function getDefaults(): array + { + return [ + 'createdAt' => self::faker()->dateTime(), + 'name' => self::faker()->text(255), + 'updatedAt' => self::faker()->dateTime(), + ]; + } + + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization + */ + protected function initialize(): self + { + return $this + // ->afterInstantiate(function(Software $software): void {}) + ; + } + + protected static function getClass(): string + { + return Software::class; + } +} diff --git a/src/Factory/SoftwareProfileFactory.php b/src/Factory/SoftwareProfileFactory.php new file mode 100644 index 0000000..5a05ae4 --- /dev/null +++ b/src/Factory/SoftwareProfileFactory.php @@ -0,0 +1,57 @@ + + */ +final class SoftwareProfileFactory extends ModelFactory +{ + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#factories-as-services + * + * @todo inject services if required + */ + public function __construct() + { + parent::__construct(); + } + + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#model-factories + * + * @todo add your default values here + */ + protected function getDefaults(): array + { + return [ + 'createdAt' => self::faker()->dateTime(), + 'description' => self::faker()->text(255), + 'updatedAt' => self::faker()->dateTime(), + 'organizationalUnit' => OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT])->_save(), + ]; + } + + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization + */ + protected function initialize(): self + { + return $this + // ->afterInstantiate(function(SoftwareProfile $softwareProfile): void {}) + ; + } + + protected static function getClass(): string + { + return SoftwareProfile::class; + } +} diff --git a/src/State/Processor/HardwareProcessor.php b/src/State/Processor/HardwareProcessor.php index 971fb3d..ff54e13 100644 --- a/src/State/Processor/HardwareProcessor.php +++ b/src/State/Processor/HardwareProcessor.php @@ -26,7 +26,7 @@ class HardwareProcessor implements ProcessorInterface /** * @throws \Exception */ - public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): HardwareOutput + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): HardwareOutput|null { switch ($operation){ case $operation instanceof Post: diff --git a/src/State/Processor/HardwareProfileProcessor.php b/src/State/Processor/HardwareProfileProcessor.php index ed6ccf8..f68c3a8 100644 --- a/src/State/Processor/HardwareProfileProcessor.php +++ b/src/State/Processor/HardwareProfileProcessor.php @@ -26,7 +26,7 @@ readonly class HardwareProfileProcessor implements ProcessorInterface /** * @throws \Exception */ - public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): HardwareProfileOutput + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): HardwareProfileOutput|null { switch ($operation){ case $operation instanceof Post: diff --git a/src/State/Processor/ImageProcessor.php b/src/State/Processor/ImageProcessor.php index 8506b70..833225d 100644 --- a/src/State/Processor/ImageProcessor.php +++ b/src/State/Processor/ImageProcessor.php @@ -25,7 +25,7 @@ readonly class ImageProcessor implements ProcessorInterface /** * @throws \Exception */ - public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): ImageOutput + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): ImageOutput|null { switch ($operation){ case $operation instanceof Post: diff --git a/src/State/Processor/SoftwareProcessor.php b/src/State/Processor/SoftwareProcessor.php index 3730595..9109b7b 100644 --- a/src/State/Processor/SoftwareProcessor.php +++ b/src/State/Processor/SoftwareProcessor.php @@ -25,7 +25,7 @@ readonly class SoftwareProcessor implements ProcessorInterface /** * @throws \Exception */ - public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): SoftwareOutput + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): SoftwareOutput|null { switch ($operation){ case $operation instanceof Post: diff --git a/src/State/Processor/SoftwareProfileProcessor.php b/src/State/Processor/SoftwareProfileProcessor.php index 7368d4d..21bde82 100644 --- a/src/State/Processor/SoftwareProfileProcessor.php +++ b/src/State/Processor/SoftwareProfileProcessor.php @@ -25,7 +25,7 @@ readonly class SoftwareProfileProcessor implements ProcessorInterface /** * @throws \Exception */ - public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): SoftwareProfileOutput + public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): SoftwareProfileOutput|null { switch ($operation){ case $operation instanceof Post: diff --git a/tests/Functional/ClientTest.php b/tests/Functional/ClientTest.php index f28429a..82d8055 100644 --- a/tests/Functional/ClientTest.php +++ b/tests/Functional/ClientTest.php @@ -4,11 +4,13 @@ namespace Functional; use App\Entity\Client; use App\Entity\HardwareProfile; +use App\Entity\HardwareType; use App\Entity\OrganizationalUnit; use App\Entity\User; use App\Entity\UserGroup; use App\Factory\ClientFactory; use App\Factory\HardwareProfileFactory; +use App\Factory\HardwareTypeFactory; use App\Factory\OrganizationalUnitFactory; use App\Factory\UserFactory; use App\Factory\UserGroupFactory; diff --git a/tests/Functional/HardwareProfileTest.php b/tests/Functional/HardwareProfileTest.php new file mode 100644 index 0000000..6d710b8 --- /dev/null +++ b/tests/Functional/HardwareProfileTest.php @@ -0,0 +1,124 @@ + self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + HardwareProfileFactory::createMany(10); + + $this->createClientWithCredentials()->request('GET', '/hardware-profiles'); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/HardwareProfile', + '@id' => '/hardware-profiles', + '@type' => 'hydra:Collection', + 'hydra:totalItems' => 10, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testCreateHardwareProfile(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]); + $ouIri = $this->findIriBy(OrganizationalUnit::class, ['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]); + + $this->createClientWithCredentials()->request('POST', '/hardware-profiles',['json' => [ + 'description' => self::HW_PROFILE_CREATE, + 'organizationalUnit' => $ouIri + ]]); + + $this->assertResponseStatusCodeSame(201); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/HardwareProfileOutput', + '@type' => 'HardwareProfile', + 'description' => self::HW_PROFILE_CREATE + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testUpdateHardwareProfile(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + HardwareProfileFactory::createOne(['description' => self::HW_PROFILE_CREATE]); + $iri = $this->findIriBy(HardwareProfile::class, ['description' => self::HW_PROFILE_CREATE]); + + $this->createClientWithCredentials()->request('PUT', $iri, ['json' => [ + 'description' => self::HW_PROFILE_UPDATE, + ]]); + + $this->assertResponseIsSuccessful(); + $this->assertJsonContains([ + '@id' => $iri, + 'description' => self::HW_PROFILE_UPDATE, + ]); + } + + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + */ + public function testDeleteHardwareProfile(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + HardwareProfileFactory::createOne(['description' => self::HW_PROFILE_DELETE]); + $iri = $this->findIriBy(HardwareProfile::class, ['description' => self::HW_PROFILE_DELETE]); + + $this->createClientWithCredentials()->request('DELETE', $iri); + $this->assertResponseStatusCodeSame(204); + $this->assertNull( + static::getContainer()->get('doctrine')->getRepository(HardwareProfile::class)->findOneBy(['description' => self::HW_PROFILE_DELETE]) + ); + } +} \ No newline at end of file diff --git a/tests/Functional/HardwareTest.php b/tests/Functional/HardwareTest.php new file mode 100644 index 0000000..1726ae7 --- /dev/null +++ b/tests/Functional/HardwareTest.php @@ -0,0 +1,125 @@ + self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + HardwareFactory::createMany(10); + + $this->createClientWithCredentials()->request('GET', '/hardware'); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/Hardware', + '@id' => '/hardware', + '@type' => 'hydra:Collection', + 'hydra:totalItems' => 10, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testCreateHardware(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + HardwareTypeFactory::createOne(['name' => self::HW_TYPE]); + $hwIri = $this->findIriBy(HardwareType::class, ['name' => self::HW_TYPE]); + + $this->createClientWithCredentials()->request('POST', '/hardware',['json' => [ + 'name' => self::HW_CREATE, + 'type' => $hwIri + ]]); + + $this->assertResponseStatusCodeSame(201); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/HardwareOutput', + '@type' => 'Hardware', + 'name' => self::HW_CREATE + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testUpdateHardware(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + HardwareFactory::createOne(['name' => self::HW_CREATE]); + $iri = $this->findIriBy(Hardware::class, ['name' => self::HW_CREATE]); + + $this->createClientWithCredentials()->request('PUT', $iri, ['json' => [ + 'name' => self::HW_UPDATE, + ]]); + + $this->assertResponseIsSuccessful(); + $this->assertJsonContains([ + '@id' => $iri, + 'name' => self::HW_UPDATE, + ]); + } + + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + */ + public function testDeleteHardware(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + HardwareFactory::createOne(['name' => self::HW_DELETE]); + $iri = $this->findIriBy(Hardware::class, ['name' => self::HW_DELETE]); + + $this->createClientWithCredentials()->request('DELETE', $iri); + $this->assertResponseStatusCodeSame(204); + $this->assertNull( + static::getContainer()->get('doctrine')->getRepository(Hardware::class)->findOneBy(['name' => self::HW_DELETE]) + ); + } +} \ No newline at end of file diff --git a/tests/Functional/ImageTest.php b/tests/Functional/ImageTest.php new file mode 100644 index 0000000..b4e95fc --- /dev/null +++ b/tests/Functional/ImageTest.php @@ -0,0 +1,136 @@ + self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + ImageFactory::createMany(10); + + $this->createClientWithCredentials()->request('GET', '/images'); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/Image', + '@id' => '/images', + '@type' => 'hydra:Collection', + 'hydra:totalItems' => 10, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testCreateImage(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + ClientFactory::createOne(['name' => self::CLIENT]); + $clientIri = $this->findIriBy(Client::class, ['name' => self::CLIENT]); + + SoftwareProfileFactory::createOne(['description' => self::SOFTWARE_PROFILE]); + $swPIri = $this->findIriBy(SoftwareProfile::class, ['description' => self::SOFTWARE_PROFILE]); + + $this->createClientWithCredentials()->request('POST', '/images',['json' => [ + 'name' => self::IMAGE_CREATE, + 'size' => 123, + 'path' => '/path/to/image', + 'type' => 'type', + 'client' => $clientIri, + 'softwareProfile' => $swPIri + ]]); + + $this->assertResponseStatusCodeSame(201); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/ImageOutput', + '@type' => 'Image', + 'name' => self::IMAGE_CREATE, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testUpdateImage(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + ImageFactory::createOne(['name' => self::IMAGE_CREATE]); + $iri = $this->findIriBy(Image::class, ['name' => self::IMAGE_CREATE]); + + $this->createClientWithCredentials()->request('PUT', $iri, ['json' => [ + 'name' => self::IMAGE_UPDATE, + 'size' => 123 + ]]); + + $this->assertResponseIsSuccessful(); + $this->assertJsonContains([ + '@id' => $iri, + 'name' => self::IMAGE_UPDATE, + 'size' => 123 + ]); + } + + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + */ + public function testDeleteImage(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + ImageFactory::createOne(['name' => self::IMAGE_DELETE]); + $iri = $this->findIriBy(Image::class, ['name' => self::IMAGE_DELETE]); + + $this->createClientWithCredentials()->request('DELETE', $iri); + $this->assertResponseStatusCodeSame(204); + $this->assertNull( + static::getContainer()->get('doctrine')->getRepository(Client::class)->findOneBy(['name' => self::IMAGE_DELETE]) + ); + } +} \ No newline at end of file diff --git a/tests/Functional/PartitionTest.php b/tests/Functional/PartitionTest.php index 4bd3f75..39debe4 100644 --- a/tests/Functional/PartitionTest.php +++ b/tests/Functional/PartitionTest.php @@ -40,12 +40,7 @@ class PartitionTest extends AbstractTest { UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); - $ou = OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]); - $hp = HardwareProfileFactory::createOne(['description' => self::HW_PROFILE]); - - $client = ClientFactory::createOne(['name' => self::CLIENT_CREATE, 'serialNumber' => '123abc', 'organizationalUnit' => $ou, 'hardwareProfile' => $hp]); - - PartitionFactory::createMany(10, ['client' => $client]); + PartitionFactory::createMany(10); $this->createClientWithCredentials()->request('GET', '/partitions'); $this->assertResponseStatusCodeSame(Response::HTTP_OK); @@ -95,4 +90,30 @@ class PartitionTest extends AbstractTest ]); } + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testUpdatePartition(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + PartitionFactory::createOne(['size' => 100, 'memoryUsage' => 100]); + $iri = $this->findIriBy(Partition::class, ['size' => 100, 'memoryUsage' => 100]); + + $this->createClientWithCredentials()->request('PUT', $iri, ['json' => [ + 'size' => 200, + 'memoryUsage' => 300 + ]]); + + $this->assertResponseIsSuccessful(); + $this->assertJsonContains([ + '@id' => $iri, + 'size' => 200, + 'memoryUsage' => 300 + ]); + } } \ No newline at end of file diff --git a/tests/Functional/SoftwareProfileTest.php b/tests/Functional/SoftwareProfileTest.php new file mode 100644 index 0000000..8d2ac62 --- /dev/null +++ b/tests/Functional/SoftwareProfileTest.php @@ -0,0 +1,124 @@ + self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + SoftwareProfileFactory::createMany(10); + + $this->createClientWithCredentials()->request('GET', '/software-profiles'); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/SoftwareProfile', + '@id' => '/software-profiles', + '@type' => 'hydra:Collection', + 'hydra:totalItems' => 10, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testCreateSoftwareProfile(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + OrganizationalUnitFactory::createOne(['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]); + $ouIri = $this->findIriBy(OrganizationalUnit::class, ['type' => OrganizationalUnitTypes::ORGANIZATIONAL_UNIT]); + + $this->createClientWithCredentials()->request('POST', '/software-profiles',['json' => [ + 'description' => self::SW_PROFILE_CREATE, + 'organizationalUnit' => $ouIri + ]]); + + $this->assertResponseStatusCodeSame(201); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/SoftwareProfileOutput', + '@type' => 'SoftwareProfile', + 'description' => self::SW_PROFILE_CREATE + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testUpdateSoftwareProfile(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + SoftwareProfileFactory::createOne(['description' => self::SW_PROFILE_CREATE]); + $iri = $this->findIriBy(SoftwareProfile::class, ['description' => self::SW_PROFILE_CREATE]); + + $this->createClientWithCredentials()->request('PUT', $iri, ['json' => [ + 'description' => self::SW_PROFILE_UPDATE, + ]]); + + $this->assertResponseIsSuccessful(); + $this->assertJsonContains([ + '@id' => $iri, + 'description' => self::SW_PROFILE_UPDATE, + ]); + } + + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + */ + public function testDeleteSoftwareProfile(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + SoftwareProfileFactory::createOne(['description' => self::SW_PROFILE_DELETE]); + $iri = $this->findIriBy(SoftwareProfile::class, ['description' => self::SW_PROFILE_DELETE]); + + $this->createClientWithCredentials()->request('DELETE', $iri); + $this->assertResponseStatusCodeSame(204); + $this->assertNull( + static::getContainer()->get('doctrine')->getRepository(SoftwareProfile::class)->findOneBy(['description' => self::SW_PROFILE_DELETE]) + ); + } +} \ No newline at end of file diff --git a/tests/Functional/SoftwareTest.php b/tests/Functional/SoftwareTest.php new file mode 100644 index 0000000..07f41dd --- /dev/null +++ b/tests/Functional/SoftwareTest.php @@ -0,0 +1,118 @@ + self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + SoftwareFactory::createMany(10); + + $this->createClientWithCredentials()->request('GET', '/software'); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/Software', + '@id' => '/software', + '@type' => 'hydra:Collection', + 'hydra:totalItems' => 10, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testCreateSoftware(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + $this->createClientWithCredentials()->request('POST', '/software',['json' => [ + 'name' => self::SW_CREATE, + ]]); + + $this->assertResponseStatusCodeSame(201); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/SoftwareOutput', + '@type' => 'Software', + 'name' => self::SW_CREATE + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testUpdateSoftware(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + SoftwareFactory::createOne(['name' => self::SW_CREATE]); + $iri = $this->findIriBy(Software::class, ['name' => self::SW_CREATE]); + + $this->createClientWithCredentials()->request('PUT', $iri, ['json' => [ + 'name' => self::SW_UPDATE, + ]]); + + $this->assertResponseIsSuccessful(); + $this->assertJsonContains([ + '@id' => $iri, + 'name' => self::SW_UPDATE, + ]); + } + + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + */ + public function testDeleteSoftware(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + SoftwareFactory::createOne(['name' => self::SW_DELETE]); + $iri = $this->findIriBy(Software::class, ['name' => self::SW_DELETE]); + + $this->createClientWithCredentials()->request('DELETE', $iri); + $this->assertResponseStatusCodeSame(204); + $this->assertNull( + static::getContainer()->get('doctrine')->getRepository(Software::class)->findOneBy(['name' => self::SW_DELETE]) + ); + } +} \ No newline at end of file