-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into PIM-10485
- Loading branch information
Showing
27 changed files
with
396 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...vity/Connection/back/Infrastructure/Symfony/Resources/config/Webhook/message_handlers.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
services: | ||
Akeneo\Connectivity\Connection\Infrastructure\Webhook\MessageHandler\BusinessEventHandler: | ||
arguments: | ||
- '@Akeneo\Connectivity\Connection\Application\Webhook\Command\SendBusinessEventToWebhooksHandler' | ||
- '@event_dispatcher' | ||
- '%kernel.project_dir%' | ||
- '@logger' | ||
- '@Akeneo\Platform\Component\EventQueue\BulkEventNormalizer' | ||
tags: [messenger.message_handler] |
10 changes: 10 additions & 0 deletions
10
...ctivity/Connection/back/Infrastructure/Symfony/Resources/config/Webhook/services_test.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
services: | ||
Akeneo\Connectivity\Connection\Tests\EndToEnd\GuzzleJsonHistory: | ||
arguments: | ||
- '%kernel.project_dir%/var/cache/test/guzzle_history.json' | ||
|
||
akeneo_connectivity.connection.webhook.guzzle_handler: | ||
class: 'Akeneo\Connectivity\Connection\Tests\EndToEnd\GuzzleMockHandlerStack' | ||
factory: ['Akeneo\Connectivity\Connection\Tests\EndToEnd\GuzzleMockHandlerStack', 'createWithHistoryContainer'] | ||
arguments: | ||
- '@Akeneo\Connectivity\Connection\Tests\EndToEnd\GuzzleJsonHistory' |
55 changes: 55 additions & 0 deletions
55
...nnectivity/Connection/back/Infrastructure/Webhook/Command/SendBusinessEventToWebhooks.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akeneo\Connectivity\Connection\Infrastructure\Webhook\Command; | ||
|
||
use Akeneo\Connectivity\Connection\Application\Webhook\Command\SendBusinessEventToWebhooksCommand; | ||
use Akeneo\Connectivity\Connection\Application\Webhook\Command\SendBusinessEventToWebhooksHandler; | ||
use Akeneo\Connectivity\Connection\Domain\Webhook\Event\MessageProcessedEvent; | ||
use Akeneo\Platform\Component\EventQueue\BulkEvent; | ||
use Akeneo\Platform\Component\EventQueue\BulkEventNormalizer; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
class SendBusinessEventToWebhooks extends Command | ||
{ | ||
protected static $defaultName = 'akeneo:connectivity:send-business-event'; | ||
protected static $defaultDescription = 'Send business event to webhooks'; | ||
|
||
public function __construct( | ||
private BulkEventNormalizer $bulkEventNormalizer, | ||
private SendBusinessEventToWebhooksHandler $commandHandler, | ||
private EventDispatcherInterface $eventDispatcher | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setHidden(true) | ||
->addArgument( | ||
'message', | ||
InputArgument::REQUIRED, | ||
'Symfony Messenger serialized message' | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$message = \json_decode($input->getArgument('message'), true); | ||
$event = $this->bulkEventNormalizer->denormalize($message, BulkEvent::class); | ||
|
||
$this->commandHandler->handle(new SendBusinessEventToWebhooksCommand($event)); | ||
$this->eventDispatcher->dispatch(new MessageProcessedEvent()); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/Akeneo/Connectivity/Connection/back/tests/EndToEnd/GuzzleJsonHistory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akeneo\Connectivity\Connection\Tests\EndToEnd; | ||
|
||
use GuzzleHttp\Psr7\Message; | ||
use Webmozart\Assert\Assert; | ||
|
||
/** | ||
* @author JMLeroux <jean-marie.leroux@akeneo.com> | ||
* @copyright 2022 Akeneo SAS (http://www.akeneo.com) | ||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
* | ||
* A filesystem container to store Guzzle history in a json file. | ||
* We need this filesytem json file to share it between process and keep track of the history in the tests | ||
*/ | ||
class GuzzleJsonHistory implements \ArrayAccess, \Countable | ||
{ | ||
public function __construct(private string $filepath) | ||
{ | ||
} | ||
|
||
public function resetHistory(): void | ||
{ | ||
if (\file_exists($this->filepath)) { | ||
\unlink($this->filepath); | ||
} | ||
} | ||
|
||
public function offsetExists(mixed $offset) | ||
{ | ||
$history = $this->readFile(); | ||
|
||
return isset($history[$offset]); | ||
} | ||
|
||
public function offsetGet(mixed $offset) | ||
{ | ||
$history = $this->readFile(); | ||
Assert::isArray($history); | ||
|
||
return $history[$offset]; | ||
} | ||
|
||
public function offsetSet(mixed $offset, mixed $value) | ||
{ | ||
$history = $this->readFile(); | ||
$history[] = [ | ||
'request' => Message::toString($value['request']), | ||
'response' => $value['response'] ? Message::toString($value['response']) : null, | ||
]; | ||
$this->writeFile($history); | ||
} | ||
|
||
public function offsetUnset(mixed $offset) | ||
{ | ||
$history = $this->readFile(); | ||
unset($history[$offset]); | ||
$this->writeFile($history); | ||
} | ||
|
||
public function count(): int | ||
{ | ||
$history = $this->readFile(); | ||
|
||
return \count($history); | ||
} | ||
|
||
private function readFile(): array | ||
{ | ||
if (!\file_exists($this->filepath)) { | ||
return []; | ||
} | ||
|
||
return \json_decode(\file_get_contents($this->filepath), true); | ||
} | ||
|
||
private function writeFile(array $history): void | ||
{ | ||
\file_put_contents($this->filepath, \json_encode($history)); | ||
} | ||
} |
Oops, something went wrong.