Skip to content

Commit

Permalink
Merge pull request #12 from MacPaw/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Yozhef authored Aug 26, 2021
2 parents 001a2e6 + 8cddadb commit 6614a3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ In the `config/services_test.yaml` file of your project:

```
BehatMessengerContext\:
resource: '../vendor/macpaw/symfony-behat-context/src/*'
resource: '../vendor/macpaw/behat-messenger-context/src/*'
```

Step 3: Configure Messenger
Expand All @@ -48,7 +48,7 @@ Go to `behat.yml`
```yaml
...
contexts:
- SymfonyBehatContext\Context\MessengerContext
- BehatMessengerContext\Context\MessengerContext
...
```

Expand Down
17 changes: 7 additions & 10 deletions src/Context/MessengerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
use Exception;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Messenger\Transport\InMemoryTransport;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;

class MessengerContext implements Context
{
use ArraySimilarTrait;

private ContainerInterface $container;
private Serializer $serializer;
private NormalizableInterface $normalizable;

public function __construct(
ContainerInterface $container,
Serializer $serializer
NormalizableInterface $normalizable
) {
$this->container = $container;
$this->serializer = $serializer;
$this->normalizable = $normalizable;
}

/**
Expand Down Expand Up @@ -65,14 +65,11 @@ public function busShouldContainMessageWithJsonAndVariableFields(
$expectedMessage = $this->decodeExpectedJson($expectedMessage);

$transport = $this->getMessengerTransportByName($busName);
$actualMessageList = [];
foreach ($transport->get() as $envelope) {
$actualMessage = $this->convertToArray($envelope->getMessage());
if ($this->isArraysSimilar($actualMessage, $expectedMessage, $variableFields)) {
return;
}

$actualMessageList[] = $actualMessage;
}

throw new Exception(
Expand Down Expand Up @@ -167,7 +164,7 @@ private function getPrettyJson(array $message)
*/
private function convertToArray($object): array
{
return (array) $this->serializer->normalize($object);
return (array) $this->normalizable->normalize($object);
}

/**
Expand All @@ -189,7 +186,7 @@ private function getMessengerTransportByName(string $busName): InMemoryTransport
$hasTransport = $this->container->has($fullName);

if ($hasTransport === false) {
throw new Exception('Transport' . $fullName . ' not found');
throw new Exception('Transport ' . $fullName . ' not found');
}

$transport = $this->container->get($fullName);
Expand All @@ -199,7 +196,7 @@ private function getMessengerTransportByName(string $busName): InMemoryTransport
}

throw new Exception(
'In memory transport' . $fullName . ' not found'
'In memory transport ' . $fullName . ' not found'
);
}
}

0 comments on commit 6614a3e

Please sign in to comment.