diff --git a/src/Factory/CommandGroupFactory.php b/src/Factory/CommandGroupFactory.php new file mode 100644 index 0000000..4608586 --- /dev/null +++ b/src/Factory/CommandGroupFactory.php @@ -0,0 +1,56 @@ + + */ +final class CommandGroupFactory 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 getClass(): string + { + return CommandGroup::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(), + 'enabled' => self::faker()->boolean(), + '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(CommandGroup $commandGroup): void {}) + ; + } +} diff --git a/src/Factory/CommandTaskFactory.php b/src/Factory/CommandTaskFactory.php new file mode 100644 index 0000000..91d2d09 --- /dev/null +++ b/src/Factory/CommandTaskFactory.php @@ -0,0 +1,56 @@ + + */ +final class CommandTaskFactory 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 getClass(): string + { + return CommandTask::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(), + 'datetime' => self::faker()->dateTime(), + 'status' => 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(CommandTask $commandTask): void {}) + ; + } +} diff --git a/src/Factory/TraceFactory.php b/src/Factory/TraceFactory.php new file mode 100644 index 0000000..14aec4b --- /dev/null +++ b/src/Factory/TraceFactory.php @@ -0,0 +1,58 @@ + + */ +final class TraceFactory 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 getClass(): string + { + return Trace::class; + } + + /** + * @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(), + 'command' => CommandFactory::new(), + 'createdAt' => self::faker()->dateTime(), + 'executedAt' => self::faker()->dateTime(), + 'status' => self::faker()->text(255), + 'updatedAt' => self::faker()->dateTime() + ]; + } + + /** + * @see https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#initialization + */ + protected function initialize(): static + { + return $this + // ->afterInstantiate(function(Trace $trace): void {}) + ; + } +} diff --git a/tests/Functional/CommandGroupTest.php b/tests/Functional/CommandGroupTest.php new file mode 100644 index 0000000..de5faef --- /dev/null +++ b/tests/Functional/CommandGroupTest.php @@ -0,0 +1,127 @@ + self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + CommandGroupFactory::createMany(10); + + $this->createClientWithCredentials()->request('GET', '/command-groups'); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/CommandGroup', + '@id' => '/command-groups', + '@type' => 'hydra:Collection', + 'hydra:totalItems' => 10, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testCreateCommandGroup(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + CommandFactory::createOne(['name' => self::CMD_CREATE]); + $commandIri = $this->findIriBy(Command::class, ['name' => self::CMD_CREATE]); + + $this->createClientWithCredentials()->request('POST', '/command-groups',['json' => [ + 'name' => self::CMD_GROUP_CREATE, + 'commands' => [ + $commandIri + ] + ]]); + + $this->assertResponseStatusCodeSame(201); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/CommandGroupOutput', + '@type' => 'CommandGroup', + 'name' => self::CMD_GROUP_CREATE, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testUpdateCommandGroup(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + CommandGroupFactory::createOne(['name' => self::CMD_GROUP_CREATE]); + $iri = $this->findIriBy(CommandGroup::class, ['name' => self::CMD_GROUP_CREATE]); + + $this->createClientWithCredentials()->request('PUT', $iri, ['json' => [ + 'name' => self::CMD_GROUP_UPDATE, + ]]); + + $this->assertResponseIsSuccessful(); + $this->assertJsonContains([ + '@id' => $iri, + 'name' => self::CMD_GROUP_UPDATE + ]); + } + + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + */ + public function testDeleteCommandGroup(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + CommandGroupFactory::createOne(['name' => self::CMD_GROUP_DELETE]); + $iri = $this->findIriBy(CommandGroup::class, ['name' => self::CMD_GROUP_DELETE]); + + $this->createClientWithCredentials()->request('DELETE', $iri); + $this->assertResponseStatusCodeSame(204); + $this->assertNull( + static::getContainer()->get('doctrine')->getRepository(CommandGroup::class)->findOneBy(['name' => self::CMD_GROUP_DELETE]) + ); + } +} \ No newline at end of file diff --git a/tests/Functional/CommandTaskTest.php b/tests/Functional/CommandTaskTest.php new file mode 100644 index 0000000..49b9555 --- /dev/null +++ b/tests/Functional/CommandTaskTest.php @@ -0,0 +1,129 @@ + self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + CommandTaskFactory::createMany(10); + + $this->createClientWithCredentials()->request('GET', '/command-tasks'); + $this->assertResponseStatusCodeSame(Response::HTTP_OK); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/CommandTask', + '@id' => '/command-tasks', + '@type' => 'hydra:Collection', + 'hydra:totalItems' => 10, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testCreateCommandTask(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + CommandFactory::createOne(['name' => self::CMD_CREATE]); + $commandIri = $this->findIriBy(Command::class, ['name' => self::CMD_CREATE]); + + $date = new \DateTimeImmutable(); + + $this->createClientWithCredentials()->request('POST', '/command-tasks',['json' => [ + 'dateTime' => $date->format('Y-m-d H:i:s'), + 'notes' => self::CMD_TASK_CREATE, + 'commands' => [ + $commandIri + ] + ]]); + + $this->assertResponseStatusCodeSame(201); + $this->assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8'); + $this->assertJsonContains([ + '@context' => '/contexts/CommandTaskOutput', + '@type' => 'CommandTask', + 'notes' => self::CMD_TASK_CREATE, + ]); + } + + /** + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + */ + public function testUpdateCommandTask(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + CommandTaskFactory::createOne(['notes' => self::CMD_TASK_CREATE]); + $iri = $this->findIriBy(CommandTask::class, ['notes' => self::CMD_TASK_CREATE]); + + $this->createClientWithCredentials()->request('PUT', $iri, ['json' => [ + 'notes' => self::CMD_TASK_UPDATE, + ]]); + + $this->assertResponseIsSuccessful(); + $this->assertJsonContains([ + '@id' => $iri, + 'notes' => self::CMD_TASK_UPDATE + ]); + } + + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws DecodingExceptionInterface + * @throws ClientExceptionInterface + */ + public function testDeleteCommandTask(): void + { + UserFactory::createOne(['username' => self::USER_ADMIN, 'roles'=> [UserGroupPermissions::ROLE_SUPER_ADMIN]]); + + CommandTaskFactory::createOne(['notes' => self::CMD_TASK_DELETE]); + $iri = $this->findIriBy(CommandTask::class, ['notes' => self::CMD_TASK_DELETE]); + + $this->createClientWithCredentials()->request('DELETE', $iri); + $this->assertResponseStatusCodeSame(204); + $this->assertNull( + static::getContainer()->get('doctrine')->getRepository(CommandTask::class)->findOneBy(['notes' => self::CMD_TASK_DELETE]) + ); + } +} \ No newline at end of file