Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony 5 and nexylan/slack 3.0 support #34

Merged
merged 4 commits into from Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
/composer.lock
/vendor/
/.php_cs.cache
/.phpunit.result.cache
13 changes: 7 additions & 6 deletions .travis.yml
Expand Up @@ -5,8 +5,7 @@ branches:
language: php

php:
- 7.1
- 7.2
- 7.3
- nightly

env:
Expand All @@ -16,13 +15,15 @@ env:
matrix:
fast_finish: true
include:
- php: 7.1
- php: 7.3
env: COMPOSER_FLAGS="--prefer-lowest"
- php: 7.2
- php: 7.3
env: SYMFONY_VERSION=3.*
- php: 7.2
- php: 7.3
env: SYMFONY_VERSION=4.*
- php: 7.2
- php: 7.3
env: SYMFONY_VERSION=5.*
- php: 7.3
env: SYMFONY_VERSION=dev-master
allow_failures:
- php: nightly
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Expand Up @@ -10,15 +10,15 @@
}
],
"require": {
"php": "^7.1",
"nexylan/slack": "^2.2",
"php-http/httplug-bundle": "^1.8",
"symfony/http-kernel": "^3.4 || ^4.0"
"php": "^7.3",
"nexylan/slack": "^3.0",
"php-http/httplug-bundle": "^1.17",
"symfony/http-kernel": "^3.4 || ^4.0 || ^5.0"
},
"require-dev": {
"matthiasnoback/symfony-dependency-injection-test": "^2.3",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"php-http/mock-client": "^1.1",
"phpunit/phpunit": "^6.5"
"phpunit/phpunit": "^8.0"
},
"suggest": {
"eightpoints/guzzle-bundle": "Make a custom Guzzle instance for Slack with ease"
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Expand Up @@ -8,8 +8,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
soullivaneuh marked this conversation as resolved.
Show resolved Hide resolved
stopOnFailure="false">
<testsuites>
<testsuite name="NexySlackBundle Test Suite">
<directory >./tests/</directory>
Expand Down
2 changes: 2 additions & 0 deletions src/DependencyInjection/Configuration.php
Expand Up @@ -38,6 +38,8 @@ public function getConfigTreeBuilder(): TreeBuilder
->addDefaultsIfNotSet()
->children()
->scalarNode('client')->defaultValue('httplug.client')->end()
->scalarNode('request_factory')->defaultValue('nexy_slack.request_factory.default')->end()
->scalarNode('stream_factory')->defaultValue('nexy_slack.stream_factory.default')->end()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same logic as with the HTTP client class, allow a bundle user to replace the request and stream factories with their own implementation.

->end()
->end()
->scalarNode('endpoint')
Expand Down
2 changes: 2 additions & 0 deletions src/DependencyInjection/NexySlackExtension.php
Expand Up @@ -31,6 +31,8 @@ public function load(array $configs, ContainerBuilder $container): void

$container->setParameter('nexy_slack.endpoint', $config['endpoint']);
$container->setAlias('nexy_slack.http.client', new Alias($config['http']['client'], false));
$container->setAlias('nexy_slack.http.request_factory', new Alias($config['http']['request_factory'], false));
$container->setAlias('nexy_slack.http.stream_factory', new Alias($config['http']['stream_factory'], false));

// Unset the not needed keys for the Slack config.
unset($config['http'], $config['endpoint']);
Expand Down
12 changes: 11 additions & 1 deletion src/Resources/config/client.xml
Expand Up @@ -6,11 +6,21 @@

<services>
<service id="Nexy\Slack\Client" public="true">
<argument type="service" id="nexy_slack.http.client" />
<argument type="service" id="nexy_slack.http.request_factory" />
<argument type="service" id="nexy_slack.http.stream_factory" />
<argument>%nexy_slack.endpoint%</argument>
<argument>%nexy_slack.config%</argument>
<argument type="service" id="nexy_slack.http.client" />
</service>

<service id="nexy_slack.client" alias="Nexy\Slack\Client"/>

<service id="nexy_slack.request_factory.default" class="Psr\Http\Message\RequestFactoryInterface">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HttplugBundle doesn't provide services directly creating the PSR-17 factories, so the services here are the defaults used to discover compatible factories through the Httplug discovery system.

<factory class="Http\Discovery\Psr17FactoryDiscovery" method="findRequestFactory" />
</service>

<service id="nexy_slack.stream_factory.default" class="Psr\Http\Message\StreamFactoryInterface">
<factory class="Http\Discovery\Psr17FactoryDiscovery" method="findStreamFactory" />
</service>
</services>
</container>
10 changes: 8 additions & 2 deletions tests/DependencyInjection/ConfigurationTest.php
Expand Up @@ -16,6 +16,8 @@
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionConfigurationTestCase;
use Nexy\SlackBundle\DependencyInjection\Configuration;
use Nexy\SlackBundle\DependencyInjection\NexySlackExtension;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;

/**
* @author Sullivan Senechal <soullivaneuh@gmail.com>
Expand All @@ -27,6 +29,8 @@ public function testMinimalConfigurationProcess(): void
$expectedConfiguration = [
'http' => [
'client' => 'httplug.client',
'request_factory' => 'nexy_slack.request_factory.default',
'stream_factory' => 'nexy_slack.stream_factory.default',
],
'sticky_channel' => false,
'endpoint' => 'https://hooks.slack.com/services/XXXXX/XXXXX/XXXXXXXXXX',
Expand All @@ -45,6 +49,8 @@ public function testFullConfigurationProcess(): void
$expectedConfiguration = [
'http' => [
'client' => 'httplug.curl',
'request_factory' => 'nexy_slack.request_factory.default',
'stream_factory' => 'nexy_slack.stream_factory.default',
],
'sticky_channel' => false,
'endpoint' => 'https://hooks.slack.com/services/XXXXX/XXXXX/XXXXXXXXXX',
Expand All @@ -68,15 +74,15 @@ public function testFullConfigurationProcess(): void
/**
* {@inheritdoc}
*/
protected function getContainerExtension()
protected function getContainerExtension(): ExtensionInterface
{
return new NexySlackExtension();
}

/**
* {@inheritdoc}
*/
protected function getConfiguration()
protected function getConfiguration(): ConfigurationInterface
{
return new Configuration();
}
Expand Down
12 changes: 8 additions & 4 deletions tests/DependencyInjection/NexySlackExtensionTest.php
Expand Up @@ -49,12 +49,16 @@ public function testLoadWithMinimalConfiguration(): void

$this->assertContainerBuilderHasService(Client::class);

$this->assertContainerBuilderHasServiceDefinitionWithArgument(Client::class, 0, '%nexy_slack.endpoint%');
$this->assertContainerBuilderHasServiceDefinitionWithArgument(Client::class, 1, '%nexy_slack.config%');
$this->assertContainerBuilderHasServiceDefinitionWithArgument(Client::class, 2, new Reference('nexy_slack.http.client'));
$this->assertContainerBuilderHasServiceDefinitionWithArgument(Client::class, 0, new Reference('nexy_slack.http.client'));
$this->assertContainerBuilderHasServiceDefinitionWithArgument(Client::class, 1, new Reference('nexy_slack.http.request_factory'));
$this->assertContainerBuilderHasServiceDefinitionWithArgument(Client::class, 2, new Reference('nexy_slack.http.stream_factory'));
$this->assertContainerBuilderHasServiceDefinitionWithArgument(Client::class, 3, '%nexy_slack.endpoint%');
$this->assertContainerBuilderHasServiceDefinitionWithArgument(Client::class, 4, '%nexy_slack.config%');

$this->assertContainerBuilderHasAlias('nexy_slack.client', Client::class);
$this->assertContainerBuilderHasAlias('nexy_slack.http.client', 'httplug.client');
$this->assertContainerBuilderHasAlias('nexy_slack.http.request_factory', 'nexy_slack.request_factory.default');
$this->assertContainerBuilderHasAlias('nexy_slack.http.stream_factory', 'nexy_slack.stream_factory.default');
}

public function testLoadWithCustomConfiguration(): void
Expand All @@ -81,7 +85,7 @@ public function testLoadWithCustomConfiguration(): void
/**
* {@inheritdoc}
*/
protected function getContainerExtensions()
protected function getContainerExtensions(): array
{
return [
new NexySlackExtension(),
Expand Down
3 changes: 3 additions & 0 deletions tests/NexySlackBundleTest.php
Expand Up @@ -33,6 +33,9 @@ protected function setUp(): void
$this->bundle = new NexySlackBundle();
}

/**
* @doesNotPerformAssertions
soullivaneuh marked this conversation as resolved.
Show resolved Hide resolved
*/
public function testBuild(): void
{
$this->bundle->build($this->container);
Expand Down