Skip to content

Commit

Permalink
Update acceptance test (MetadataValidator).
Browse files Browse the repository at this point in the history
  • Loading branch information
zerai committed Sep 20, 2024
1 parent 563cf68 commit 513b31a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public function execute(CommandBus $commandBus): void
$moduleId = 'foo';

// with error
$repoUrl = 'https://github.com/zerai/foo';
//$repoUrl = 'https://github.com/zerai/foo';

// without metadata
//$repoUrl = 'https://github.com/zerai/oe-module-demo-farm-add-ons';

// with metadata
//$repoUrl = 'https://github.com/MedicalMundi/oe-module-todo-list';
$repoUrl = 'https://github.com/MedicalMundi/oe-module-todo-list';

$command = new UpdateModuleMetadata($moduleId, $repoUrl);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Ecotone\Modelling\Attribute\CommandHandler;
use Github\Api\Repo;
use Github\Client as GithubClient;
use Metadata\Core\MetadataValidationEngine\MetadataValidator;
use Metadata\Core\ValueObject\Repository;
use Nyholm\Psr7\Request;
use Psr\Http\Client\ClientInterface;
Expand Down Expand Up @@ -137,30 +138,35 @@ public function getComposerJson(

#[InternalHandler(
inputChannelName: 'module.extractMetadata',
outputChannelName: 'image.upload'
outputChannelName: 'module.validateMetadata',
changingHeaders: true,
)]
public function extractMetadata(
UpdateModuleMetadata $command,
#[Header('composer_json_content')]
string $composerJsonContent,
): UpdateModuleMetadata {
): ?array {
$ar = (array) json_decode($composerJsonContent, true);

if ($this->hasMetadata($ar)) {
print_r($ar['extra']['openemr-module']['metadata']['oe-modules.com']);
return [
'metadata' => $ar['extra']['openemr-module']['metadata']['oe-modules.com'],

Check failure on line 153 in _metadata/src/AdapterForReadingExternalMetadataSource/StatelessWorkflowProcess.php

View workflow job for this annotation

GitHub Actions / Commit Stage / Commit checks (8.1)

MixedArrayAccess

_metadata/src/AdapterForReadingExternalMetadataSource/StatelessWorkflowProcess.php:153:31: MixedArrayAccess: Cannot access array value on mixed variable $ar['extra'] (see https://psalm.dev/051)

Check failure on line 153 in _metadata/src/AdapterForReadingExternalMetadataSource/StatelessWorkflowProcess.php

View workflow job for this annotation

GitHub Actions / Commit Stage / Commit checks (8.1)

MixedArrayAccess

_metadata/src/AdapterForReadingExternalMetadataSource/StatelessWorkflowProcess.php:153:31: MixedArrayAccess: Cannot access array value on mixed variable $ar['extra']['openemr-module'] (see https://psalm.dev/051)

Check failure on line 153 in _metadata/src/AdapterForReadingExternalMetadataSource/StatelessWorkflowProcess.php

View workflow job for this annotation

GitHub Actions / Commit Stage / Commit checks (8.1)

MixedArrayAccess

_metadata/src/AdapterForReadingExternalMetadataSource/StatelessWorkflowProcess.php:153:31: MixedArrayAccess: Cannot access array value on mixed variable $ar['extra']['openemr-module']['metadata'] (see https://psalm.dev/051)
];
}

print_r($nodata = 'No metadata found');

return $command;
return null;
}

#[InternalHandler(inputChannelName: 'image.resize', outputChannelName: 'image.upload')]
public function resizeImage(UpdateModuleMetadata $command): UpdateModuleMetadata
#[InternalHandler(inputChannelName: 'module.validateMetadata')]
public function validateMetadata(#[Header('metadata')] array $metadata, MetadataValidator $metadataValidator): ?UpdateModuleMetadata
{
//echo 'xxxx';
if ($metadataValidator->validate($metadata)) {
echo 'metadata pass';
} else {
echo 'metadata not pass';
}

return $command;
return null;
}

#[InternalHandler(inputChannelName: 'image.upload')]
Expand Down
4 changes: 2 additions & 2 deletions _metadata/src/Core/MetadataUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

namespace Metadata\Core;

use Metadata\Core\MetadataValidationEngine\FixedTrueMetadataValidationEngineValidation;
use Metadata\Core\MetadataValidationEngine\ForMetadataSchemaValidation;
use Metadata\Core\MetadataValidationEngine\MetadataValidationException;
use Metadata\Core\MetadataValidationEngine\MetadataValidator;
use Metadata\Core\Port\Driven\ForReadingExternalMetadataSource\ForReadingExternalMetadataSource;
use Metadata\Core\Port\Driven\ForReadingExternalMetadataSource\MetadataReaderException;
use Metadata\Core\Port\Driven\ForStoringMetadata;
Expand All @@ -32,7 +32,7 @@ public function __construct(
/** TODO: Implement a real validator engine */
private ?ForMetadataSchemaValidation $validatorEngine = null,
) {
$this->validatorEngine = $validatorEngine ?? new FixedTrueMetadataValidationEngineValidation();
$this->validatorEngine = $validatorEngine ?? new MetadataValidator();
}

public function getMetadataForModule(string $moduleId): ?ModuleMetadata
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ Feature: Synchronize module metadata

Given there is the following metadata at metadata original source "https://www.github.com/foo/bar"
| enableSync | category | tag |
| true | FINANCE | finance, payment |
| true | billing | todo |

When I ask for update the metadata for module with code "4868cd6a-b854-461e-91a4-fb30ad1ce2cd"

Then I should obtain the following updated metadata:
| enableSync | category | tag | moduleCode |
| true | FINANCE | finance, payment | 4868cd6a-b854-461e-91a4-fb30ad1ce2cd |
| true | billing | todo | 4868cd6a-b854-461e-91a4-fb30ad1ce2cd |


13 changes: 6 additions & 7 deletions _metadata/tests/Unit/MetadataUpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use Metadata\AdapterForStoringMetadataFake\FakeForStoringMetadata;
use Metadata\Core\MetadataModule;
use Metadata\Core\MetadataUpdater;
use Metadata\Core\MetadataValidationEngine\FixedTrueMetadataValidationEngineValidation;
use Metadata\Core\MetadataValidationEngine\MetadataValidationException;
use Metadata\Core\MetadataValidationEngine\MetadataValidator;
use Metadata\Core\ModuleConfigurator;
use Metadata\Core\Port\Driven\ForReadingExternalMetadataSource\ExternalMetadataDto;
use Metadata\Core\Port\Driven\ModuleMetadata;
Expand All @@ -36,7 +36,7 @@
#[UsesClass(MetadataModule::class)]
#[UsesClass(FakeForStoringMetadata::class)]
#[UsesClass(StubAdapterForReadingExternalMetadataSource::class)]
#[UsesClass(FixedTrueMetadataValidationEngineValidation::class)]
#[UsesClass(MetadataValidator::class)]
#[UsesClass(ModuleConfigurator::class)]
#[UsesClass(ModuleMetadata::class)]
#[UsesClass(ExternalMetadataDto::class)]
Expand Down Expand Up @@ -77,23 +77,22 @@ public function should_update_metadata_for_a_given_module()
$tags = ['irrelevant1-1', 'irrelevant-2']
);
$app->moduleConfigurator()->createMetadata($moduleMetadata);
$app->moduleConfigurator()->setExternalMetadataDto($repoUrl, new ExternalMetadataDto(false, 'performance', ['cache', 'redis']));
$app->moduleConfigurator()->setExternalMetadataDto($repoUrl, new ExternalMetadataDto(false, 'billing', ['sms', 'organizer']));

$app->metadataUpdater()->synchronizeMetadataFor($moduleIdAsString);

$updatedModuleMetadata = $app->metadataUpdater()->getMetadataForModule($moduleIdAsString);
self::assertEquals(false, $updatedModuleMetadata->isSynchronizable());
self::assertEquals('performance', $updatedModuleMetadata->category());
self::assertEquals(['cache', 'redis'], $updatedModuleMetadata->tags());
self::assertEquals('billing', $updatedModuleMetadata->category());
self::assertEquals(['sms', 'organizer'], $updatedModuleMetadata->tags());
}

#[Test]
public function should_throw_metadata_validation_error()
{
self::markTestIncomplete('Implement a real Metadata Validator');
self::expectException(MetadataValidationException::class);
self::expectExceptionMessage(
'Metadata validation error'
'Category not allowed: performance'
);

$app = new MetadataModule(
Expand Down

0 comments on commit 513b31a

Please sign in to comment.