From a93a06652b2a1346c47c76dd809720d880ed7630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Copp=C3=A9e?= Date: Sun, 15 Oct 2023 11:40:03 +0200 Subject: [PATCH] test(common): ai generated tests (#636) --- EMS/common-bundle/phpunit.xml.dist | 6 +- .../tests/Hook/BypassFinalHook.php | 16 + .../Unit/Common/Admin/ConfigHelperAiTest.php | 98 +++++ .../tests/Unit/Common/Cache/CacheAiTest.php | 107 +++++ .../tests/Unit/Common/Cache/ConfigAiTest.php | 70 +++ .../Common/Composer/ComposerInfoAiTest.php | 40 ++ .../Common/Composer/fixtures/composer.lock | 32 ++ .../tests/Unit/Common/ConverterAiTest.php | 32 ++ .../tests/Unit/Common/ConverterTest.php | 2 + .../Common/CoreApi/CoreApiFactoryAiTest.php | 41 ++ .../Endpoint/Admin/Message/JobAiTest.php | 76 ++++ .../CoreApi/Endpoint/Data/DraftAiTest.php | 43 ++ .../CoreApi/Endpoint/Data/RevisionAiTest.php | 30 ++ .../Endpoint/File/DataExtractAiTest.php | 40 ++ .../CoreApi/Endpoint/File/FileAiTest.php | 164 +++++++ .../CoreApi/Endpoint/Form/FormAiTest.php | 56 +++ .../CoreApi/{ => Endpoint}/Form/FormTest.php | 2 +- .../CoreApi/Endpoint/Meta/MetaAiTest.php | 38 ++ .../CoreApi/Endpoint/Search/SearchAiTest.php | 150 +++++++ .../CoreApi/Endpoint/User/ProfileAiTest.php | 76 ++++ .../CoreApi/Endpoint/User/UserAiTest.php | 54 +++ .../BaseUrlNotDefinedExceptionAiTest.php | 19 + .../NotAuthenticatedExceptionAiTest.php | 34 ++ .../NotSuccessfulExceptionAiTest.php | 30 ++ .../Unit/Common/CoreApi/ResultAiTest.php | 49 +++ .../Common/CoreApi/Search/ScrollAiTest.php | 73 ++++ .../tests/Unit/Common/EMSLinkAiTest.php | 81 ++++ .../tests/Unit/Common/EMSLinkTest.php | 2 + .../Unit/Common/HttpClientFactoryAiTest.php | 31 ++ .../tests/Unit/Common/Job/JobOutputAiTest.php | 50 +++ .../Unit/Common/Log/DoctrineHandlerAiTest.php | 72 +++ .../Unit/Common/Log/LocalizedLoggerAiTest.php | 69 +++ .../Log/LocalizedLoggerFactoryAiTest.php | 33 ++ .../Metric/EmsInfoMetricCollectorAiTest.php | 48 ++ .../Metric/MetricEventListenerAiTest.php | 58 +++ .../PropertyAccess/PropertyAccessorAiTest.php | 107 +++++ .../PropertyAccess/PropertyPathAiTest.php | 72 +++ .../PropertyPathElementAiTest.php | 32 ++ .../tests/Unit/Common/Route/LoaderAiTest.php | 39 ++ .../SpreadsheetGeneratorServiceAiTest.php | 96 ++++ .../Unit/Common/SpreadsheetGeneratorTest.php | 2 + .../Unit/Common/Standard/Base64AiTest.php | 36 ++ .../Unit/Common/Standard/DateTimeAiTest.php | 46 ++ .../tests/Unit/Common/Standard/HashAiTest.php | 45 ++ .../Unit/Common/Standard/ImageAiTest.php | 48 ++ .../tests/Unit/Common/Standard/JsonAiTest.php | 65 +++ .../tests/Unit/Common/Standard/TypeAiTest.php | 39 ++ .../Unit/Common/Standard/fixtures/image.png | Bin 0 -> 16625 bytes .../Factory/StoreDataCacheFactoryAiTest.php | 53 +++ .../Factory/StoreDataEntityFactoryAiTest.php | 53 +++ .../StoreDataFileSystemFactoryAiTest.php | 50 +++ .../Service/StoreDataCacheServiceAiTest.php | 72 +++ .../Service/StoreDataEntityServiceAiTest.php | 74 ++++ .../StoreDataFileSystemServiceAiTest.php | 57 +++ .../StoreData/StoreDataHelperAiTest.php | 43 ++ .../StoreData/StoreDataManagerAiTest.php | 78 ++++ .../tests/Unit/Common/Text/EmsHtmlAiTest.php | 43 ++ .../Elasticsearch/Document/DocumentAiTest.php | 77 ++++ .../Document/DocumentCollectionAiTest.php | 62 +++ .../Document/DocumentCollectionTest.php | 2 + .../Elasticsearch/Document/DocumentTest.php | 2 + .../Document/EMSSourceAiTest.php | 81 ++++ .../Elasticsearch/Request/RequestAiTest.php | 41 ++ .../Elasticsearch/Response/ResponseAiTest.php | 132 ++++++ .../tests/Unit/Helper/CacheTest.php | 2 + .../tests/Unit/Helper/Text/EncoderTest.php | 2 + .../tests/Unit/Json/JsonMenuNestedTest.php | 2 + .../tests/Unit/Search/SearchAiTest.php | 145 +++++++ .../tests/Unit/Storage/StorageManagerTest.php | 2 + .../tests/Unit/Twig/AssetRuntimeTest.php | 2 + .../tests/Unit/Twig/TextRuntimeTest.php | 2 + composer.json | 1 + composer.lock | 410 ++++++++++-------- phpunit.xml.dist | 1 + 74 files changed, 3758 insertions(+), 180 deletions(-) create mode 100644 EMS/common-bundle/tests/Hook/BypassFinalHook.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Admin/ConfigHelperAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Cache/CacheAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Cache/ConfigAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Composer/ComposerInfoAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Composer/fixtures/composer.lock create mode 100644 EMS/common-bundle/tests/Unit/Common/ConverterAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/CoreApiFactoryAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Admin/Message/JobAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Data/DraftAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Data/RevisionAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/File/DataExtractAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/File/FileAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Form/FormAiTest.php rename EMS/common-bundle/tests/Unit/Common/CoreApi/{ => Endpoint}/Form/FormTest.php (94%) create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Meta/MetaAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Search/SearchAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/User/ProfileAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/User/UserAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/BaseUrlNotDefinedExceptionAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/NotAuthenticatedExceptionAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/NotSuccessfulExceptionAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/ResultAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/CoreApi/Search/ScrollAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/EMSLinkAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/HttpClientFactoryAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Job/JobOutputAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Log/DoctrineHandlerAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Log/LocalizedLoggerAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Log/LocalizedLoggerFactoryAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Metric/EmsInfoMetricCollectorAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Metric/MetricEventListenerAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/PropertyAccess/PropertyAccessorAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/PropertyAccess/PropertyPathAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/PropertyAccess/PropertyPathElementAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Route/LoaderAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/SpreadsheetGeneratorServiceAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Standard/Base64AiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Standard/DateTimeAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Standard/HashAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Standard/ImageAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Standard/JsonAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Standard/TypeAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Standard/fixtures/image.png create mode 100644 EMS/common-bundle/tests/Unit/Common/StoreData/Factory/StoreDataCacheFactoryAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/StoreData/Factory/StoreDataEntityFactoryAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/StoreData/Factory/StoreDataFileSystemFactoryAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/StoreData/Service/StoreDataCacheServiceAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/StoreData/Service/StoreDataEntityServiceAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/StoreData/Service/StoreDataFileSystemServiceAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/StoreData/StoreDataHelperAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/StoreData/StoreDataManagerAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Common/Text/EmsHtmlAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Elasticsearch/Document/DocumentAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Elasticsearch/Document/DocumentCollectionAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Elasticsearch/Document/EMSSourceAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Elasticsearch/Request/RequestAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Elasticsearch/Response/ResponseAiTest.php create mode 100644 EMS/common-bundle/tests/Unit/Search/SearchAiTest.php diff --git a/EMS/common-bundle/phpunit.xml.dist b/EMS/common-bundle/phpunit.xml.dist index 0a24d56db..c8916301d 100644 --- a/EMS/common-bundle/phpunit.xml.dist +++ b/EMS/common-bundle/phpunit.xml.dist @@ -28,4 +28,8 @@ - \ No newline at end of file + + + + + diff --git a/EMS/common-bundle/tests/Hook/BypassFinalHook.php b/EMS/common-bundle/tests/Hook/BypassFinalHook.php new file mode 100644 index 000000000..2a0cd1513 --- /dev/null +++ b/EMS/common-bundle/tests/Hook/BypassFinalHook.php @@ -0,0 +1,16 @@ +config = $this->createMock(ConfigInterface::class); + $this->tempDir = \sys_get_temp_dir().DIRECTORY_SEPARATOR.\uniqid('config_test_', true); + $this->configHelper = new ConfigHelper($this->config, $this->tempDir); + } + + protected function tearDown(): void + { + // Cleanup temporary directory + \array_map('unlink', \glob("$this->tempDir/*.*")); + \rmdir($this->tempDir); + } + + public function testUpdate(): void + { + $this->config->expects($this->once())->method('index')->willReturn(['config1', 'config2']); + $this->config->expects($this->exactly(2))->method('get')->willReturnOnConsecutiveCalls(['key1' => 'value1'], ['key2' => 'value2']); + + $this->configHelper->update(); + + $this->assertFileExists($this->tempDir.DIRECTORY_SEPARATOR.'config1.json'); + $this->assertFileExists($this->tempDir.DIRECTORY_SEPARATOR.'config2.json'); + } + + public function testSave(): void + { + $configData = ['key' => 'value']; + $this->configHelper->save('testConfig', $configData); + + $this->assertFileExists($this->tempDir.DIRECTORY_SEPARATOR.'testConfig.json'); + $this->assertEquals(\json_encode($configData, JSON_PRETTY_PRINT), \file_get_contents($this->tempDir.DIRECTORY_SEPARATOR.'testConfig.json')); + } + + public function testLocal(): void + { + \touch($this->tempDir.DIRECTORY_SEPARATOR.'config1.json'); + \touch($this->tempDir.DIRECTORY_SEPARATOR.'config2.json'); + + $localConfigs = $this->configHelper->local(); + + $this->assertEquals(['config1', 'config2'], $localConfigs); + } + + public function testRemote(): void + { + $this->config->expects($this->once())->method('index')->willReturn(['config1', 'config2']); + + $remoteConfigs = $this->configHelper->remote(); + + $this->assertEquals(['config1', 'config2'], $remoteConfigs); + } + + public function testNeedUpdate(): void + { + $this->config->expects($this->exactly(2))->method('get')->willReturnOnConsecutiveCalls(['key1' => 'value1'], ['key2' => 'value2']); + + \file_put_contents($this->tempDir.DIRECTORY_SEPARATOR.'config1.json', \json_encode(['key1' => 'value1'])); + \file_put_contents($this->tempDir.DIRECTORY_SEPARATOR.'config2.json', \json_encode(['key2' => 'value2_changed'])); + + $configsToUpdate = $this->configHelper->needUpdate(['config1', 'config2']); + + $this->assertEquals(['config2'], $configsToUpdate); + } + + public function testDeleteConfigs(): void + { + $this->config->expects($this->exactly(2))->method('delete'); + + $this->configHelper->deleteConfigs(['config1', 'config2']); + } + + public function testUpdateConfigs(): void + { + $this->config->expects($this->exactly(2))->method('update'); + + \file_put_contents($this->tempDir.DIRECTORY_SEPARATOR.'config1.json', \json_encode(['key1' => 'value1'])); + \file_put_contents($this->tempDir.DIRECTORY_SEPARATOR.'config2.json', \json_encode(['key2' => 'value2'])); + + $this->configHelper->updateConfigs(['config1', 'config2']); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Cache/CacheAiTest.php b/EMS/common-bundle/tests/Unit/Common/Cache/CacheAiTest.php new file mode 100644 index 000000000..cb32815df --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Cache/CacheAiTest.php @@ -0,0 +1,107 @@ +cacheDir = \sys_get_temp_dir().DIRECTORY_SEPARATOR.\uniqid('cache_test_', true); + \mkdir($this->cacheDir); + } + + protected function removeDirectory($path): void + { + $files = \glob($path.'/*'); + foreach ($files as $file) { + \is_dir($file) ? $this->removeDirectory($file) : \unlink($file); + } + \rmdir($path); + } + + protected function tearDown(): void + { + \array_map('unlink', \glob("$this->cacheDir/*.*")); + $this->removeDirectory($this->cacheDir); + } + + public function testIsApc(): void + { + $this->cache = new Cache(['type' => Cache::TYPE_APC, 'prefix' => 'test_prefix_'], $this->cacheDir); + $this->assertTrue($this->cache->isApc()); + } + + public function testIsRedis(): void + { + $this->cache = new Cache(['type' => Cache::TYPE_REDIS, 'prefix' => 'test_prefix_', 'redis' => ['host' => '127.0.0.1', 'port' => 6379]], $this->cacheDir); + $this->assertTrue($this->cache->isRedis()); + } + + public function testIsFilesystem(): void + { + $this->cache = new Cache(['type' => Cache::TYPE_FILE_SYSTEM, 'prefix' => 'test_prefix_'], $this->cacheDir); + $this->assertTrue($this->cache->isFilesystem()); + } + + public function testGetType(): void + { + $this->cache = new Cache(['type' => Cache::TYPE_APC, 'prefix' => 'test_prefix_'], $this->cacheDir); + $this->assertEquals(Cache::TYPE_APC, $this->cache->getType()); + } + + public function testGetItem(): void + { + $this->cache = new Cache(['type' => Cache::TYPE_FILE_SYSTEM, 'prefix' => 'test_prefix_'], $this->cacheDir); + $item = $this->cache->getItem('test_key'); + $this->assertFalse($item->isHit()); + } + + public function testSave(): void + { + $this->cache = new Cache(['type' => Cache::TYPE_FILE_SYSTEM, 'prefix' => 'test_prefix_'], $this->cacheDir); + $item = $this->cache->getItem('test_key'); + $item->set('test_value'); + $this->cache->save($item); + + $savedItem = $this->cache->getItem('test_key'); + $this->assertTrue($savedItem->isHit()); + $this->assertEquals('test_value', $savedItem->get()); + } + + public function testDelete(): void + { + $this->cache = new Cache(['type' => Cache::TYPE_FILE_SYSTEM, 'prefix' => 'test_prefix_'], $this->cacheDir); + $item = $this->cache->getItem('test_key'); + $item->set('test_value'); + $this->cache->save($item); + + $this->cache->delete('test_key'); + $deletedItem = $this->cache->getItem('test_key'); + $this->assertFalse($deletedItem->isHit()); + } + + public function testClear(): void + { + $this->cache = new Cache(['type' => Cache::TYPE_FILE_SYSTEM, 'prefix' => 'test_prefix_'], $this->cacheDir); + $item1 = $this->cache->getItem('test_key1'); + $item1->set('test_value1'); + $this->cache->save($item1); + + $item2 = $this->cache->getItem('test_key2'); + $item2->set('test_value2'); + $this->cache->save($item2); + + $this->cache->clear(); + + $this->assertFalse($this->cache->getItem('test_key1')->isHit()); + $this->assertFalse($this->cache->getItem('test_key2')->isHit()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Cache/ConfigAiTest.php b/EMS/common-bundle/tests/Unit/Common/Cache/ConfigAiTest.php new file mode 100644 index 000000000..026e820a6 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Cache/ConfigAiTest.php @@ -0,0 +1,70 @@ + Cache::TYPE_REDIS, + 'prefix' => 'test_prefix_', + 'redis' => [ + 'host' => 'localhost', + 'port' => 6379, + ], + ]); + + $this->assertEquals(Cache::TYPE_REDIS, $config->type); + $this->assertEquals('test_prefix_', $config->prefix); + $this->assertEquals('localhost', $config->redis['host']); + $this->assertEquals(6379, $config->redis['port']); + } + + public function testDefaultRedisConfig(): void + { + $config = new Config([ + 'type' => Cache::TYPE_REDIS, + 'prefix' => 'test_prefix_', + ]); + + $this->assertEquals('localhost', $config->redis['host']); + $this->assertEquals(6379, $config->redis['port']); + } + + public function testInvalidType(): void + { + $this->expectException(\InvalidArgumentException::class); + new Config([ + 'type' => 'invalid_type', + 'prefix' => 'test_prefix_', + ]); + } + + public function testMissingRequiredFields(): void + { + $this->expectException(\InvalidArgumentException::class); + new Config([ + 'type' => Cache::TYPE_REDIS, + ]); + } + + public function testInvalidRedisPort(): void + { + $this->expectException(\InvalidArgumentException::class); + new Config([ + 'type' => Cache::TYPE_REDIS, + 'prefix' => 'test_prefix_', + 'redis' => [ + 'host' => 'localhost', + 'port' => 'invalid_port', + ], + ]); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Composer/ComposerInfoAiTest.php b/EMS/common-bundle/tests/Unit/Common/Composer/ComposerInfoAiTest.php new file mode 100644 index 000000000..40646dc5e --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Composer/ComposerInfoAiTest.php @@ -0,0 +1,40 @@ +composerInfo = new ComposerInfo($projectDir); + } + + public function testBuild(): void + { + $this->composerInfo->build(); + + $expectedPackages = [ + 'core' => '1.0.0', + 'client' => '1.1.0', + 'common' => '1.2.0', + 'form' => '1.3.0', + 'submission' => '1.4.0', + 'symfony' => '5.3.0', + ]; + + $this->assertEquals($expectedPackages, $this->composerInfo->getVersionPackages()); + } + + public function testGetVersionPackagesWithoutBuild(): void + { + $this->assertEmpty($this->composerInfo->getVersionPackages()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Composer/fixtures/composer.lock b/EMS/common-bundle/tests/Unit/Common/Composer/fixtures/composer.lock new file mode 100644 index 000000000..d4b3387d7 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Composer/fixtures/composer.lock @@ -0,0 +1,32 @@ +{ + "packages": [ + { + "name": "elasticms/core-bundle", + "version": "1.0.0" + }, + { + "name": "elasticms/client-helper-bundle", + "version": "1.1.0" + }, + { + "name": "elasticms/common-bundle", + "version": "1.2.0" + }, + { + "name": "elasticms/form-bundle", + "version": "1.3.0" + }, + { + "name": "elasticms/submission-bundle", + "version": "1.4.0" + }, + { + "name": "symfony/framework-bundle", + "version": "5.3.0" + }, + { + "name": "unrelated/package", + "version": "2.0.0" + } + ] +} diff --git a/EMS/common-bundle/tests/Unit/Common/ConverterAiTest.php b/EMS/common-bundle/tests/Unit/Common/ConverterAiTest.php new file mode 100644 index 000000000..5afe8aa05 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/ConverterAiTest.php @@ -0,0 +1,32 @@ +assertEquals('hello-world', Converter::toAscii('Hello World')); + $this->assertEquals('emsasset', Converter::toAscii('ems://asset')); + $this->assertEquals('a-e-i-o-u', Converter::toAscii('À É Í Ó Ú')); + } + + public function testFormatBytes(): void + { + $this->assertEquals('1 B', Converter::formatBytes(1)); + $this->assertEquals('1 KB', Converter::formatBytes(1024)); + $this->assertEquals('1 MB', Converter::formatBytes(1024 * 1024)); + } + + public function testStringify(): void + { + $this->assertEquals('hello', Converter::stringify('hello')); + $this->assertEquals('123', Converter::stringify(123)); + $this->assertEquals('{"key":"value"}', Converter::stringify(['key' => 'value'])); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/ConverterTest.php b/EMS/common-bundle/tests/Unit/Common/ConverterTest.php index b97e87b73..3e5ffe2b6 100644 --- a/EMS/common-bundle/tests/Unit/Common/ConverterTest.php +++ b/EMS/common-bundle/tests/Unit/Common/ConverterTest.php @@ -1,5 +1,7 @@ logger = $this->createMock(LoggerInterface::class); + $this->storageManager = $this->createMock(StorageManager::class); + $this->factory = new CoreApiFactory($this->logger, $this->storageManager); + } + + public function testCreate(): void + { + $baseUrl = 'http://example.com'; + $coreApi = $this->factory->create($baseUrl); + + $this->assertInstanceOf(CoreApi::class, $coreApi); + + $reflection = new \ReflectionClass($coreApi); + $clientProperty = $reflection->getProperty('client'); + $client = $clientProperty->getValue($coreApi); + + $this->assertInstanceOf(Client::class, $client); + $this->assertEquals($baseUrl, $client->getBaseUrl()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Admin/Message/JobAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Admin/Message/JobAiTest.php new file mode 100644 index 000000000..5fbc0036b --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Admin/Message/JobAiTest.php @@ -0,0 +1,76 @@ + true, + 'success' => true, + 'message' => 'Some message', + 'job_id' => '12345', + 'output' => 'Some output', + 'command' => 'Some command', + ]; + + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn($data); + + $job = new Job($result); + + $this->assertSame('12345', $job->getJobId()); + $this->assertSame($result, $job->getResult()); + $this->assertSame('Some command', $job->getCommand()); + $this->assertSame('Some output', $job->getOutput()); + } + + public function testConstructWithMissingCommand(): void + { + $data = [ + 'acknowledged' => true, + 'success' => true, + 'message' => 'Some message', + 'job_id' => '12345', + 'output' => 'Some output', + 'command' => null, + ]; + + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn($data); + + $job = new Job($result); + + $this->assertSame('12345', $job->getJobId()); + $this->assertSame($result, $job->getResult()); + $this->assertSame('list', $job->getCommand()); + $this->assertSame('Some output', $job->getOutput()); + } + + public function testConstructWithInvalidData(): void + { + $this->expectException(InvalidOptionsExceptionAlias::class); + + $data = [ + 'acknowledged' => true, + 'success' => true, + 'message' => 'Some message', + 'job_id' => 12345, // Invalid type + 'output' => 'Some output', + 'command' => 'Some command', + ]; + + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn($data); + + new Job($result); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Data/DraftAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Data/DraftAiTest.php new file mode 100644 index 000000000..727309e34 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Data/DraftAiTest.php @@ -0,0 +1,43 @@ + 123, + 'ouuid' => 'test-ouuid', + ]; + + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn($resultData); + + $draft = new Draft($result); + + $this->assertEquals(123, $draft->getRevisionId()); + $this->assertEquals('test-ouuid', $draft->getOuuid()); + } + + public function testConstructWithMissingOuuid(): void + { + $resultData = [ + 'revision_id' => 456, + ]; + + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn($resultData); + + $draft = new Draft($result); + + $this->assertEquals(456, $draft->getRevisionId()); + $this->assertNull($draft->getOuuid()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Data/RevisionAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Data/RevisionAiTest.php new file mode 100644 index 000000000..692d82b27 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Data/RevisionAiTest.php @@ -0,0 +1,30 @@ + 123, + 'ouuid' => 'test-ouuid', + 'revision' => ['key' => 'value'], + ]; + + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn($resultData); + + $revision = new Revision($result); + + $this->assertEquals(123, $revision->getRevisionId()); + $this->assertEquals('test-ouuid', $revision->getOuuid()); + $this->assertEquals(['key' => 'value'], $revision->getRawData()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/File/DataExtractAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/File/DataExtractAiTest.php new file mode 100644 index 000000000..f7f5ed76e --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/File/DataExtractAiTest.php @@ -0,0 +1,40 @@ +client = $this->createMock(Client::class); + $this->dataExtract = new DataExtract($this->client); + } + + public function testGet(): void + { + $hash = 'sample-hash'; + $expectedData = ['key' => 'value']; + + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn($expectedData); + + $this->client->expects($this->once()) + ->method('get') + ->with('/api/extract-data/get/'.$hash) + ->willReturn($result); + + $data = $this->dataExtract->get($hash); + + $this->assertEquals($expectedData, $data); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/File/FileAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/File/FileAiTest.php new file mode 100644 index 000000000..aab6c0bd2 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/File/FileAiTest.php @@ -0,0 +1,164 @@ +client = $this->createMock(Client::class); + $this->storageManager = $this->createMock(StorageManager::class); + $this->file = new File($this->client, $this->storageManager); + } + + public function testUploadStream(): void + { + $stream = $this->createMock(StreamInterface::class); + $stream->method('getSize')->willReturn(10); + $stream->method('eof')->willReturn(true); + + $this->storageManager->expects($this->once()) + ->method('computeStreamHash') + ->willReturn('sample-hash'); + + $this->client->expects($this->once()) + ->method('post') + ->willReturn($this->createMockResult(['uploaded' => 10])); + + $this->client->expects($this->once()) + ->method('head') + ->willReturn(false); + + $hash = $this->file->uploadStream($stream, 'filename.txt', 'text/plain'); + + $this->assertEquals('sample-hash', $hash); + } + + public function testDownloadLink(): void + { + $hash = 'sample-hash'; + $expectedLink = \sprintf('%s/data/file/%s', $this->client->getBaseUrl(), $hash); + + $result = $this->file->downloadLink($hash); + + $this->assertEquals($expectedLink, $result); + } + + public function testHashFile(): void + { + $filename = 'sample.txt'; + $hash = 'sample-hash'; + + $this->storageManager->expects($this->once()) + ->method('computeFileHash') + ->with($filename) + ->willReturn($hash); + + $result = $this->file->hashFile($filename); + + $this->assertEquals($hash, $result); + } + + public function testHashStream(): void + { + $stream = new Stream(\fopen('php://temp', 'r+')); + \fwrite($stream->detach(), 'sample-content'); + $hash = 'sample-hash'; + + $this->storageManager->expects($this->once()) + ->method('computeStreamHash') + ->with($stream) + ->willReturn($hash); + + $result = $this->file->hashStream($stream); + + $this->assertEquals($hash, $result); + } + + public function testHeadFile(): void + { + $filename = 'sample.txt'; + $hash = 'sample-hash'; + + $this->storageManager->expects($this->once()) + ->method('computeFileHash') + ->with($filename) + ->willReturn($hash); + + $this->client->expects($this->once()) + ->method('head') + ->with('/api/file/'.$hash) + ->willReturn(true); + + $result = $this->file->headFile($filename); + + $this->assertTrue($result); + } + + public function testHeadHash(): void + { + $hash = 'sample-hash'; + + $this->client->expects($this->once()) + ->method('head') + ->with('/api/file/'.$hash) + ->willReturn(true); + + $result = $this->file->headHash($hash); + + $this->assertTrue($result); + } + + public function testInitUpload(): void + { + $hash = 'sample-hash'; + $size = 12345; + $filename = 'sample.txt'; + $mimeType = 'text/plain'; + + $this->client->expects($this->once()) + ->method('post') + ->willReturn($this->createMockResult(['uploaded' => 0])); + + $result = $this->file->initUpload($hash, $size, $filename, $mimeType); + + $this->assertEquals(0, $result); + } + + public function testAddChunk(): void + { + $hash = 'sample-hash'; + $chunk = 'sample-chunk'; + + $this->client->expects($this->once()) + ->method('postBody') + ->willReturn($this->createMockResult(['uploaded' => \strlen($chunk)])); + + $result = $this->file->addChunk($hash, $chunk); + + $this->assertEquals(\strlen($chunk), $result); + } + + private function createMockResult(array $data): Result + { + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn($data); + $result->method('isSuccess')->willReturn(true); + + return $result; + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Form/FormAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Form/FormAiTest.php new file mode 100644 index 000000000..717fa0861 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Form/FormAiTest.php @@ -0,0 +1,56 @@ +client = $this->createMock(Client::class); + $this->form = new Form($this->client); + } + + public function testCreateVerification(): void + { + $resultData = ['code' => '123456']; + + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn($resultData); + + $this->client->expects($this->once()) + ->method('post') + ->with('api/forms/verifications', ['value' => 'test-value']) + ->willReturn($result); + + $code = $this->form->createVerification('test-value'); + + $this->assertEquals('123456', $code); + } + + public function testGetVerification(): void + { + $resultData = ['code' => '654321']; + + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn($resultData); + + $this->client->expects($this->once()) + ->method('get') + ->with('api/forms/verifications', ['value' => 'test-value']) + ->willReturn($result); + + $code = $this->form->getVerification('test-value'); + + $this->assertEquals('654321', $code); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Form/FormTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Form/FormTest.php similarity index 94% rename from EMS/common-bundle/tests/Unit/Common/CoreApi/Form/FormTest.php rename to EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Form/FormTest.php index e2f38dd60..2bb0ba2e9 100644 --- a/EMS/common-bundle/tests/Unit/Common/CoreApi/Form/FormTest.php +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Form/FormTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace EMS\CommonBundle\Tests\Unit\Common\CoreApi\Form; +namespace EMS\CommonBundle\Tests\Unit\Common\CoreApi\Endpoint\Form; use EMS\CommonBundle\Common\CoreApi\Client; use EMS\CommonBundle\Common\CoreApi\Endpoint\Form\Form; diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Meta/MetaAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Meta/MetaAiTest.php new file mode 100644 index 000000000..78b52b34b --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Meta/MetaAiTest.php @@ -0,0 +1,38 @@ +client = $this->createMock(Client::class); + $this->meta = new Meta($this->client); + } + + public function testGetDefaultContentTypeEnvironmentAlias(): void + { + $contentTypeName = 'testType'; + + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn(['alias' => 'testAlias']); + + $this->client->method('get') + ->with(\implode('/', ['api', 'meta', 'content-type', $contentTypeName])) + ->willReturn($result); + + $alias = $this->meta->getDefaultContentTypeEnvironmentAlias($contentTypeName); + + $this->assertEquals('testAlias', $alias); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Search/SearchAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Search/SearchAiTest.php new file mode 100644 index 000000000..7575adadc --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/Search/SearchAiTest.php @@ -0,0 +1,150 @@ +client = $this->createMock(Client::class); + $this->search = new Search($this->client); + } + + public function testSearch(): void + { + $searchObject = new SearchObject(['index1'], new MatchAll()); + + $this->client->expects($this->once()) + ->method('post') + ->with('/api/search/search', ['search' => $searchObject->serialize()]) + ->willReturn($this->createMockResult(['data' => 'test'])); + + $response = $this->search->search($searchObject); + + $this->assertInstanceOf(ResponseInterface::class, $response); + } + + public function testCount(): void + { + $searchObject = new SearchObject(['index1'], new MatchAll()); + + $this->client->expects($this->once()) + ->method('post') + ->with('/api/search/count', ['search' => $searchObject->serialize()]) + ->willReturn($this->createMockResult(['count' => 5])); + + $count = $this->search->count($searchObject); + + $this->assertEquals(5, $count); + } + + public function testVersion(): void + { + $this->client->expects($this->once()) + ->method('get') + ->with('/api/search/version') + ->willReturn($this->createMockResult(['version' => '1.0.0'])); + + $version = $this->search->version(); + + $this->assertEquals('1.0.0', $version); + } + + public function testHealthStatus(): void + { + $this->client->expects($this->once()) + ->method('get') + ->with('/api/search/health-status') + ->willReturn($this->createMockResult(['status' => 'healthy'])); + + $status = $this->search->healthStatus(); + + $this->assertEquals('healthy', $status); + } + + public function testRefresh(): void + { + $this->client->expects($this->once()) + ->method('post') + ->with('/api/search/refresh', ['index' => 'test_index']) + ->willReturn($this->createMockResult(['success' => true])); + + $success = $this->search->refresh('test_index'); + + $this->assertTrue($success); + } + + public function testGetIndicesFromAlias(): void + { + $this->client->expects($this->once()) + ->method('post') + ->with('/api/search/indices-from-alias', ['alias' => 'test_alias']) + ->willReturn($this->createMockResult(['indices' => ['index1', 'index2']])); + + $indices = $this->search->getIndicesFromAlias('test_alias'); + + $this->assertEquals(['index1', 'index2'], $indices); + } + + public function testGetAliasesFromIndex(): void + { + $this->client->expects($this->once()) + ->method('post') + ->with('/api/search/aliases-from-index', ['index' => 'test_index']) + ->willReturn($this->createMockResult(['aliases' => ['alias1', 'alias2']])); + + $aliases = $this->search->getAliasesFromIndex('test_index'); + + $this->assertEquals(['alias1', 'alias2'], $aliases); + } + + public function testGetDocument(): void + { + $documentData = [ + '_index' => 'test_index', + '_id' => '123', + '_source' => [ + 'field' => 'value', + '_contenttype' => 'test_content_type', + ], + ]; + + $this->client->expects($this->once()) + ->method('post') + ->with('/api/search/document', [ + 'index' => 'test_index', + 'content-type' => 'test_content_type', + 'ouuid' => '123', + 'source-includes' => [], + 'sources-excludes' => [], + ]) + ->willReturn($this->createMockResult($documentData)); + + $document = $this->search->getDocument('test_index', 'test_content_type', '123'); + + $this->assertInstanceOf(Document::class, $document); + $this->assertEquals('123', $document->getId()); + } + + private function createMockResult(array $data): Result + { + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn($data); + + return $result; + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/User/ProfileAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/User/ProfileAiTest.php new file mode 100644 index 000000000..5dfd558ae --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/User/ProfileAiTest.php @@ -0,0 +1,76 @@ + 1, + 'username' => 'testUser', + 'email' => 'test@example.com', + 'displayName' => 'Test User', + 'roles' => ['ROLE_USER', 'ROLE_ADMIN'], + 'circles' => ['circle1', 'circle2'], + 'lastLogin' => '2023-10-06T15:00:00+00:00', + 'userOptions' => [ + 'option1' => 'ok', + 'option2' => 'nope', + 'customOption' => [ + 'customOption1' => 'nope', + 'customOption2' => 'ok', + ], + ], + ]; + $this->profile = new Profile($data); + } + + public function testGetId(): void + { + $this->assertSame(1, $this->profile->getId()); + } + + public function testGetUsername(): void + { + $this->assertSame('testUser', $this->profile->getUsername()); + } + + public function testGetEmail(): void + { + $this->assertSame('test@example.com', $this->profile->getEmail()); + } + + public function testGetDisplayName(): void + { + $this->assertSame('Test User', $this->profile->getDisplayName()); + } + + public function testGetRoles(): void + { + $this->assertSame(['ROLE_USER', 'ROLE_ADMIN'], $this->profile->getRoles()); + } + + public function testGetCircles(): void + { + $this->assertSame(['circle1', 'circle2'], $this->profile->getCircles()); + } + + public function testGetLastLogin(): void + { + $expectedDate = \DateTimeImmutable::createFromFormat(\DateTimeImmutable::ATOM, '2023-10-06T15:00:00+00:00'); + $this->assertEquals($expectedDate, $this->profile->getLastLogin()); + } + + public function testGetUserOptions(): void + { + $this->assertSame(['option1' => 'ok', 'option2' => 'nope', 'customOption' => ['customOption1' => 'nope', 'customOption2' => 'ok']], $this->profile->getUserOptions()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/User/UserAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/User/UserAiTest.php new file mode 100644 index 000000000..116a915fa --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Endpoint/User/UserAiTest.php @@ -0,0 +1,54 @@ +client = $this->createMock(Client::class); + $this->user = new User($this->client); + } + + public function testGetProfiles(): void + { + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn([ + ['id' => 1, 'username' => 'user1', 'email' => 'user1@example.com'], + ['id' => 2, 'username' => 'user2', 'email' => 'user2@example.com'], + ]); + + $this->client->method('get')->with('/api/user-profiles')->willReturn($result); + + $profiles = $this->user->getProfiles(); + + $this->assertCount(2, $profiles); + $this->assertInstanceOf(Profile::class, $profiles[0]); + $this->assertEquals('user1', $profiles[0]->getUsername()); + $this->assertEquals('user2', $profiles[1]->getUsername()); + } + + public function testGetProfileAuthenticated(): void + { + $result = $this->createMock(Result::class); + $result->method('getData')->willReturn(['id' => 1, 'username' => 'user1', 'email' => 'user1@example.com']); + + $this->client->method('get')->with('/api/user-profile')->willReturn($result); + + $profile = $this->user->getProfileAuthenticated(); + + $this->assertInstanceOf(Profile::class, $profile); + $this->assertEquals('user1', $profile->getUsername()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/BaseUrlNotDefinedExceptionAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/BaseUrlNotDefinedExceptionAiTest.php new file mode 100644 index 000000000..42cfb3964 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/BaseUrlNotDefinedExceptionAiTest.php @@ -0,0 +1,19 @@ +assertEquals($expectedMessage, $exception->getMessage()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/NotAuthenticatedExceptionAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/NotAuthenticatedExceptionAiTest.php new file mode 100644 index 000000000..1c63fde9d --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/NotAuthenticatedExceptionAiTest.php @@ -0,0 +1,34 @@ +createMock(ResponseInterface::class); + $response->method('getInfo') + ->willReturn([ + 'http_code' => $httpCode, + 'http_method' => $httpMethod, + 'url' => $url, + ]); + $response->method('getStatusCode')->willReturn($httpCode); + + $exception = new NotAuthenticatedException($response); + + $expectedMessage = \sprintf('%s Unauthorized for [%s] %s', $httpCode, $httpMethod, $url); + $this->assertEquals($expectedMessage, $exception->getMessage()); + $this->assertEquals($httpCode, $exception->getCode()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/NotSuccessfulExceptionAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/NotSuccessfulExceptionAiTest.php new file mode 100644 index 000000000..37a741451 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Exception/NotSuccessfulExceptionAiTest.php @@ -0,0 +1,30 @@ +createMock(ResponseInterface::class); + $response->method('getInfo') + ->willReturn([ + 'http_method' => 'GET', + 'url' => 'https://example.com/api/test', + ]); + $response->method('getStatusCode') + ->willReturn(404); + + $exception = new NotSuccessfulException($response); + + $expectedMessage = '[GET] https://example.com/api/test was not successful! (Check logs!)'; + $this->assertEquals($expectedMessage, $exception->getMessage()); + $this->assertEquals(404, $exception->getCode()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/ResultAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/ResultAiTest.php new file mode 100644 index 000000000..8393a5da2 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/ResultAiTest.php @@ -0,0 +1,49 @@ +response = $this->createMock(ResponseInterface::class); + $this->logger = $this->createMock(LoggerInterface::class); + } + + public function testGetData(): void + { + $data = ['someKey' => 'someValue']; + $this->response->method('getContent')->willReturn(\json_encode($data)); + + $result = new Result($this->response, $this->logger); + $this->assertEquals($data, $result->getData()); + } + + public function testIsSuccess(): void + { + $data = ['success' => true]; + $this->response->method('getContent')->willReturn(\json_encode($data)); + + $result = new Result($this->response, $this->logger); + $this->assertTrue($result->isSuccess()); + } + + public function testIsAcknowledged(): void + { + $data = ['acknowledged' => true]; + $this->response->method('getContent')->willReturn(\json_encode($data)); + + $result = new Result($this->response, $this->logger); + $this->assertTrue($result->isAcknowledged()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/CoreApi/Search/ScrollAiTest.php b/EMS/common-bundle/tests/Unit/Common/CoreApi/Search/ScrollAiTest.php new file mode 100644 index 000000000..73d850e11 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/CoreApi/Search/ScrollAiTest.php @@ -0,0 +1,73 @@ +client = $this->createMock(Client::class); + $this->search = $this->createMock(Search::class); + } + + public function testCurrent(): void + { + $document = $this->createMock(Document::class); + $response = $this->createConfiguredMock(ResponseInterface::class, [ + 'getDocument' => $document, + 'getTotalDocuments' => 1, + ]); + + $this->client + ->method('post') + ->willReturn($this->createConfiguredMock(Result::class, ['getData' => []])); + + $scroll = new Scroll($this->client, $this->search); + $reflection = new \ReflectionClass($scroll); + $property = $reflection->getProperty('currentResponse'); + $property->setValue($scroll, $response); + + $this->assertSame($document, $scroll->current()); + } + + public function testKeyInvalidScroll(): void + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Invalid scroll'); + + $scroll = new Scroll($this->client, $this->search); + $scroll->key(); + } + + public function testRewind(): void + { + $this->client + ->expects($this->once()) + ->method('post') + ->with('/api/search/init-scroll', [ + 'search' => '{}', + 'expire-time' => '3m', + ]) + ->willReturn($this->createConfiguredMock(Result::class, ['getData' => []])); + + $this->search + ->method('serialize') + ->willReturn('{}'); + + $scroll = new Scroll($this->client, $this->search); + $scroll->rewind(); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/EMSLinkAiTest.php b/EMS/common-bundle/tests/Unit/Common/EMSLinkAiTest.php new file mode 100644 index 000000000..b1a6bc95b --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/EMSLinkAiTest.php @@ -0,0 +1,81 @@ +assertEquals('ems://object:page:AWTLzKLc8K-kdP4iJ3rt', (string) $link); + } + + public function testIsValid(): void + { + $link = EMSLink::fromContentTypeOuuid('page', 'AWTLzKLc8K-kdP4iJ3rt'); + $this->assertTrue($link->isValid()); + } + + public function testFromText(): void + { + $link = EMSLink::fromText('ems://object:page:AWTLzKLc8K-kdP4iJ3rt'); + $this->assertEquals('ems://object:page:AWTLzKLc8K-kdP4iJ3rt', (string) $link); + } + + public function testFromMatch(): void + { + $match = [ + 'ouuid' => 'AWTLzKLc8K-kdP4iJ3rt', + 'link_type' => 'object', + 'content_type' => 'page', + ]; + $link = EMSLink::fromMatch($match); + $this->assertEquals('ems://object:page:AWTLzKLc8K-kdP4iJ3rt', (string) $link); + } + + public function testFromDocument(): void + { + $document = [ + '_id' => 'AWTLzKLc8K-kdP4iJ3rt', + '_source' => [ + '_contenttype' => 'page', + ], + ]; + $link = EMSLink::fromDocument($document); + $this->assertEquals('ems://object:page:AWTLzKLc8K-kdP4iJ3rt', (string) $link); + } + + public function testGetters(): void + { + $link = EMSLink::fromText('ems://object:page:AWTLzKLc8K-kdP4iJ3rt'); + $this->assertEquals('object', $link->getLinkType()); + $this->assertEquals('page', $link->getContentType()); + $this->assertEquals('AWTLzKLc8K-kdP4iJ3rt', $link->getOuuid()); + $this->assertEquals([], $link->getQuery()); + $this->assertTrue($link->hasContentType()); + $this->assertEquals('page:AWTLzKLc8K-kdP4iJ3rt', $link->getEmsId()); + } + + public function testJsonSerialize(): void + { + $link = EMSLink::fromText('ems://object:page:AWTLzKLc8K-kdP4iJ3rt'); + $this->assertEquals('ems://object:page:AWTLzKLc8K-kdP4iJ3rt', $link->jsonSerialize()); + } + + public function testFromMatchException(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('ouuid is required!'); + + $match = [ + 'link_type' => 'object', + 'content_type' => 'page', + ]; + EMSLink::fromMatch($match); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/EMSLinkTest.php b/EMS/common-bundle/tests/Unit/Common/EMSLinkTest.php index 59312b7bf..fc24a72be 100644 --- a/EMS/common-bundle/tests/Unit/Common/EMSLinkTest.php +++ b/EMS/common-bundle/tests/Unit/Common/EMSLinkTest.php @@ -1,5 +1,7 @@ 'EMSClient']; + $timeout = 10; + $allowRedirects = true; + + $client = HttpClientFactory::create($baseUrl, $headers, $timeout, $allowRedirects); + + $this->assertInstanceOf(Client::class, $client); + + $config = $client->getConfig(); + + $this->assertEquals($baseUrl, $config['base_uri']); + $this->assertEquals($headers, $config['headers']); + $this->assertEquals($timeout, $config['timeout']); + $this->assertEquals($allowRedirects, $config['allow_redirects']); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Job/JobOutputAiTest.php b/EMS/common-bundle/tests/Unit/Common/Job/JobOutputAiTest.php new file mode 100644 index 000000000..39d13b80c --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Job/JobOutputAiTest.php @@ -0,0 +1,50 @@ +admin = $this->createMock(AdminInterface::class); + $this->job = $this->createMock(Job::class); + $this->otherOutput = $this->createMock(OutputInterface::class); + + $this->jobOutput = new JobOutput($this->admin, $this->job, $this->otherOutput); + } + + public function testDoWrite(): void + { + $message = 'Test message'; + $newline = true; + + $this->admin->expects($this->once())->method('jobDoWrite') + ->with($this->job, $message, $newline); + + $this->otherOutput->expects($this->once())->method('write') + ->with($message, $newline); + + $this->jobOutput->doWrite($message, $newline); + } + + public function testSetVerbosity(): void + { + $verbosity = OutputInterface::VERBOSITY_VERBOSE; + $this->jobOutput->setVerbosity($verbosity); + + $this->assertSame(OutputInterface::VERBOSITY_NORMAL, $this->jobOutput->getVerbosity()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Log/DoctrineHandlerAiTest.php b/EMS/common-bundle/tests/Unit/Common/Log/DoctrineHandlerAiTest.php new file mode 100644 index 000000000..a905ce78f --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Log/DoctrineHandlerAiTest.php @@ -0,0 +1,72 @@ +logRepository = $this->createMock(LogRepository::class); + $this->tokenStorage = $this->createMock(TokenStorageInterface::class); + + $this->doctrineHandler = new DoctrineHandler($this->logRepository, $this->tokenStorage, Logger::WARNING); + } + + public function testWrite(): void + { + $record = [ + 'message' => 'testMessage', + 'level' => Logger::ERROR, + 'level_name' => 'ERROR', + 'context' => ['api_key' => '123456'], + 'channel' => 'testChannel', + 'formatted' => 'testFormatted', + 'datetime' => new \DateTimeImmutable(), + 'extra' => [], + ]; + + $secretValue = new \ReflectionClassConstant(DoctrineHandler::class, 'SECRET_VALUE'); + + $this->logRepository->expects($this->once()) + ->method('insertRecord') + ->with($this->callback(function ($subject) use ($record, $secretValue) { + return $subject['context']['api_key'] === $secretValue->getValue() && $subject['message'] === $record['message']; + })); + + $method = new \ReflectionMethod(DoctrineHandler::class, 'write'); + + $method->invoke($this->doctrineHandler, $record); + } + + public function testSecretContext(): void + { + $context = [ + 'api_key' => '123456', + 'other_key' => 'value', + ]; + + $secretValue = new \ReflectionClassConstant(DoctrineHandler::class, 'SECRET_VALUE'); + $expected = [ + 'api_key' => $secretValue->getValue(), + 'other_key' => 'value', + ]; + + $method = new \ReflectionMethod(DoctrineHandler::class, 'secretContext'); + + $result = $method->invoke($this->doctrineHandler, $context); + + $this->assertEquals($expected, $result); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Log/LocalizedLoggerAiTest.php b/EMS/common-bundle/tests/Unit/Common/Log/LocalizedLoggerAiTest.php new file mode 100644 index 000000000..14ad58b70 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Log/LocalizedLoggerAiTest.php @@ -0,0 +1,69 @@ +logger = $this->createMock(LoggerInterface::class); + $this->translator = $this->createMock(TranslatorInterface::class); + + $this->localizedLogger = new LocalizedLogger($this->logger, $this->translator, $this->translationDomain); + } + + public function testLog(): void + { + $level = 'info'; + $message = 'Hello %name%'; + $translatedMessage = 'Bonjour %name%'; + $context = [ + 'name' => 'John', + 'translation_message' => $message, + ]; + + $this->translator->expects($this->once()) + ->method('trans') + ->with($message, [], $this->translationDomain) + ->willReturn($translatedMessage); + + $this->logger->expects($this->once()) + ->method('log') + ->with($level, 'Bonjour John', $context); + + $this->localizedLogger->log($level, $message, $context); + } + + public function testLogWithoutReplacement(): void + { + $level = 'info'; + $message = 'Hello World'; + $translatedMessage = 'Bonjour le Monde'; + $context = [ + 'translation_message' => $message, + ]; + + $this->translator->expects($this->once()) + ->method('trans') + ->with($message, [], $this->translationDomain) + ->willReturn($translatedMessage); + + $this->logger->expects($this->once()) + ->method('log') + ->with($level, $translatedMessage, $context); + + $this->localizedLogger->log($level, $message, $context); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Log/LocalizedLoggerFactoryAiTest.php b/EMS/common-bundle/tests/Unit/Common/Log/LocalizedLoggerFactoryAiTest.php new file mode 100644 index 000000000..95d3ef2c9 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Log/LocalizedLoggerFactoryAiTest.php @@ -0,0 +1,33 @@ +translator = $this->createMock(TranslatorInterface::class); + $this->localizedLoggerFactory = new LocalizedLoggerFactory($this->translator); + } + + public function testInvoke(): void + { + $logger = $this->createMock(LoggerInterface::class); + $translationDomain = 'test_domain'; + + $localizedLogger = ($this->localizedLoggerFactory)($logger, $translationDomain); + + $this->assertInstanceOf(LocalizedLogger::class, $localizedLogger); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Metric/EmsInfoMetricCollectorAiTest.php b/EMS/common-bundle/tests/Unit/Common/Metric/EmsInfoMetricCollectorAiTest.php new file mode 100644 index 000000000..1f57726d2 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Metric/EmsInfoMetricCollectorAiTest.php @@ -0,0 +1,48 @@ +composerInfo = $this->createMock(ComposerInfo::class); + $this->emsInfoMetricCollector = new EmsInfoMetricCollector($this->composerInfo); + } + + public function testGetName(): void + { + $this->assertSame('ems_info', $this->emsInfoMetricCollector->getName()); + } + + public function testValidUntil(): void + { + $timestamp = $this->emsInfoMetricCollector->validUntil(); + $this->assertGreaterThan(\time(), $timestamp); + } + + public function testCollect(): void + { + $versionPackages = ['package1' => '1.0.0', 'package2' => '2.0.0']; + $this->composerInfo->method('getVersionPackages')->willReturn($versionPackages); + + $gauge = $this->createMock(Gauge::class); + $gauge->expects($this->once())->method('set')->with(1, \array_values($versionPackages)); + + $collectorRegistry = $this->createMock(CollectorRegistry::class); + $collectorRegistry->method('getOrRegisterGauge')->willReturn($gauge); + + $this->emsInfoMetricCollector->collect($collectorRegistry); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Metric/MetricEventListenerAiTest.php b/EMS/common-bundle/tests/Unit/Common/Metric/MetricEventListenerAiTest.php new file mode 100644 index 000000000..710f57207 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Metric/MetricEventListenerAiTest.php @@ -0,0 +1,58 @@ +metricCollector = $this->createMock(MetricCollector::class); + $this->metricEventListener = new MetricEventListener($this->metricCollector); + } + + public function testGetSubscribedEvents(): void + { + $expectedEvents = [ + 'kernel.terminate' => [ + ['metricCollect', 300], + ], + ]; + + $this->assertSame($expectedEvents, MetricEventListener::getSubscribedEvents()); + } + + public function testMetricCollect(): void + { + $request = new Request(); + $request->attributes->set('_controller', MetricController::METRICS); + + $event = new TerminateEvent( + $this->createMock(HttpKernelInterface::class), + $request, + $this->createMock(Response::class) + ); + + $this->metricCollector->expects($this->once()) + ->method('isInMemoryStorage') + ->willReturn(false); + + $this->metricCollector->expects($this->once()) + ->method('collectWithValidity'); + + $this->metricEventListener->metricCollect($event); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/PropertyAccess/PropertyAccessorAiTest.php b/EMS/common-bundle/tests/Unit/Common/PropertyAccess/PropertyAccessorAiTest.php new file mode 100644 index 000000000..9d6d5ee32 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/PropertyAccess/PropertyAccessorAiTest.php @@ -0,0 +1,107 @@ +propertyAccessor = PropertyAccessor::createPropertyAccessor(); + } + + public function testGetValue(): void + { + $array = [ + 'name' => 'John', + 'details' => [ + 'age' => 30, + 'address' => '123 Street', + ], + ]; + + $value = $this->propertyAccessor->getValue($array, '[name]'); + $this->assertSame('John', $value); + + $value = $this->propertyAccessor->getValue($array, '[details][age]'); + $this->assertSame(30, $value); + } + + public function testSetValue(): void + { + $array = [ + 'name' => 'John', + 'details' => [ + 'age' => 30, + ], + ]; + + $this->propertyAccessor->setValue($array, '[name]', 'Doe'); + $this->assertSame('Doe', $array['name']); + + $this->propertyAccessor->setValue($array, '[details][address]', '456 Avenue'); + $this->assertSame('456 Avenue', $array['details']['address']); + } + + public function testIterator(): void + { + $array = [ + 'users' => [ + ['id' => 1, 'name' => 'John'], + ['id' => 2, 'name' => 'Doe'], + ], + ]; + + $results = []; + foreach ($this->propertyAccessor->iterator('[users][*][name]', $array) as $path => $value) { + $results[$path] = $value; + } + + $this->assertSame([ + '[users][0][name]' => 'John', + '[users][1][name]' => 'Doe', + ], $results); + } + + public function testEncodeDecodeException(): void + { + $this->expectException(\RuntimeException::class); + $this->propertyAccessor->getValue(['data' => 'invalid'], '[json:data]'); + } + + public function testCreatePropertyAccessor(): void + { + $accessor1 = PropertyAccessor::createPropertyAccessor(); + $accessor2 = PropertyAccessor::createPropertyAccessor(); + + $this->assertSame($accessor1, $accessor2, 'Expected the same instance of PropertyAccessor'); + } + + public function testSetValueWithOperators(): void + { + $array = [ + 'data' => '{"name":"John"}', + ]; + + $this->propertyAccessor->setValue($array, '[json:data][name]', 'Doe'); + $this->assertSame('{"name":"Doe"}', $array['data']); + } + + public function testIdPropertyAsArrayKeyException(): void + { + $this->expectException(\RuntimeException::class); + $this->propertyAccessor->getValue(['data' => [['name' => 'John']]], '[id_key:data]'); + } + + public function testInvalidOperatorException(): void + { + $this->expectException(\RuntimeException::class); + $this->propertyAccessor->getValue(['data' => 'value'], '[invalid:data]'); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/PropertyAccess/PropertyPathAiTest.php b/EMS/common-bundle/tests/Unit/Common/PropertyAccess/PropertyPathAiTest.php new file mode 100644 index 000000000..4ed02da55 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/PropertyAccess/PropertyPathAiTest.php @@ -0,0 +1,72 @@ +assertSame('[operator1:slug1][operator2:slug2]', $propertyPath->getPathAsString()); + } + + public function testInvalidPropertyPath(): void + { + $this->expectException(InvalidPropertyPathException::class); + new PropertyPath('[operator1:slug1]invalid[operator2:slug2]'); + } + + public function testGetElements(): void + { + $propertyPath = new PropertyPath('[operator1:slug1][operator2:slug2]'); + $elements = $propertyPath->getElements(); + $this->assertCount(2, $elements); + $this->assertSame('slug1', $elements[0]->getName()); + $this->assertSame('slug2', $elements[1]->getName()); + } + + public function testIterator(): void + { + $propertyPath = new PropertyPath('[operator1:slug1][operator2:slug2]'); + $elements = []; + foreach ($propertyPath as $element) { + $elements[] = $element->getName(); + } + $this->assertSame(['slug1', 'slug2'], $elements); + } + + public function testCount(): void + { + $propertyPath = new PropertyPath('[operator1:slug1][operator2:slug2]'); + $this->assertCount(2, $propertyPath); + } + + public function testLast(): void + { + $propertyPath = new PropertyPath('[operator1:slug1][operator2:slug2]'); + $this->assertFalse($propertyPath->last()); + $propertyPath->next(); + $this->assertTrue($propertyPath->last()); + } + + public function testSetAndGetIndex(): void + { + $propertyPath = new PropertyPath('[operator1:slug1][operator2:slug2]'); + $propertyPath->setIndex(1); + $this->assertSame(1, $propertyPath->getIndex()); + } + + public function testCurrentWithInvalidIndex(): void + { + $propertyPath = new PropertyPath('[operator1:slug1]'); + $propertyPath->setIndex(2); + $this->expectException(\RuntimeException::class); + $propertyPath->current(); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/PropertyAccess/PropertyPathElementAiTest.php b/EMS/common-bundle/tests/Unit/Common/PropertyAccess/PropertyPathElementAiTest.php new file mode 100644 index 000000000..5be36e025 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/PropertyAccess/PropertyPathElementAiTest.php @@ -0,0 +1,32 @@ +assertSame('testName', $propertyPathElement->getName()); + } + + public function testGetOperators(): void + { + $propertyPathElement = new PropertyPathElement('testName', ['operator1', 'operator2']); + $this->assertSame(['operator1', 'operator2'], $propertyPathElement->getOperators()); + } + + public function testGetOperatorsAsString(): void + { + $propertyPathElement = new PropertyPathElement('testName', ['operator1', 'operator2']); + $this->assertSame('operator1:operator2:', $propertyPathElement->getOperatorsAsString()); + + $propertyPathElementEmpty = new PropertyPathElement('testName', []); + $this->assertSame('', $propertyPathElementEmpty->getOperatorsAsString()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Route/LoaderAiTest.php b/EMS/common-bundle/tests/Unit/Common/Route/LoaderAiTest.php new file mode 100644 index 000000000..2c24e2050 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Route/LoaderAiTest.php @@ -0,0 +1,39 @@ +load(); + + $this->assertInstanceOf(RouteCollection::class, $routes); + $this->assertCount(1, $routes); + + /** @var Route $route */ + $route = $routes->get('ems_metric'); + $this->assertInstanceOf(Route::class, $route); + $this->assertEquals('/metrics', $route->getPath()); + $this->assertEquals(['GET'], $route->getMethods()); + $this->assertEquals('%ems.metric.host%', $route->getHost()); + $this->assertEquals('ems.controller.metric::metrics', $route->getDefault('_controller')); + } + + public function testLoadWithMetricsDisabled(): void + { + $loader = new Loader(false); + $routes = $loader->load(); + + $this->assertInstanceOf(RouteCollection::class, $routes); + $this->assertCount(0, $routes); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/SpreadsheetGeneratorServiceAiTest.php b/EMS/common-bundle/tests/Unit/Common/SpreadsheetGeneratorServiceAiTest.php new file mode 100644 index 000000000..016ad2f95 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/SpreadsheetGeneratorServiceAiTest.php @@ -0,0 +1,96 @@ +service = new SpreadsheetGeneratorService(); + } + + public function testGenerateSpreadsheetWithInvalidWriter(): void + { + $this->expectException(InvalidOptionsException::class); + $this->expectExceptionMessage('The option "writer" with value "invalid_writer" is invalid. Accepted values are: "xlsx", "csv".'); + + $config = [ + 'writer' => 'invalid_writer', + 'filename' => 'test', + 'sheets' => [], + 'disposition' => 'attachment', + ]; + + $this->service->generateSpreadsheet($config); + } + + public function testGenerateSpreadsheetXlsx(): void + { + $config = [ + 'writer' => SpreadsheetGeneratorService::XLSX_WRITER, + 'filename' => 'test', + 'sheets' => [['name' => 'Sheet1', 'rows' => [['A1', 'B1']]]], + 'disposition' => 'attachment', + ]; + + $response = $this->service->generateSpreadsheet($config); + + $this->assertInstanceOf(StreamedResponse::class, $response); + $this->assertEquals('application/vnd.ms-excel', $response->headers->get('Content-Type')); + } + + public function testGenerateSpreadsheetCsv(): void + { + $config = [ + 'writer' => SpreadsheetGeneratorService::CSV_WRITER, + 'filename' => 'test', + 'sheets' => [['name' => 'Sheet1', 'rows' => [['A1', 'B1']]]], + 'disposition' => 'attachment', + ]; + + $response = $this->service->generateSpreadsheet($config); + + $this->assertInstanceOf(StreamedResponse::class, $response); + $this->assertEquals('text/csv; charset=utf-8', $response->headers->get('Content-Type')); + } + + public function testGenerateSpreadsheetCacheableResponseXlsx(): void + { + $config = [ + 'writer' => SpreadsheetGeneratorService::XLSX_WRITER, + 'filename' => 'test', + 'sheets' => [['name' => 'Sheet1', 'rows' => [['A1', 'B1']]]], + 'disposition' => 'attachment', + ]; + + $response = $this->service->generateSpreadsheetCacheableResponse($config); + + $this->assertInstanceOf(Response::class, $response); + $this->assertEquals('application/vnd.ms-excel', $response->headers->get('Content-Type')); + } + + public function testGenerateSpreadsheetCacheableResponseCsv(): void + { + $config = [ + 'writer' => SpreadsheetGeneratorService::CSV_WRITER, + 'filename' => 'test', + 'sheets' => [['name' => 'Sheet1', 'rows' => [['A1', 'B1']]]], + 'disposition' => 'attachment', + ]; + + $response = $this->service->generateSpreadsheetCacheableResponse($config); + + $this->assertInstanceOf(Response::class, $response); + $this->assertEquals('text/csv; charset=utf-8', $response->headers->get('Content-Type')); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/SpreadsheetGeneratorTest.php b/EMS/common-bundle/tests/Unit/Common/SpreadsheetGeneratorTest.php index 9969ee69c..93eb26d62 100644 --- a/EMS/common-bundle/tests/Unit/Common/SpreadsheetGeneratorTest.php +++ b/EMS/common-bundle/tests/Unit/Common/SpreadsheetGeneratorTest.php @@ -1,5 +1,7 @@ assertEquals(\base64_encode($original), $encoded); + } + + public function testDecode(): void + { + $original = 'Hello World'; + $encoded = \base64_encode($original); + $decoded = Base64::decode($encoded); + + $this->assertEquals($original, $decoded); + } + + public function testDecodeInvalidBase64(): void + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Invalid base64 💀'); + + Base64::decode('💀'); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Standard/DateTimeAiTest.php b/EMS/common-bundle/tests/Unit/Common/Standard/DateTimeAiTest.php new file mode 100644 index 000000000..994562075 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Standard/DateTimeAiTest.php @@ -0,0 +1,46 @@ +assertInstanceOf(\DateTimeInterface::class, $dateTime); + $this->assertEquals($time, $dateTime->format('Y-m-d H:i:s')); + } + + public function testCreateInvalidTime(): void + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Failed creating time for "invalid-time"'); + + DateTime::create('invalid-time'); + } + + public function testCreateFromFormat(): void + { + $time = '2023-10-06T12:00:00+00:00'; + $format = \DateTimeInterface::ATOM; + $dateTime = DateTime::createFromFormat($time, $format); + + $this->assertInstanceOf(\DateTimeInterface::class, $dateTime); + $this->assertEquals($time, $dateTime->format($format)); + } + + public function testCreateFromFormatInvalidTime(): void + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessageMatches('/^Failed creating dateTime for "invalid-time" with format ".*", \[.*\]$/'); + + DateTime::createFromFormat('invalid-time', \DateTimeInterface::ATOM); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Standard/HashAiTest.php b/EMS/common-bundle/tests/Unit/Common/Standard/HashAiTest.php new file mode 100644 index 000000000..59332d8dc --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Standard/HashAiTest.php @@ -0,0 +1,45 @@ +assertEquals(\sha1($value), $hashedValue); + } + + public function testStringHashWithPrefix(): void + { + $value = 'test_string'; + $prefix = 'prefix_'; + $hashedValue = Hash::string($value, $prefix); + + $this->assertEquals($prefix.\sha1($value), $hashedValue); + } + + public function testArrayHash(): void + { + $value = ['key' => 'value']; + $hashedValue = Hash::array($value); + + $this->assertEquals(\sha1(\json_encode($value)), $hashedValue); + } + + public function testArrayHashWithPrefix(): void + { + $value = ['key' => 'value']; + $prefix = 'prefix_'; + $hashedValue = Hash::array($value, $prefix); + + $this->assertEquals($prefix.\sha1(\json_encode($value)), $hashedValue); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Standard/ImageAiTest.php b/EMS/common-bundle/tests/Unit/Common/Standard/ImageAiTest.php new file mode 100644 index 000000000..836f8da7e --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Standard/ImageAiTest.php @@ -0,0 +1,48 @@ +assertTrue('object' == \gettype($image) && 'GdImage' == \get_class($image)); + } + + public function testImageResolution(): void + { + $resolution = Image::imageResolution(self::TEST_IMAGE_PATH); + + $this->assertIsArray($resolution); + $this->assertCount(2, $resolution); + $this->assertIsInt($resolution[0]); + $this->assertIsInt($resolution[1]); + } + + public function testImageSize(): void + { + $size = Image::imageSize(self::TEST_IMAGE_PATH); + + $this->assertIsArray($size); + $this->assertArrayHasKey(0, $size); + $this->assertArrayHasKey(1, $size); + $this->assertArrayHasKey('mime', $size); + } + + public function testImageCreateFromFilename(): void + { + $image = Image::imageCreateFromFilename(self::TEST_IMAGE_PATH); + + $this->assertTrue('object' == \gettype($image) && 'GdImage' == \get_class($image)); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Standard/JsonAiTest.php b/EMS/common-bundle/tests/Unit/Common/Standard/JsonAiTest.php new file mode 100644 index 000000000..646194a87 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Standard/JsonAiTest.php @@ -0,0 +1,65 @@ + 'value']; + + /** + * @group legacy + */ + public function testEncodeTriggersDeprecation(): void + { + $this->expectDeprecation('The function %s::encode has been deprecated, use %s::encode instead'); + Json::encode(self::TEST_JSON_ARRAY); + } + + /** + * @group legacy + */ + public function testEscapeTriggersDeprecation(): void + { + $this->expectDeprecation('The function %s::escape has been deprecated, use %s::escape instead'); + Json::escape(self::TEST_JSON_STRING); + } + + /** + * @group legacy + */ + public function testDecodeTriggersDeprecation(): void + { + $this->expectDeprecation('The function %s::decode has been deprecated, use %s::decode instead'); + Json::decode(self::TEST_JSON_STRING); + } + + /** + * @group legacy + */ + public function testDecodeFileTriggersDeprecation(): void + { + $this->expectDeprecation('The function %s::decodeFile has been deprecated, use %s::decodeFile instead'); + $tempFile = \tempnam(\sys_get_temp_dir(), 'json_test'); + \file_put_contents($tempFile, self::TEST_JSON_STRING); + Json::decodeFile($tempFile); + \unlink($tempFile); + } + + /** + * @group legacy + */ + public function testIsJsonTriggersDeprecation(): void + { + $this->expectDeprecation('The function %s::isJson has been deprecated, use %s::isJson instead'); + Json::isJson(self::TEST_JSON_STRING); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Standard/TypeAiTest.php b/EMS/common-bundle/tests/Unit/Common/Standard/TypeAiTest.php new file mode 100644 index 000000000..25d2a8ea1 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Standard/TypeAiTest.php @@ -0,0 +1,39 @@ +assertSame($input, $result); + } + + public function testStringThrowsExceptionForNonString(): void + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage("Expect a string got 'integer'"); + Type::string(123); + } + + public function testIntegerReturnsInteger(): void + { + $input = 123; + $result = Type::integer($input); + $this->assertSame($input, $result); + } + + public function testIntegerThrowsExceptionForNonInteger(): void + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage("Expect an integer got 'string'"); + Type::integer('test'); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Standard/fixtures/image.png b/EMS/common-bundle/tests/Unit/Common/Standard/fixtures/image.png new file mode 100644 index 0000000000000000000000000000000000000000..34fdb4024bc4d122442bc5c6f483f5090fea8a1f GIT binary patch literal 16625 zcmbV!W0dI3wqV=t)3$Bfwr$(CZQFLAw$0PFZQI>*zI)$&Ge6#%S!=SARHd@LcV#8J zsuCeDD+UXN2?YQE04pIbtoXO||L1@J`+FYbHJJQcU^t7YJ1g0lI=dM-ng9qG+ZmeR zOV}8gnJAhV7<)L3n{WdF0GnGVt2?X9NOKz5+0YvN14HX>WB(T$0Dzm%-QK{+%ETGp z(8SEbmWS}BvzHLx!kC9pjYWoD#$L$8+(O*b(L~8pR@unY%80|5kdGI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zgt)PD3{{jp7xPkxx literal 0 HcmV?d00001 diff --git a/EMS/common-bundle/tests/Unit/Common/StoreData/Factory/StoreDataCacheFactoryAiTest.php b/EMS/common-bundle/tests/Unit/Common/StoreData/Factory/StoreDataCacheFactoryAiTest.php new file mode 100644 index 000000000..e5cd05290 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/StoreData/Factory/StoreDataCacheFactoryAiTest.php @@ -0,0 +1,53 @@ +cache = $this->createMock(Cache::class); + } + + public function testGetType(): void + { + $factory = new StoreDataCacheFactory($this->cache); + $this->assertSame(StoreDataCacheFactory::TYPE_CACHE, $factory->getType()); + } + + public function testCreateService(): void + { + $factory = new StoreDataCacheFactory($this->cache); + $service = $factory->createService(['type' => StoreDataCacheFactory::TYPE_CACHE]); + + $this->assertInstanceOf(StoreDataCacheService::class, $service); + } + + public function testCreateServiceWithInvalidType(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The option "type" with value "invalid" is invalid.'); + + $factory = new StoreDataCacheFactory($this->cache); + $factory->createService(['type' => 'invalid']); + } + + public function testCreateServiceWithoutType(): void + { + $this->expectException(MissingOptionsException::class); + $this->expectExceptionMessage('The required option "type" is missing.'); + + $factory = new StoreDataCacheFactory($this->cache); + $factory->createService([]); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/StoreData/Factory/StoreDataEntityFactoryAiTest.php b/EMS/common-bundle/tests/Unit/Common/StoreData/Factory/StoreDataEntityFactoryAiTest.php new file mode 100644 index 000000000..1f5cdde16 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/StoreData/Factory/StoreDataEntityFactoryAiTest.php @@ -0,0 +1,53 @@ +repository = $this->createMock(StoreDataRepository::class); + } + + public function testGetType(): void + { + $factory = new StoreDataEntityFactory($this->repository); + $this->assertSame(StoreDataEntityFactory::TYPE_DB, $factory->getType()); + } + + public function testCreateService(): void + { + $factory = new StoreDataEntityFactory($this->repository); + $service = $factory->createService(['type' => StoreDataEntityFactory::TYPE_DB]); + + $this->assertInstanceOf(StoreDataEntityService::class, $service); + } + + public function testCreateServiceWithInvalidType(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The option "type" with value "invalid" is invalid.'); + + $factory = new StoreDataEntityFactory($this->repository); + $factory->createService(['type' => 'invalid']); + } + + public function testCreateServiceWithoutType(): void + { + $this->expectException(MissingOptionsException::class); + $this->expectExceptionMessage('The required option "type" is missing.'); + + $factory = new StoreDataEntityFactory($this->repository); + $factory->createService([]); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/StoreData/Factory/StoreDataFileSystemFactoryAiTest.php b/EMS/common-bundle/tests/Unit/Common/StoreData/Factory/StoreDataFileSystemFactoryAiTest.php new file mode 100644 index 000000000..7be6061f1 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/StoreData/Factory/StoreDataFileSystemFactoryAiTest.php @@ -0,0 +1,50 @@ +assertSame('fs', $factory->getType()); + } + + public function testCreateService(): void + { + $factory = new StoreDataFileSystemFactory(); + $service = $factory->createService([ + 'type' => 'fs', + 'path' => '/tmp', + ]); + + $this->assertInstanceOf(StoreDataFileSystemService::class, $service); + } + + public function testCreateServiceWithInvalidType(): void + { + $this->expectException(\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException::class); + + $factory = new StoreDataFileSystemFactory(); + $factory->createService([ + 'type' => 'invalid_type', + 'path' => '/tmp', + ]); + } + + public function testCreateServiceWithoutPath(): void + { + $this->expectException(\Symfony\Component\OptionsResolver\Exception\MissingOptionsException::class); + + $factory = new StoreDataFileSystemFactory(); + $factory->createService([ + 'type' => 'fs', + ]); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/StoreData/Service/StoreDataCacheServiceAiTest.php b/EMS/common-bundle/tests/Unit/Common/StoreData/Service/StoreDataCacheServiceAiTest.php new file mode 100644 index 000000000..882c0fc69 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/StoreData/Service/StoreDataCacheServiceAiTest.php @@ -0,0 +1,72 @@ +cache = $this->createMock(Cache::class); + $this->service = new StoreDataCacheService($this->cache); + } + + public function testSave(): void + { + $dataHelper = new StoreDataHelper('key', ['data' => 'value']); + $cacheItem = $this->createMock(CacheItemInterface::class); + + $this->cache->expects($this->once()) + ->method('getItem') + ->with('key') + ->willReturn($cacheItem); + + $cacheItem->expects($this->once()) + ->method('set') + ->with(['data' => 'value']); + + $this->cache->expects($this->once()) + ->method('save') + ->with($cacheItem); + + $this->service->save($dataHelper); + } + + public function testRead(): void + { + $cacheItem = $this->createMock(CacheItemInterface::class); + + $this->cache->expects($this->once()) + ->method('getItem') + ->with('key') + ->willReturn($cacheItem); + + $cacheItem->expects($this->once()) + ->method('get') + ->willReturn(['data' => 'value']); + + $dataHelper = $this->service->read('key'); + $this->assertInstanceOf(StoreDataHelper::class, $dataHelper); + $this->assertSame('key', $dataHelper->getKey()); + $this->assertSame(['data' => 'value'], $dataHelper->getData()); + } + + public function testDelete(): void + { + $this->cache->expects($this->once()) + ->method('delete') + ->with('key'); + + $this->service->delete('key'); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/StoreData/Service/StoreDataEntityServiceAiTest.php b/EMS/common-bundle/tests/Unit/Common/StoreData/Service/StoreDataEntityServiceAiTest.php new file mode 100644 index 000000000..7a6a2f455 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/StoreData/Service/StoreDataEntityServiceAiTest.php @@ -0,0 +1,74 @@ +repository = $this->createMock(StoreDataRepository::class); + $this->service = new StoreDataEntityService($this->repository); + } + + public function testSave(): void + { + $dataHelper = new StoreDataHelper('key', ['data' => 'value']); + $entity = new StoreData(); + + $this->repository->expects($this->once()) + ->method('getByKey') + ->with('key') + ->willReturn(null); + + $this->repository->expects($this->once()) + ->method('update') + ->with($this->isInstanceOf(StoreData::class)); + + $this->service->save($dataHelper); + } + + public function testRead(): void + { + $entity = new StoreData(); + $entity->setKey('key'); + $entity->setData(['data' => 'value']); + + $this->repository->expects($this->once()) + ->method('getByKey') + ->with('key') + ->willReturn($entity); + + $dataHelper = $this->service->read('key'); + $this->assertInstanceOf(StoreDataHelper::class, $dataHelper); + $this->assertSame('key', $dataHelper->getKey()); + $this->assertSame(['data' => 'value'], $dataHelper->getData()); + } + + public function testDelete(): void + { + $entity = new StoreData(); + $entity->setKey('key'); + + $this->repository->expects($this->once()) + ->method('getByKey') + ->with('key') + ->willReturn($entity); + + $this->repository->expects($this->once()) + ->method('delete') + ->with($entity); + + $this->service->delete('key'); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/StoreData/Service/StoreDataFileSystemServiceAiTest.php b/EMS/common-bundle/tests/Unit/Common/StoreData/Service/StoreDataFileSystemServiceAiTest.php new file mode 100644 index 000000000..0b60f628b --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/StoreData/Service/StoreDataFileSystemServiceAiTest.php @@ -0,0 +1,57 @@ +rootPath = \sys_get_temp_dir().DIRECTORY_SEPARATOR.'store_data_test'; + @\mkdir($this->rootPath); + $this->service = new StoreDataFileSystemService($this->rootPath); + } + + protected function tearDown(): void + { + \array_map('unlink', \glob($this->rootPath.DIRECTORY_SEPARATOR.'*')); + \rmdir($this->rootPath); + } + + public function testSaveAndRead(): void + { + $dataHelper = new StoreDataHelper('key', ['data' => 'value']); + $this->service->save($dataHelper); + + $readDataHelper = $this->service->read('key'); + $this->assertInstanceOf(StoreDataHelper::class, $readDataHelper); + $this->assertSame('key', $readDataHelper->getKey()); + $this->assertSame(['data' => 'value'], $readDataHelper->getData()); + } + + public function testDelete(): void + { + $dataHelper = new StoreDataHelper('key', ['data' => 'value']); + $this->service->save($dataHelper); + + $this->service->delete('key'); + $this->assertNull($this->service->read('key')); + } + + public function testInvalidKey(): void + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('The key invalid*key contains 1 invalid character(s): ^, *, ?, <, >, | ou :'); + + $dataHelper = new StoreDataHelper('invalid*key', ['data' => 'value']); + $this->service->save($dataHelper); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/StoreData/StoreDataHelperAiTest.php b/EMS/common-bundle/tests/Unit/Common/StoreData/StoreDataHelperAiTest.php new file mode 100644 index 000000000..6570c87ff --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/StoreData/StoreDataHelperAiTest.php @@ -0,0 +1,43 @@ +assertSame($key, $helper->getKey()); + } + + public function testGetData(): void + { + $data = ['name' => 'John', 'age' => 30]; + $helper = new StoreDataHelper('key', $data); + $this->assertSame($data, $helper->getData()); + } + + public function testGet(): void + { + $data = ['name' => 'John', 'age' => 30]; + $helper = new StoreDataHelper('key', $data); + $this->assertSame('John', $helper->get('[name]')); + $this->assertSame(30, $helper->get('[age]')); + } + + public function testSet(): void + { + $data = ['name' => 'John', 'age' => 30]; + $helper = new StoreDataHelper('key', $data); + $helper->set('[name]', 'Jane'); + $helper->set('[age]', 25); + $this->assertSame('Jane', $helper->get('[name]')); + $this->assertSame(25, $helper->get('[age]')); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/StoreData/StoreDataManagerAiTest.php b/EMS/common-bundle/tests/Unit/Common/StoreData/StoreDataManagerAiTest.php new file mode 100644 index 000000000..64a783d39 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/StoreData/StoreDataManagerAiTest.php @@ -0,0 +1,78 @@ +logger = $this->createMock(LoggerInterface::class); + $this->factory = $this->createMock(StoreDataFactoryInterface::class); + } + + public function testSave(): void + { + $service = $this->createMock(StoreDataServiceInterface::class); + $service->expects($this->once())->method('save'); + + $this->factory->method('getType')->willReturn('test_type'); + $this->factory->method('createService')->willReturn($service); + + $manager = new StoreDataManager($this->logger, [$this->factory], [['type' => 'test_type']]); + $manager->save(new StoreDataHelper('test_key')); + } + + public function testRead(): void + { + $service = $this->createMock(StoreDataServiceInterface::class); + $service->method('read')->willReturn(new StoreDataHelper('test_key')); + + $this->factory->method('getType')->willReturn('test_type'); + $this->factory->method('createService')->willReturn($service); + + $manager = new StoreDataManager($this->logger, [$this->factory], [['type' => 'test_type']]); + $result = $manager->read('test_key'); + + $this->assertInstanceOf(StoreDataHelper::class, $result); + } + + public function testDelete(): void + { + $service = $this->createMock(StoreDataServiceInterface::class); + $service->expects($this->once())->method('delete'); + + $this->factory->method('getType')->willReturn('test_type'); + $this->factory->method('createService')->willReturn($service); + + $manager = new StoreDataManager($this->logger, [$this->factory], [['type' => 'test_type']]); + $manager->delete('test_key'); + } + + public function testMissingService(): void + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('No Store Data service is defined'); + + $manager = new StoreDataManager($this->logger, [], []); + $manager->save(new StoreDataHelper('test_key')); + } + + public function testUnregisteredFactory(): void + { + $this->logger->expects($this->once())->method('warning')->with('Store data factory unregistered_type not registered'); + + new StoreDataManager($this->logger, [$this->factory], [['type' => 'unregistered_type']]); + } +} diff --git a/EMS/common-bundle/tests/Unit/Common/Text/EmsHtmlAiTest.php b/EMS/common-bundle/tests/Unit/Common/Text/EmsHtmlAiTest.php new file mode 100644 index 000000000..8e23dc894 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Common/Text/EmsHtmlAiTest.php @@ -0,0 +1,43 @@ +Hello World'); + $html->removeTag('span', '.*?', false); + + $this->assertEquals('
Hello
', (string) $html); + } + + public function testRemoveTagKeepContent(): void + { + $html = new EmsHtml('
Hello World
'); + $html->removeTag('span'); + + $this->assertEquals('
Hello World
', (string) $html); + } + + public function testPrintUrls(): void + { + $html = new EmsHtml('Example and Anchor'); + $html->printUrls(); + + $this->assertEquals('Example (https://example.com) and Anchor', (string) $html); + } + + public function testReplace(): void + { + $html = new EmsHtml('
Hello World
'); + $html->replace(['Hello' => 'Hi', 'World' => 'Everyone']); + + $this->assertEquals('
Hi Everyone
', (string) $html); + } +} diff --git a/EMS/common-bundle/tests/Unit/Elasticsearch/Document/DocumentAiTest.php b/EMS/common-bundle/tests/Unit/Elasticsearch/Document/DocumentAiTest.php new file mode 100644 index 000000000..2aee39d11 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Elasticsearch/Document/DocumentAiTest.php @@ -0,0 +1,77 @@ + '12345', + '_index' => 'test_index', + '_source' => [ + 'title' => 'Test Title', + '_contenttype' => 'test_content', + ], + ]; + + public function testFromResult(): void + { + $result = $this->createMock(Result::class); + $result->method('getHit')->willReturn($this->sampleDocumentData); + + $document = Document::fromResult($result); + + $this->assertEquals('12345', $document->getId()); + } + + public function testGetters(): void + { + $document = Document::fromArray($this->sampleDocumentData); + + $this->assertEquals('12345', $document->getId()); + $this->assertEquals('test_content', $document->getContentType()); + $this->assertEquals('test_content:12345', $document->getEmsId()); + $this->assertEquals('test_index', $document->getIndex()); + $this->assertEquals($this->sampleDocumentData, $document->getRaw()); + $this->assertNull($document->getHighlight()); + } + + public function testGetEmsLink(): void + { + $document = Document::fromArray($this->sampleDocumentData); + $emsLink = $document->getEmsLink(); + + $this->assertInstanceOf(EMSLink::class, $emsLink); + $this->assertEquals('ems://object:test_content:12345', $emsLink->__toString()); + } + + public function testGetSource(): void + { + $document = Document::fromArray($this->sampleDocumentData); + + $this->assertEquals(['title' => 'Test Title', EMSSource::FIELD_CONTENT_TYPE => 'test_content'], $document->getSource()); + $this->assertEquals(['title' => 'Test Title'], $document->getSource(true)); + } + + public function testGetValue(): void + { + $document = Document::fromArray($this->sampleDocumentData); + + $this->assertEquals('Test Title', $document->getValue('[title]')); + $this->assertNull($document->getValue('[description]')); + $this->assertEquals('Default', $document->getValue('[description]', 'Default')); + } + + public function testFieldPathToPropertyPath(): void + { + $this->assertEquals('[field][subfield]', Document::fieldPathToPropertyPath('field.subfield')); + $this->assertEquals('[field][0]', Document::fieldPathToPropertyPath('field[0]')); + } +} diff --git a/EMS/common-bundle/tests/Unit/Elasticsearch/Document/DocumentCollectionAiTest.php b/EMS/common-bundle/tests/Unit/Elasticsearch/Document/DocumentCollectionAiTest.php new file mode 100644 index 000000000..b476d55a7 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Elasticsearch/Document/DocumentCollectionAiTest.php @@ -0,0 +1,62 @@ + [ + 'total' => 2, + 'hits' => [ + [ + '_id' => '12345', + '_index' => 'test_index', + '_source' => [ + 'title' => 'Test Title 1', + '_contenttype' => 'test_content', + ], + ], + [ + '_id' => '67890', + '_index' => 'test_index', + '_source' => [ + 'title' => 'Test Title 2', + '_contenttype' => 'test_content', + ], + ], + ], + ], + ]; + + public function testFromResponse(): void + { + $response = Response::fromArray($this->sampleResponseData); + $collection = DocumentCollection::fromResponse($response); + + $this->assertInstanceOf(DocumentCollection::class, $collection); + $this->assertCount(2, $collection); + } + + public function testGetIterator(): void + { + $response = Response::fromArray($this->sampleResponseData); + $collection = DocumentCollection::fromResponse($response); + + $documents = []; + foreach ($collection as $document) { + $documents[] = $document; + } + + $this->assertCount(2, $documents); + $this->assertInstanceOf(Document::class, $documents[0]); + $this->assertEquals('12345', $documents[0]->getId()); + $this->assertEquals('67890', $documents[1]->getId()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Elasticsearch/Document/DocumentCollectionTest.php b/EMS/common-bundle/tests/Unit/Elasticsearch/Document/DocumentCollectionTest.php index 5442307f8..2b6fa03ec 100644 --- a/EMS/common-bundle/tests/Unit/Elasticsearch/Document/DocumentCollectionTest.php +++ b/EMS/common-bundle/tests/Unit/Elasticsearch/Document/DocumentCollectionTest.php @@ -1,5 +1,7 @@ 'test_content', + '_sha1' => 'sample_hash', + '_finalized_by' => 'test_user', + '_finalization_datetime' => '2023-10-06T12:00:00+0200', + '_published_datetime' => '2023-10-06T13:00:00+0200', + ]; + + public function testConstructAndGetters(): void + { + $emsSource = new EMSSource($this->sampleSourceData); + + $this->assertEquals('test_content', $emsSource->getContentType()); + $this->assertEquals('sample_hash', $emsSource->getHash()); + $this->assertTrue($emsSource->hasFinalizedBy()); + $this->assertEquals('test_user', $emsSource->getFinalizedBy()); + $this->assertTrue($emsSource->hasFinalizationDateTime()); + $this->assertEquals('2023-10-06 12:00:00', $emsSource->getFinalizationDateTime()->format('Y-m-d H:i:s')); + $this->assertTrue($emsSource->hasPublicationDateTime()); + $this->assertEquals('2023-10-06 13:00:00', $emsSource->getPublicationDateTime()->format('Y-m-d H:i:s')); + } + + public function testGetWithDefault(): void + { + $emsSource = new EMSSource($this->sampleSourceData); + $this->assertEquals('default_value', $emsSource->get('non_existent_field', 'default_value')); + } + + public function testGetFinalizedByException(): void + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Finalized by missing'); + + $sourceData = $this->sampleSourceData; + unset($sourceData['_finalized_by']); + + $emsSource = new EMSSource($sourceData); + $emsSource->getFinalizedBy(); + } + + public function testGetFinalizationDateTimeException(): void + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Finalization datetime by missing'); + + $sourceData = $this->sampleSourceData; + unset($sourceData['_finalization_datetime']); + + $emsSource = new EMSSource($sourceData); + $emsSource->getFinalizationDateTime(); + } + + public function testGetPublicationDateTimeException(): void + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Finalization datetime by missing'); + + $sourceData = $this->sampleSourceData; + unset($sourceData['_published_datetime']); + + $emsSource = new EMSSource($sourceData); + $emsSource->getPublicationDateTime(); + } + + public function testToArray(): void + { + $emsSource = new EMSSource($this->sampleSourceData); + $this->assertEquals($this->sampleSourceData, $emsSource->toArray()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Elasticsearch/Request/RequestAiTest.php b/EMS/common-bundle/tests/Unit/Elasticsearch/Request/RequestAiTest.php new file mode 100644 index 000000000..02469bc90 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Elasticsearch/Request/RequestAiTest.php @@ -0,0 +1,41 @@ +assertEquals('30s', $request->getScroll()); + } + + public function testSetSize(): void + { + $request = new Request('test_index', []); + $request->setSize(20); + + $data = $request->toArray(); + $this->assertEquals(20, $data['size']); + } + + public function testToArray(): void + { + $body = ['query' => ['match_all' => new \stdClass()]]; + $request = new Request('test_index', $body); + + $expected = [ + 'body' => $body, + 'index' => 'test_index', + 'scroll' => '30s', + 'size' => 10, + ]; + + $this->assertEquals($expected, $request->toArray()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Elasticsearch/Response/ResponseAiTest.php b/EMS/common-bundle/tests/Unit/Elasticsearch/Response/ResponseAiTest.php new file mode 100644 index 000000000..eab4fd109 --- /dev/null +++ b/EMS/common-bundle/tests/Unit/Elasticsearch/Response/ResponseAiTest.php @@ -0,0 +1,132 @@ + [ + 'total' => [ + 'value' => 10, + 'relation' => 'eq', + ], + 'hits' => [ + ['_index' => 'test_index', '_id' => '1', '_source' => ['_contenttype' => 'content-type']], + ['_index' => 'test_index', '_id' => '2', '_source' => ['_contenttype' => 'content-type']], + ], + ], + 'aggregations' => [ + 'test_agg' => [], + ], + '_scroll_id' => 'scroll123', + ]; + + $response = Response::fromArray($data); + + $this->assertTrue($response->hasDocuments()); + $this->assertEquals(2, \iterator_count($response->getDocuments())); + $this->assertInstanceOf(Document::class, $response->getDocument(0)); + $this->assertInstanceOf(Aggregation::class, $response->getAggregation('test_agg')); + $this->assertEquals('scroll123', $response->getScrollId()); + $this->assertEquals(10, $response->getTotal()); + $this->assertEquals('10', $response->getFormattedTotal()); + $this->assertTrue($response->isAccurate()); + } + + public function testFromResultSet(): void + { + $resultSet = $this->createMock(ResultSet::class); + $resultSet->method('getResponse')->willReturn($this->createConfiguredMock(\Elastica\Response::class, [ + 'getData' => [ + 'hits' => [ + 'total' => 5, + 'hits' => [ + ['_index' => 'test_index', '_id' => '3', '_source' => ['_contenttype' => 'content-type']], + ], + ], + ], + ])); + + $response = Response::fromResultSet($resultSet); + + $this->assertTrue($response->hasDocuments()); + $this->assertEquals(1, \iterator_count($response->getDocuments())); + $this->assertInstanceOf(Document::class, $response->getDocument(0)); + $this->assertEquals(5, $response->getTotal()); + } + + public function testGetAggregations(): void + { + $data = [ + 'aggregations' => [ + 'test_agg1' => [], + 'test_agg2' => [], + ], + ]; + + $response = Response::fromArray($data); + $aggregations = \iterator_to_array($response->getAggregations()); + + $this->assertCount(2, $aggregations); + $this->assertInstanceOf(Aggregation::class, $aggregations[0]); + $this->assertInstanceOf(Aggregation::class, $aggregations[1]); + } + + public function testGetDocumentCollection(): void + { + $data = [ + 'hits' => [ + 'hits' => [ + ['_index' => 'test_index', '_id' => '1', '_source' => ['_contenttype' => 'content-type']], + ['_index' => 'test_index', '_id' => '2', '_source' => ['_contenttype' => 'content-type']], + ], + ], + ]; + + $response = Response::fromArray($data); + $collection = $response->getDocumentCollection(); + + $this->assertCount(2, $collection); + } + + public function testGetTotalDocuments(): void + { + $data = [ + 'hits' => [ + 'hits' => [ + ['_index' => 'test_index', '_id' => '1', '_source' => ['_contenttype' => 'content-type']], + ['_index' => 'test_index', '_id' => '2', '_source' => ['_contenttype' => 'content-type']], + ], + ], + ]; + + $response = Response::fromArray($data); + $this->assertEquals(2, $response->getTotalDocuments()); + } + + public function testInaccurateTotal(): void + { + $data = [ + 'hits' => [ + 'total' => [ + 'value' => 10, + 'relation' => 'gte', + ], + ], + ]; + + $response = Response::fromArray($data); + $this->assertFalse($response->isAccurate()); + $this->assertEquals('≥10', $response->getFormattedTotal()); + } +} diff --git a/EMS/common-bundle/tests/Unit/Helper/CacheTest.php b/EMS/common-bundle/tests/Unit/Helper/CacheTest.php index 1c6ba7cc5..c59647e9f 100644 --- a/EMS/common-bundle/tests/Unit/Helper/CacheTest.php +++ b/EMS/common-bundle/tests/Unit/Helper/CacheTest.php @@ -1,5 +1,7 @@ serialize(); + + $deserialized = Search::deserialize($serialized); + + $this->assertInstanceOf(Search::class, $deserialized); + $this->assertEquals($search->getIndices(), $deserialized->getIndices()); + } + + public function testHasSources(): void + { + $search = new Search(['index1']); + $this->assertFalse($search->hasSources()); + + $search->setSources(['field1']); + $this->assertTrue($search->hasSources()); + } + + public function testGetSources(): void + { + $search = new Search(['index1']); + $search->setSources(['field1', 'field2']); + $this->assertEquals(['field1', 'field2', '_contenttype', '_version_uuid', '_sha1'], $search->getSources()); + } + + public function testGetQueryArray(): void + { + $search = new Search(['index1'], ['match_all' => new \stdClass()]); + $this->assertEquals(['match_all' => new \stdClass()], $search->getQueryArray()); + } + + public function testSetQueryArray(): void + { + $search = new Search(['index1']); + $search->setQueryArray(['match_all' => new \stdClass()]); + $this->assertEquals(['match_all' => new \stdClass()], $search->getQueryArray()); + } + + public function testAddAggregations(): void + { + $search = new Search(['index1']); + $termsAggregation = new Terms('test_aggregation'); + $search->addAggregations([$termsAggregation]); + + $aggregations = $search->getAggregations(); + $this->assertCount(1, $aggregations); + $this->assertInstanceOf(Terms::class, $aggregations[0]); + } + + public function testAddTermsAggregation(): void + { + $search = new Search(['index1']); + $search->addTermsAggregation('test_aggregation', 'field1', 10); + + $aggregations = $search->getAggregations(); + $this->assertCount(1, $aggregations); + $this->assertInstanceOf(Terms::class, $aggregations[0]); + } + + public function testSetAndGetIndices(): void + { + $search = new Search(['index1']); + $this->assertEquals(['index1'], $search->getIndices()); + } + + public function testSetAndGetContentTypes(): void + { + $search = new Search(['index1']); + $search->setContentTypes(['type1', 'type2']); + $this->assertEquals(['type1', 'type2'], $search->getContentTypes()); + } + + public function testSetAndGetFrom(): void + { + $search = new Search(['index1']); + $search->setFrom(5); + $this->assertEquals(5, $search->getSearchOptions()[\Elastica\Search::OPTION_FROM]); + } + + public function testSetAndGetSize(): void + { + $search = new Search(['index1']); + $search->setSize(15); + $this->assertEquals(15, $search->getSearchOptions()[\Elastica\Search::OPTION_SIZE]); + } + + public function testSetAndGetSort(): void + { + $search = new Search(['index1']); + $search->setSort(['field1' => 'asc']); + $this->assertEquals(['field1' => 'asc'], $search->getSort()); + } + + public function testSetAndGetPostFilter(): void + { + $search = new Search(['index1']); + $postFilter = new MatchAll(); + $search->setPostFilter($postFilter); + $this->assertEquals($postFilter, $search->getPostFilter()); + } + + public function testSetAndGetSuggest(): void + { + $search = new Search(['index1']); + $suggest = new \Elastica\Suggest(); + $search->setSuggest($suggest); + $this->assertEquals($suggest, $search->getSuggest()); + } + + public function testSetAndGetHighlight(): void + { + $search = new Search(['index1']); + $highlight = ['field' => 'field1']; + $search->setHighlight($highlight); + $this->assertEquals($highlight, $search->getHighlight()); + } + + public function testSetAndGetRegex(): void + { + $search = new Search(['index1']); + $search->setRegex('test_regex'); + $this->assertEquals('test_regex', $search->getRegex()); + } + + public function testGetSerializer(): void + { + $serializer = Search::getSerializer(); + $this->assertInstanceOf(\Symfony\Component\Serializer\Serializer::class, $serializer); + } +} diff --git a/EMS/common-bundle/tests/Unit/Storage/StorageManagerTest.php b/EMS/common-bundle/tests/Unit/Storage/StorageManagerTest.php index 9433a5bfb..60bec32b0 100644 --- a/EMS/common-bundle/tests/Unit/Storage/StorageManagerTest.php +++ b/EMS/common-bundle/tests/Unit/Storage/StorageManagerTest.php @@ -1,5 +1,7 @@ =7.1" + }, + "require-dev": { + "nette/tester": "^2.3", + "phpstan/phpstan": "^0.12" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0", + "GPL-3.0" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + } + ], + "description": "Removes final keyword from source code on-the-fly and allows mocking of final methods and classes", + "keywords": [ + "finals", + "mocking", + "phpunit", + "testing", + "unit" + ], + "support": { + "issues": "https://github.com/dg/bypass-finals/issues", + "source": "https://github.com/dg/bypass-finals/tree/v1.5.1" + }, + "time": "2023-09-16T09:13:54+00:00" + }, { "name": "friendsofphp/php-cs-fixer", "version": "v3.14.2", @@ -12393,16 +12446,16 @@ }, { "name": "knplabs/github-api", - "version": "v3.11.0", + "version": "v3.12.0", "source": { "type": "git", "url": "https://github.com/KnpLabs/php-github-api.git", - "reference": "c68b874ac3267c3cc0544b726dbb4e49a72a9920" + "reference": "b50fc1f40bb5ac50957d32c5732fcde9167ac30a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/KnpLabs/php-github-api/zipball/c68b874ac3267c3cc0544b726dbb4e49a72a9920", - "reference": "c68b874ac3267c3cc0544b726dbb4e49a72a9920", + "url": "https://api.github.com/repos/KnpLabs/php-github-api/zipball/b50fc1f40bb5ac50957d32c5732fcde9167ac30a", + "reference": "b50fc1f40bb5ac50957d32c5732fcde9167ac30a", "shasum": "" }, "require": { @@ -12416,7 +12469,7 @@ "psr/cache": "^1.0|^2.0|^3.0", "psr/http-client-implementation": "^1.0", "psr/http-factory-implementation": "^1.0", - "psr/http-message": "^1.0", + "psr/http-message": "^1.0|^2.0", "symfony/deprecation-contracts": "^2.2|^3.0", "symfony/polyfill-php80": "^1.17" }, @@ -12436,7 +12489,7 @@ "extra": { "branch-alias": { "dev-2.x": "2.20.x-dev", - "dev-master": "3.10.x-dev" + "dev-master": "3.11.x-dev" } }, "autoload": { @@ -12469,7 +12522,7 @@ ], "support": { "issues": "https://github.com/KnpLabs/php-github-api/issues", - "source": "https://github.com/KnpLabs/php-github-api/tree/v3.11.0" + "source": "https://github.com/KnpLabs/php-github-api/tree/v3.12.0" }, "funding": [ { @@ -12477,7 +12530,7 @@ "type": "github" } ], - "time": "2023-03-10T11:40:14+00:00" + "time": "2023-09-30T16:42:04+00:00" }, { "name": "knplabs/packagist-api", @@ -13543,16 +13596,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.24.1", + "version": "1.24.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01" + "reference": "bcad8d995980440892759db0c32acae7c8e79442" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01", - "reference": "9f854d275c2dbf84915a5c0ec9a2d17d2cd86b01", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/bcad8d995980440892759db0c32acae7c8e79442", + "reference": "bcad8d995980440892759db0c32acae7c8e79442", "shasum": "" }, "require": { @@ -13584,22 +13637,22 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.2" }, - "time": "2023-09-18T12:18:02+00:00" + "time": "2023-09-26T12:28:12+00:00" }, { "name": "phpstan/phpstan", - "version": "1.10.35", + "version": "1.10.38", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "e730e5facb75ffe09dfb229795e8c01a459f26c3" + "reference": "5302bb402c57f00fb3c2c015bac86e0827e4b691" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e730e5facb75ffe09dfb229795e8c01a459f26c3", - "reference": "e730e5facb75ffe09dfb229795e8c01a459f26c3", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/5302bb402c57f00fb3c2c015bac86e0827e4b691", + "reference": "5302bb402c57f00fb3c2c015bac86e0827e4b691", "shasum": "" }, "require": { @@ -13648,7 +13701,7 @@ "type": "tidelift" } ], - "time": "2023-09-19T15:27:56+00:00" + "time": "2023-10-06T14:19:14+00:00" }, { "name": "phpstan/phpstan-doctrine", @@ -13722,16 +13775,16 @@ }, { "name": "phpstan/phpstan-phpunit", - "version": "1.3.14", + "version": "1.3.15", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "614acc10c522e319639bf38b0698a4a566665f04" + "reference": "70ecacc64fe8090d8d2a33db5a51fe8e88acd93a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/614acc10c522e319639bf38b0698a4a566665f04", - "reference": "614acc10c522e319639bf38b0698a4a566665f04", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/70ecacc64fe8090d8d2a33db5a51fe8e88acd93a", + "reference": "70ecacc64fe8090d8d2a33db5a51fe8e88acd93a", "shasum": "" }, "require": { @@ -13768,28 +13821,28 @@ "description": "PHPUnit extensions and rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.3.14" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.3.15" }, - "time": "2023-08-25T09:46:39+00:00" + "time": "2023-10-09T18:58:39+00:00" }, { "name": "phpstan/phpstan-symfony", - "version": "1.3.2", + "version": "1.3.4", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-symfony.git", - "reference": "7332b90dfc291ac5b4b83fbca2081936faa1e3f9" + "reference": "383855999db6a7d65d0bf580ce2762e17188c2a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-symfony/zipball/7332b90dfc291ac5b4b83fbca2081936faa1e3f9", - "reference": "7332b90dfc291ac5b4b83fbca2081936faa1e3f9", + "url": "https://api.github.com/repos/phpstan/phpstan-symfony/zipball/383855999db6a7d65d0bf580ce2762e17188c2a5", + "reference": "383855999db6a7d65d0bf580ce2762e17188c2a5", "shasum": "" }, "require": { "ext-simplexml": "*", "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.9.18" + "phpstan/phpstan": "^1.10.36" }, "conflict": { "symfony/framework-bundle": "<3.0" @@ -13797,8 +13850,8 @@ "require-dev": { "nikic/php-parser": "^4.13.0", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^1.0", - "phpstan/phpstan-strict-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.3.11", + "phpstan/phpstan-strict-rules": "^1.5.1", "phpunit/phpunit": "^8.5.29 || ^9.5", "psr/container": "1.0 || 1.1.1", "symfony/config": "^5.4 || ^6.1", @@ -13809,7 +13862,8 @@ "symfony/http-foundation": "^5.4 || ^6.1", "symfony/messenger": "^5.4", "symfony/polyfill-php80": "^1.24", - "symfony/serializer": "^5.4" + "symfony/serializer": "^5.4", + "symfony/service-contracts": "^2.2.0" }, "type": "phpstan-extension", "extra": { @@ -13839,9 +13893,9 @@ "description": "Symfony Framework extensions and rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-symfony/issues", - "source": "https://github.com/phpstan/phpstan-symfony/tree/1.3.2" + "source": "https://github.com/phpstan/phpstan-symfony/tree/1.3.4" }, - "time": "2023-05-16T12:46:15+00:00" + "time": "2023-09-29T14:10:11+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0ce0022f1..dd558cb3f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -72,5 +72,6 @@ +