From 9a19d9eb8da461948dbfb62596120a2794f6b917 Mon Sep 17 00:00:00 2001 From: Mathieu De Keyzer Date: Sat, 6 Jan 2024 10:38:12 +0100 Subject: [PATCH] ref: Remove EMS\CommonBundle\Common\Standard\Type --- .../src/Common/Standard/Type.php | 26 -------- .../src/Repository/LogRepository.php | 10 +-- .../src/Storage/Processor/Image.php | 2 +- .../tests/Unit/Common/Standard/TypeTest.php | 63 ------------------- .../EnvironmentController.php | 2 +- .../Controller/ElasticsearchController.php | 2 +- .../src/Controller/I18nController.php | 2 +- .../src/Controller/NotificationController.php | 2 +- .../src/Core/Document/DataLinksFactory.php | 2 +- EMS/core-bundle/src/Entity/Revision.php | 2 +- .../tests/Unit}/Standard/TypeAiTest.php | 4 +- EMS/helpers/tests/Unit/Standard/TypeTest.php | 52 +++++++++++++++ .../Document/Update/DocumentUpdater.php | 2 +- 13 files changed, 67 insertions(+), 104 deletions(-) delete mode 100644 EMS/common-bundle/src/Common/Standard/Type.php delete mode 100644 EMS/common-bundle/tests/Unit/Common/Standard/TypeTest.php rename EMS/{common-bundle/tests/Unit/Common => helpers/tests/Unit}/Standard/TypeAiTest.php (90%) diff --git a/EMS/common-bundle/src/Common/Standard/Type.php b/EMS/common-bundle/src/Common/Standard/Type.php deleted file mode 100644 index a96f3f2d5..000000000 --- a/EMS/common-bundle/src/Common/Standard/Type.php +++ /dev/null @@ -1,26 +0,0 @@ -expectException(\RuntimeException::class); - $this->expectExceptionMessage($error); - } - - $this->assertEquals($value, Type::string($value)); - } - - public function providerInteger(): array - { - return [ - [99, null], - [true, "Expect an integer got 'boolean'"], - ['test', "Expect an integer got 'string'"], - [5.6, "Expect an integer got 'double'"], - [['test'], "Expect an integer got 'array'"], - [new \stdClass(), "Expect an integer got 'object'"], - [null, "Expect an integer got 'NULL'"], - ]; - } - - /** - * @dataProvider providerInteger - */ - public function testTypeInteger($value, string $error = null): void - { - if ($error) { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage($error); - } - - $this->assertEquals($value, Type::integer($value)); - } -} diff --git a/EMS/core-bundle/src/Controller/ContentManagement/EnvironmentController.php b/EMS/core-bundle/src/Controller/ContentManagement/EnvironmentController.php index a56332e5f..1b1bb287e 100644 --- a/EMS/core-bundle/src/Controller/ContentManagement/EnvironmentController.php +++ b/EMS/core-bundle/src/Controller/ContentManagement/EnvironmentController.php @@ -3,7 +3,6 @@ namespace EMS\CoreBundle\Controller\ContentManagement; use Elasticsearch\Common\Exceptions\NoNodesAvailableException; -use EMS\CommonBundle\Common\Standard\Type; use EMS\CommonBundle\Elasticsearch\Exception\NotFoundException; use EMS\CommonBundle\Helper\EmsFields; use EMS\CoreBundle\Core\ContentType\ContentTypeRoles; @@ -31,6 +30,7 @@ use EMS\CoreBundle\Service\Mapping; use EMS\CoreBundle\Service\PublishService; use EMS\CoreBundle\Service\SearchService; +use EMS\Helpers\Standard\Type; use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\CollectionType; diff --git a/EMS/core-bundle/src/Controller/ElasticsearchController.php b/EMS/core-bundle/src/Controller/ElasticsearchController.php index c84fa5f99..926b72899 100644 --- a/EMS/core-bundle/src/Controller/ElasticsearchController.php +++ b/EMS/core-bundle/src/Controller/ElasticsearchController.php @@ -5,7 +5,6 @@ use Elasticsearch\Common\Exceptions\ElasticsearchException; use Elasticsearch\Common\Exceptions\NoNodesAvailableException; use EMS\CommonBundle\Common\EMSLink; -use EMS\CommonBundle\Common\Standard\Type; use EMS\CommonBundle\Elasticsearch\Document\EMSSource; use EMS\CommonBundle\Elasticsearch\Exception\NotFoundException; use EMS\CommonBundle\Elasticsearch\Response\Response as CommonResponse; @@ -38,6 +37,7 @@ use EMS\CoreBundle\Service\SearchService; use EMS\CoreBundle\Service\SortOptionService; use EMS\Helpers\Standard\Json; +use EMS\Helpers\Standard\Type; use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\ClickableInterface; diff --git a/EMS/core-bundle/src/Controller/I18nController.php b/EMS/core-bundle/src/Controller/I18nController.php index 0c12065d2..a9e9181f3 100644 --- a/EMS/core-bundle/src/Controller/I18nController.php +++ b/EMS/core-bundle/src/Controller/I18nController.php @@ -2,12 +2,12 @@ namespace EMS\CoreBundle\Controller; -use EMS\CommonBundle\Common\Standard\Type; use EMS\CoreBundle\Entity\Form\I18nFilter; use EMS\CoreBundle\Entity\I18n; use EMS\CoreBundle\Form\Form\I18nFormType; use EMS\CoreBundle\Form\Form\I18nType; use EMS\CoreBundle\Service\I18nService; +use EMS\Helpers\Standard\Type; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; diff --git a/EMS/core-bundle/src/Controller/NotificationController.php b/EMS/core-bundle/src/Controller/NotificationController.php index a6f935161..84bcfd5ea 100644 --- a/EMS/core-bundle/src/Controller/NotificationController.php +++ b/EMS/core-bundle/src/Controller/NotificationController.php @@ -3,7 +3,6 @@ namespace EMS\CoreBundle\Controller; use Doctrine\Persistence\ManagerRegistry; -use EMS\CommonBundle\Common\Standard\Type; use EMS\CoreBundle\Core\Dashboard\DashboardManager; use EMS\CoreBundle\Entity\ContentType; use EMS\CoreBundle\Entity\Environment; @@ -20,6 +19,7 @@ use EMS\CoreBundle\Service\EnvironmentService; use EMS\CoreBundle\Service\NotificationService; use EMS\CoreBundle\Service\PublishService; +use EMS\Helpers\Standard\Type; use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\ClickableInterface; diff --git a/EMS/core-bundle/src/Core/Document/DataLinksFactory.php b/EMS/core-bundle/src/Core/Document/DataLinksFactory.php index f0d0e9806..382e03f37 100644 --- a/EMS/core-bundle/src/Core/Document/DataLinksFactory.php +++ b/EMS/core-bundle/src/Core/Document/DataLinksFactory.php @@ -5,12 +5,12 @@ namespace EMS\CoreBundle\Core\Document; use EMS\CommonBundle\Common\EMSLink; -use EMS\CommonBundle\Common\Standard\Type; use EMS\CommonBundle\Elasticsearch\Exception\NotFoundException; use EMS\CoreBundle\Core\ContentType\ViewTypes; use EMS\CoreBundle\Form\View\DataLinkViewType; use EMS\CoreBundle\Service\ContentTypeService; use EMS\CoreBundle\Service\SearchService; +use EMS\Helpers\Standard\Type; use Symfony\Component\HttpFoundation\Request; final class DataLinksFactory diff --git a/EMS/core-bundle/src/Entity/Revision.php b/EMS/core-bundle/src/Entity/Revision.php index 3fb13e178..37d345585 100644 --- a/EMS/core-bundle/src/Entity/Revision.php +++ b/EMS/core-bundle/src/Entity/Revision.php @@ -4,7 +4,6 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; -use EMS\CommonBundle\Common\Standard\Type; use EMS\CommonBundle\Entity\CreatedModifiedTrait; use EMS\CommonBundle\Entity\IdentifierIntegerTrait; use EMS\CoreBundle\Core\Revision\RawDataTransformer; @@ -13,6 +12,7 @@ use EMS\CoreBundle\Service\Mapping; use EMS\Helpers\ArrayHelper\ArrayHelper; use EMS\Helpers\Standard\DateTime; +use EMS\Helpers\Standard\Type; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; diff --git a/EMS/common-bundle/tests/Unit/Common/Standard/TypeAiTest.php b/EMS/helpers/tests/Unit/Standard/TypeAiTest.php similarity index 90% rename from EMS/common-bundle/tests/Unit/Common/Standard/TypeAiTest.php rename to EMS/helpers/tests/Unit/Standard/TypeAiTest.php index 25d2a8ea1..a90d74189 100644 --- a/EMS/common-bundle/tests/Unit/Common/Standard/TypeAiTest.php +++ b/EMS/helpers/tests/Unit/Standard/TypeAiTest.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace EMS\CommonBundle\Tests\Unit\Common\Standard; +namespace EMS\Helpers\Tests\Unit\Standard; -use EMS\CommonBundle\Common\Standard\Type; +use EMS\Helpers\Standard\Type; use PHPUnit\Framework\TestCase; class TypeAiTest extends TestCase diff --git a/EMS/helpers/tests/Unit/Standard/TypeTest.php b/EMS/helpers/tests/Unit/Standard/TypeTest.php index 6eb6ac923..86db1ff2a 100644 --- a/EMS/helpers/tests/Unit/Standard/TypeTest.php +++ b/EMS/helpers/tests/Unit/Standard/TypeTest.php @@ -22,4 +22,56 @@ public function testString() $this->expectException(\RuntimeException::class); Type::string(11); } + + public function providerString(): array + { + return [ + ['test', null], + [true, "Expect a string got 'boolean'"], + [1, "Expect a string got 'integer'"], + [5.6, "Expect a string got 'double'"], + [['test'], "Expect a string got 'array'"], + [new \stdClass(), "Expect a string got 'object'"], + [null, "Expect a string got 'NULL'"], + ]; + } + + /** + * @dataProvider providerString + */ + public function testTypeString($value, string $error = null): void + { + if ($error) { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage($error); + } + + $this->assertEquals($value, Type::string($value)); + } + + public function providerInteger(): array + { + return [ + [99, null], + [true, "Expect an integer got 'boolean'"], + ['test', "Expect an integer got 'string'"], + [5.6, "Expect an integer got 'double'"], + [['test'], "Expect an integer got 'array'"], + [new \stdClass(), "Expect an integer got 'object'"], + [null, "Expect an integer got 'NULL'"], + ]; + } + + /** + * @dataProvider providerInteger + */ + public function testTypeInteger($value, string $error = null): void + { + if ($error) { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage($error); + } + + $this->assertEquals($value, Type::integer($value)); + } } diff --git a/elasticms-cli/src/Client/Document/Update/DocumentUpdater.php b/elasticms-cli/src/Client/Document/Update/DocumentUpdater.php index 0bd89ff8c..cbdcc447d 100644 --- a/elasticms-cli/src/Client/Document/Update/DocumentUpdater.php +++ b/elasticms-cli/src/Client/Document/Update/DocumentUpdater.php @@ -7,10 +7,10 @@ use App\CLI\Client\Data\Column\TransformContext; use App\CLI\Client\Data\Data; use EMS\CommonBundle\Common\EMSLink; -use EMS\CommonBundle\Common\Standard\Type; use EMS\CommonBundle\Contracts\CoreApi\CoreApiInterface; use EMS\CommonBundle\Contracts\CoreApi\Endpoint\Data\DataInterface; use EMS\Helpers\Standard\Json; +use EMS\Helpers\Standard\Type; use Symfony\Component\Console\Style\SymfonyStyle; final class DocumentUpdater