Skip to content

Commit

Permalink
Version 11 (#22)
Browse files Browse the repository at this point in the history
- Allow disabling the creation of cache pools orchestrators
- Fix/add coverage to tests
- Remove DisableSSLCompilerPass (now in kununu/http-bundle)
- Update README.md
  • Loading branch information
hugo-goncalves-kununu authored Mar 16, 2021
1 parent 66e376c commit 05d7dee
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 481 deletions.
29 changes: 6 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ It also provides some utilities to use use in your tests.

### CachePool Fixtures

All services tagged with `cache.pool` are elegible to be used to load fixtures.
All services tagged with `cache.pool` are eligible to be used to load fixtures.

For example, assuming you are using the [Cache Component](https://symfony.com/doc/current/components/cache.html):

Expand Down Expand Up @@ -72,6 +72,8 @@ final class IntegrationTest extends FixturesAwareTestCase
}
```

You can also disable the creation of orchestrators services for cache pools if you don't want to use fixtures on caches (see configuration file example).

### Connection Fixtures

All Doctrine Connections are eligible to be used to load fixtures.
Expand Down Expand Up @@ -303,19 +305,6 @@ final class WebTestCaseTest extends WebTestCase
}
}
```
### Disable SSL validations

If your code uses any http client (e.g. Guzzle) to perform Http requests and your test environment (for example, when the test are executed in a CI environment) has issues with SSL validation of certificates you might have the necessity of skipping SSL validations.

This bundle include a compiler pass (`DisableSSLCompilerPass`) that can be configured to do this to your Http clients services (see configuration sections for all options).

Currently this compiler pass only supports Guzzle and those clients have an option to disable such checks, but you only want to disable the check on certain envs (in production environment for sure you would not want to do this!).

So you can configure it to disable checks (disable configuration parameter) and then say which clients services are to be changed and the domains that are to be affected.

Suppose you run your tests at subdomain of `app.myserver.com` (let's say `tests.app.myserver.com`) then you add the `.app.myserver.com` to the list of domains in the bundle configuration.

By default the compiler pass will try to use the `VIRTUAL_HOST` environment variable, but if you setup has another var for that you can also configure the bundle to use that env var.

## Configuration

Expand All @@ -335,16 +324,9 @@ kununu_testing:
service: 'Kununu\TestingBundle\Tests\App\ElasticSearch' # Service Id of an instance of Elasticsearch\Client
index_name: 'my_index_name' # name of your index
ssl_check_disable:
cache:
# Enable or disable the generation of orchestrators for cache pools in the app
enable: true
# Currently only Guzzle clients are supported!
clients:
- 'my.guzzle.client.1'
- 'my.http.client.2'
domains:
- '.my.test.domain.com'
- '.second.test.domain.com'
env_var: 'MY_HOSTNAME_ENV_VAR'
```

## Tests
Expand All @@ -360,4 +342,5 @@ vendor/phpunit/phpunit/phpunit tests [--exclude-group integration]
```

**If you want to run the integration tests you will need the extension `ext-pdo_sqlite` (For installing int ubuntu run `apt update && apt install php-sqlite3`).**

**If you want to run the integration tests you will need to have an Elasticsearch cluster running. To change the hosts of the cluster please go to `tests/App/config/packages/parameters.yml`.**
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"require-dev": {
"doctrine/doctrine-bundle": "^1.10 || ^2.0",
"elasticsearch/elasticsearch": "~7.0",
"guzzlehttp/guzzle": "^7.2",
"kununu/scripts": "^1.1",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"phpunit/phpunit": "^8.1",
Expand All @@ -22,8 +21,7 @@
"suggest": {
"ext-pdo_sqlite": "To run Integration Tests.",
"doctrine/doctrine-bundle": "To run Integration Tests.",
"elasticsearch/elasticsearch": "To run Integration Tests.",
"guzzlehttp/guzzle": "To use DisableSSLCompilerPass."
"elasticsearch/elasticsearch": "To run Integration Tests."
},
"autoload": {
"psr-4": {
Expand Down
29 changes: 24 additions & 5 deletions src/DependencyInjection/Compiler/CachePoolCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Kununu\DataFixtures\Executor\CachePoolExecutor;
use Kununu\DataFixtures\Loader\CachePoolFixturesLoader;
use Kununu\DataFixtures\Purger\CachePoolPurger;
use Kununu\TestingBundle\DependencyInjection\ExtensionConfiguration;
use Kununu\TestingBundle\DependencyInjection\KununuTestingExtension;
use Kununu\TestingBundle\Service\Orchestrator;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
Expand All @@ -19,10 +21,29 @@ final class CachePoolCompilerPass implements CompilerPassInterface

public function process(ContainerBuilder $container): void
{
$cachePoolServices = $container->findTaggedServiceIds('cache.pool');
if (!$this->canBuildOrchestrators($container)) {
return;
}

$ids = [];
foreach ($this->getOrchestratorsIds($container, $container->findTaggedServiceIds('cache.pool')) as $id) {
$this->buildCachePoolOrchestrator($container, $id);
}
}

private function canBuildOrchestrators(ContainerBuilder $container): bool
{
if (!$container->hasExtension(KununuTestingExtension::ALIAS) ||
!($extension = $container->getExtension(KununuTestingExtension::ALIAS)) instanceof ExtensionConfiguration
) {
return false;
}

return (bool) ($extension->getConfig()['cache']['enable'] ?? true);
}

private function getOrchestratorsIds(ContainerBuilder $container, array $cachePoolServices): array
{
$ids = [];
foreach ($cachePoolServices as $id => $tags) {
$definition = $container->getDefinition($id);

Expand All @@ -47,9 +68,7 @@ public function process(ContainerBuilder $container): void
}
}

foreach ($ids as $id) {
$this->buildCachePoolOrchestrator($container, $id);
}
return $ids;
}

private function buildCachePoolOrchestrator(ContainerBuilder $container, string $id): void
Expand Down
13 changes: 0 additions & 13 deletions src/DependencyInjection/Compiler/DisableSSLAdapter.php

This file was deleted.

109 changes: 0 additions & 109 deletions src/DependencyInjection/Compiler/DisableSSLCompilerPass.php

This file was deleted.

27 changes: 0 additions & 27 deletions src/DependencyInjection/Compiler/DisableSSLGuzzleAdapter.php

This file was deleted.

32 changes: 9 additions & 23 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,6 @@ public function getConfigTreeBuilder()
$rootNode
->fixXmlConfig('connection')
->children()
->arrayNode('ssl_check_disable')
->children()
->booleanNode('enable')
->info('Enable disabling SSL checks for requests made with Http clients on selected hosts')
->defaultFalse()
->end()
->arrayNode('clients')
->info('Http client services ids. Currently only Guzzle supported')
->scalarPrototype()
->end()
->end()
->arrayNode('domains')
->info('Domains for which to disable SSL checks')
->scalarPrototype()
->end()
->end()
->scalarNode('env_var')
->info('Environment variable that has the hostname')
->cannotBeEmpty()
->defaultValue('VIRTUAL_HOST')
->end()
->end()
->end()
->arrayNode('connections')
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
Expand Down Expand Up @@ -71,6 +48,15 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->arrayNode('cache')
->addDefaultsIfNotSet()
->children()
->booleanNode('enable')
->info('Enable creating orchestrators for cache pools')
->defaultTrue()
->end()
->end()
->end()
->end()
;

Expand Down
5 changes: 0 additions & 5 deletions src/KununuTestingBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
namespace Kununu\TestingBundle;

use Kununu\TestingBundle\DependencyInjection\Compiler\CachePoolCompilerPass;
use Kununu\TestingBundle\DependencyInjection\Compiler\DisableSSLCompilerPass;
use Kununu\TestingBundle\DependencyInjection\Compiler\DisableSSLGuzzleAdapter;
use Kununu\TestingBundle\DependencyInjection\Compiler\DoctrineCompilerPass;
use Kununu\TestingBundle\DependencyInjection\Compiler\ElasticSearchCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -20,8 +18,5 @@ public function build(ContainerBuilder $container): void
$container->addCompilerPass(new CachePoolCompilerPass());
$container->addCompilerPass(new DoctrineCompilerPass());
$container->addCompilerPass(new ElasticSearchCompilerPass());
$container->addCompilerPass(new DisableSSLCompilerPass(
new DisableSSLGuzzleAdapter()
));
}
}
Loading

0 comments on commit 05d7dee

Please sign in to comment.