Skip to content

Commit

Permalink
Add testing the container build the services correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Apr 15, 2024
1 parent 2720cb2 commit 9dc8f4a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions Tests/Application/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/var
10 changes: 10 additions & 0 deletions Tests/Application/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace HandcraftedInTheAlps\RestRoutingBundle\Tests\Application;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;

class Kernel extends \Symfony\Component\HttpKernel\Kernel
{
use MicroKernelTrait;
}
30 changes: 29 additions & 1 deletion Tests/DependencyInjection/RestRoutingExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

use HandcraftedInTheAlps\RestRoutingBundle\DependencyInjection\CompilerPass\FormatsCompilerPass;
use HandcraftedInTheAlps\RestRoutingBundle\DependencyInjection\RestRoutingExtension;
use HandcraftedInTheAlps\RestRoutingBundle\Tests\Application\Kernel;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
Expand Down Expand Up @@ -62,6 +64,21 @@ protected function tearDown(): void
unset($this->container, $this->extension);
}

public function testDefault()
{
$this->load([
'handcraftedinthealps_rest_routing' => [],
], true);

$this->assertNotNull($this->container->get('handcraftedinthealps_rest_routing.loader.directory'));
$this->assertNotNull($this->container->get('handcraftedinthealps_rest_routing.loader.controller'));
$this->assertNotNull($this->container->get('handcraftedinthealps_rest_routing.loader.processor'));
$this->assertNotNull($this->container->get('handcraftedinthealps_rest_routing.loader.yaml_collection'));
$this->assertNotNull($this->container->get('handcraftedinthealps_rest_routing.loader.xml_collection'));
$this->assertNotNull($this->container->get('handcraftedinthealps_rest_routing.loader.reader.controller'));
$this->assertNotNull($this->container->get('handcraftedinthealps_rest_routing.loader.reader.action'));
}

public function testIncludeFormatDisabled()
{
$this->load(
Expand Down Expand Up @@ -180,14 +197,25 @@ private function assertValidRestFileLoader(
$this->assertArrayHasKey('routing.loader', $loader->getTags());
}

private function load(array $config): void
private function load(array $config, bool $frameworkBundle = false): void
{
$extension = new RestRoutingExtension();
$extension->load(
$config,
$this->container
);

if ($frameworkBundle) {
$this->container->setParameter('kernel.project_dir', dirname(__DIR__) . '/Application');
$this->container->setParameter('kernel.container_class', 'ApplicationContainer');
$this->container->set('kernel', new Kernel('test', false));
$extension = new FrameworkExtension();
$extension->load(
[],
$this->container
);
}

$formatsCompilerPass = new FormatsCompilerPass();
$formatsCompilerPass->process($this->container);
}
Expand Down

0 comments on commit 9dc8f4a

Please sign in to comment.