Skip to content

Commit 6d23c4f

Browse files
committed
fixed profiler collector
1 parent 39e3c22 commit 6d23c4f

File tree

10 files changed

+80
-21
lines changed

10 files changed

+80
-21
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"symfony/css-selector": "^7.3",
1717
"symfony/translation": "^7.3",
1818
"symfony/twig-bundle": "^7.3",
19+
"symfony/web-profiler-bundle": "^7.3",
1920
"symfony/yaml": "^7.3"
2021
},
2122
"config": {

config/services.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
44
use Yceruto\FormFlowBundle\Form\Extension\HttpFoundation\Type\FormFlowTypeSessionDataStorageExtension;
5-
use Yceruto\FormFlowBundle\Form\ResolvedFormTypeFactory;
65

76
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
87

@@ -12,9 +11,6 @@
1211
return static function (ContainerConfigurator $container): void {
1312
$container
1413
->services()
15-
->set(ResolvedFormTypeFactory::class)
16-
->decorate('form.resolved_type_factory')
17-
1814
->set('form.type_extension.form.flow.session_data_storage', FormFlowTypeSessionDataStorageExtension::class)
1915
->args([service('request_stack')->ignoreOnInvalid()])
2016
->tag('form.type_extension')

src/FormFlowBundle.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,36 @@
22

33
namespace Yceruto\FormFlowBundle;
44

5+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
56
use Symfony\Component\DependencyInjection\ContainerBuilder;
67
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
8+
use Symfony\Component\Form\Extension\DataCollector\Proxy\ResolvedTypeFactoryDataCollectorProxy;
79
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
10+
use Yceruto\FormFlowBundle\Form\ResolvedFormTypeFactory;
811

912
/**
1013
* @link https://symfony.com/doc/current/bundles/best_practices.html
1114
*/
12-
class FormFlowBundle extends AbstractBundle
15+
class FormFlowBundle extends AbstractBundle implements CompilerPassInterface
1316
{
17+
public function build(ContainerBuilder $container): void
18+
{
19+
$container->addCompilerPass($this);
20+
}
21+
1422
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
1523
{
1624
$container->import('../config/services.php');
1725
}
26+
27+
public function process(ContainerBuilder $container): void
28+
{
29+
$def = $container->getDefinition('form.resolved_type_factory');
30+
31+
if (ResolvedTypeFactoryDataCollectorProxy::class === $def->getClass()) {
32+
$def->getArgument(0)->setClass(ResolvedFormTypeFactory::class);
33+
} else {
34+
$def->setClass(ResolvedFormTypeFactory::class);
35+
}
36+
}
1837
}

tests/Integration/AbstractWebTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected static function createKernel(array $options = []): KernelInterface
5555
}
5656

5757
return new $class(
58-
static::getVarDir(),
58+
$options['var_dir'] ?? static::getVarDir(),
5959
$options['test_case'],
6060
$options['root_config'] ?? 'config.yaml',
6161
$options['environment'] ?? 'test',

tests/Integration/App/ShutdownBundle.php

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Yceruto\FormFlowBundle\Tests\Integration\App;
4+
5+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\HttpKernel\Bundle\Bundle;
8+
9+
class TestBundle extends Bundle implements CompilerPassInterface
10+
{
11+
public function build(ContainerBuilder $container): void
12+
{
13+
$container->addCompilerPass($this);
14+
}
15+
16+
public function shutdown(): void
17+
{
18+
restore_exception_handler();
19+
}
20+
21+
public function process(ContainerBuilder $container): void
22+
{
23+
$container->getDefinition('form.resolved_type_factory')->setPublic(true);
24+
}
25+
}

tests/Integration/App/bundles.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
44
use Symfony\Bundle\TwigBundle\TwigBundle;
5+
use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle;
56
use Yceruto\FormFlowBundle\FormFlowBundle;
6-
use Yceruto\FormFlowBundle\Tests\Integration\App\ShutdownBundle;
7+
use Yceruto\FormFlowBundle\Tests\Integration\App\TestBundle;
78

89
return [
910
new FrameworkBundle(),
1011
new TwigBundle(),
12+
new WebProfilerBundle(),
1113
new FormFlowBundle(),
12-
new ShutdownBundle(),
14+
new TestBundle(),
1315
];

tests/Integration/App/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ framework:
1616
cookie_samesite: lax
1717
php_errors:
1818
log: true
19+
profiler: false
1920

2021
twig:
2122
default_path: '%kernel.project_dir%/Templates'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
imports:
2+
- './config.yaml'
3+
4+
framework:
5+
profiler:
6+
enabled: true

tests/Integration/FormFlowBasicTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Yceruto\FormFlowBundle\Tests\Integration;
44

5+
use Symfony\Component\Form\Extension\DataCollector\Proxy\ResolvedTypeFactoryDataCollectorProxy;
6+
use Yceruto\FormFlowBundle\Form\ResolvedFormTypeFactory;
7+
58
class FormFlowBasicTest extends AbstractWebTestCase
69
{
710
public function testFormFlow(): void
@@ -198,6 +201,25 @@ public function testValidationError(): void
198201
self::assertSameFileContent('step2.html', $crawler->filter('body')->html());
199202
}
200203

204+
public function testResolvedTypeFactoryDataCollectorProxyWithProfiler(): void
205+
{
206+
$factory = self::getContainer()->get('form.resolved_type_factory');
207+
208+
self::assertInstanceOf(ResolvedFormTypeFactory::class, $factory);
209+
}
210+
211+
public function testResolvedFormTypeFactoryWithProfiler(): void
212+
{
213+
self::bootKernel([
214+
'var_dir' => 'formflow_with_profiler',
215+
'root_config' => __DIR__.'/App/config_with_profiler.yaml',
216+
]);
217+
218+
$factory = self::getContainer()->get('form.resolved_type_factory');
219+
220+
self::assertInstanceOf(ResolvedTypeFactoryDataCollectorProxy::class, $factory);
221+
}
222+
201223
private static function assertSameFileContent(string $expectedFilename, string $actualContent, bool $save = false): void
202224
{
203225
$expectedContent = self::getOutputFileContent($expectedFilename, $actualContent, $save);

0 commit comments

Comments
 (0)