Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
Use the test.xml of the FrameworkBundle (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhelias authored Mar 25, 2020
1 parent 4032893 commit b06dd86
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 47 deletions.
41 changes: 0 additions & 41 deletions resources/config/test.xml

This file was deleted.

15 changes: 10 additions & 5 deletions src/DependencyInjection/PsyshExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Psy\Command\Command;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ExpressionLanguage\Expression;
Expand All @@ -27,18 +28,22 @@
*
* @author Théo FIDRY <theo.fidry@gmail.com>
*/
final class PsyshExtension extends Extension
final class PsyshExtension extends Extension implements PrependExtensionInterface
{
public function prepend(ContainerBuilder $container)
{
if (class_exists(TestContainer::class)) {
$container->prependExtensionConfig('framework', ['test' => true]);
}
}

/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../../resources/config'));
$loader->load('services.xml');
if (class_exists(TestContainer::class) && !$container->has('test.service_container')) {
$loader->load('test.xml');
}

$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
Expand All @@ -47,7 +52,7 @@ public function load(array $configs, ContainerBuilder $container)
$value = new Reference(substr($value, 1));
}
}
$containerId = $container->has('test.service_container') ? 'test.service_container' : 'service_container';
$containerId = class_exists(TestContainer::class) ? 'test.service_container' : 'service_container';
$container->findDefinition('psysh.shell')
->addMethodCall('setScopeVariables', [$config['variables'] + [
'container' => new Reference($containerId),
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/PsyshCommandIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testScopeVariables()
public function testContainerInstance()
{
$container = $this->shell->getScopeVariable('container');
if (class_exists(TestContainer::class)) {
if (self::$kernel->getContainer()->has('test.service_container')) {
$this->assertInstanceOf(TestContainer::class, $container);
} else {
$this->assertInstanceOf(Container::class, $container);
Expand Down

0 comments on commit b06dd86

Please sign in to comment.