Skip to content

Commit

Permalink
Merge pull request #27 from MacPaw/feat/rewriteAsBundle
Browse files Browse the repository at this point in the history
feat: rewrite as bundle
  • Loading branch information
IiiigorGG authored Jan 17, 2022
2 parents dfc30e0 + dd410d1 commit f8bf6d1
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 156 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ jobs:
run: |
composer require symfony/messenger:${{ matrix.symfony-versions }} --no-update --no-scripts
composer require symfony/serializer:${{ matrix.symfony-versions }} --no-update --no-scripts
composer require symfony/dependency-injection:${{ matrix.symfony-versions }} --no-update --no-scripts
composer require symfony/http-kernel:${{ matrix.symfony-versions }} --no-update --no-scripts
- name: Install dependencies
run: composer install
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
/composer.lock
/build/
/.phpunit.result.cache

/node_modules/
package-lock.json
/.idea/
/package-lock.json
21 changes: 5 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Behat Messenger Context
Behat Messenger Context Bundle
=================================

| Version | Build Status | Code Coverage |
Expand All @@ -9,26 +9,15 @@ Behat Messenger Context
Installation
============

Step 1: Install Context
Step 1: Install Bundle
----------------------------------
Open a command console, enter your project directory and execute:

```console
$ composer require --dev macpaw/behat-messenger-context
```

Step 2: Update Container config to load Messenger Context
----------------------------------
In the `config/services_test.yaml` file of your project:

```
BehatMessengerContext\:
resource: '../vendor/macpaw/behat-messenger-context/src/*'
arguments:
- '@test.service_container'
```

Step 3: Configure Messenger
Step 2: Configure Messenger
=============
Copying `config/packages/dev/messenger.yaml` and pasting that into `config/packages/test/`. This gives us messenger configuration that will only be used in the test environment. Uncomment the code, and replace sync with in-memory. Do that for both of the transports.

Expand All @@ -43,7 +32,7 @@ framework:
```


Step 4: Configure Behat
Step 3: Configure Behat
=============
Go to `behat.yml`

Expand All @@ -61,4 +50,4 @@ Go to `behat.yml`
[master Code Coverage]: https://codecov.io/gh/macpaw/BehatMessengerContext/branch/master
[master Code Coverage Image]: https://img.shields.io/codecov/c/github/macpaw/BehatMessengerContext/master?logo=codecov
[develop Code Coverage]: https://codecov.io/gh/macpaw/BehatMessengerContext/branch/develop
[develop Code Coverage Image]: https://img.shields.io/codecov/c/github/macpaw/BehatMessengerContext/develop?logo=codecov
[develop Code Coverage Image]: https://img.shields.io/codecov/c/github/macpaw/BehatMessengerContext/develop?logo=codecov
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "macpaw/behat-messenger-context",
"type": "library",
"type": "symfony-bundle",
"description": "Behat Context for testing Symfony Messenger component",
"keywords": [
"MacPaw",
Expand Down Expand Up @@ -29,7 +29,10 @@
"php": "^7.4 || ^8.0",
"behat/behat": "^3.0",
"symfony/messenger": "^4.4 || ^5.0 || ^6.0",
"symfony/serializer": "^4.4 || ^5.0 || ^6.0"
"symfony/serializer": "^4.4 || ^5.0 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.4 || ^6.0",
"macpaw/similar-arrays": "^1.0"
},
"require-dev": {
"phpstan/phpstan": "^0.12",
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>

<file>src/</file>
<file>tests/</file>
</ruleset>
5 changes: 0 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<coverage>
<include>
<directory>./src</directory>
Expand Down
11 changes: 11 additions & 0 deletions src/BehatMessengerContextBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace BehatMessengerContext;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class BehatMessengerContextBundle extends Bundle
{
}
6 changes: 2 additions & 4 deletions src/Context/MessengerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@

namespace BehatMessengerContext\Context;

use BehatMessengerContext\Context\Traits\ArraySimilarTrait;
use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use Exception;
use SimilarArrays\SimilarArray;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Messenger\Transport\InMemoryTransport;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class MessengerContext implements Context
class MessengerContext extends SimilarArray implements Context
{
use ArraySimilarTrait;

private ContainerInterface $container;
private NormalizerInterface $normalizer;

Expand Down
48 changes: 0 additions & 48 deletions src/Context/Traits/ArraySimilarTrait.php

This file was deleted.

24 changes: 24 additions & 0 deletions src/DependencyInjection/BehatMessengerContextExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace BehatMessengerContext\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

class BehatMessengerContextExtension extends Extension
{
/**
* @param array<array> $configs
*
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('messenger_context.xml');
}
}
16 changes: 16 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace BehatMessengerContext\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
return new TreeBuilder('behat_messenger_context');
}
}
11 changes: 11 additions & 0 deletions src/Resources/config/messenger_context.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance"
xsd:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service public="true" autowire="true" id="BehatMessengerContext\Context\MessengerContext" class="BehatMessengerContext\Context\MessengerContext">
<argument key="$container" type="service" id="test.service_container"/>
</service>
</services>
</container>
79 changes: 0 additions & 79 deletions tests/Context/Traits/ArraySimilarTraitTest.php

This file was deleted.

26 changes: 26 additions & 0 deletions tests/DependencyInjection/BehatMessengerContextExtensionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace DependencyInjection;

use BehatMessengerContext\Context\MessengerContext;
use BehatMessengerContext\DependencyInjection\BehatMessengerContextExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;

class BehatMessengerContextExtensionTest extends TestCase
{
public function testHasServices(): void
{
$extension = new BehatMessengerContextExtension();
$container = new ContainerBuilder();

$this->assertInstanceOf(Extension::class, $extension);

$extension->load([], $container);

$this->assertTrue($container->has(MessengerContext::class));
}
}
25 changes: 25 additions & 0 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace DependencyInjection;

use BehatMessengerContext\DependencyInjection\Configuration;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Processor;

class ConfigurationTest extends TestCase
{
public function testConfiguration(): void
{
$processor = new Processor();
$configuration = new Configuration();

$this->assertInstanceOf(ConfigurationInterface::class, $configuration);

$configs = $processor->processConfiguration($configuration, []);

$this->assertSame([], $configs);
}
}

0 comments on commit f8bf6d1

Please sign in to comment.