File tree Expand file tree Collapse file tree 3 files changed +95
-0
lines changed
Expand file tree Collapse file tree 3 files changed +95
-0
lines changed Original file line number Diff line number Diff line change @@ -193,6 +193,35 @@ class SomeTest extends ConfigurableKernelTestCase
193193> The kernel configuration objects are * not* passed as arguments to the test method,
194194> which means you can use them anywhere between your provided real test data.
195195
196+ # ### Custom Attributes
197+
198+ You can create your own kernel configuration attributes by implementing the ` KernelConfiguration` interface:
199+
200+ ` ` ` php
201+ use Neusta\P imcore\T estingFramework\K ernel\T estKernel;
202+ use Neusta\P imcore\T estingFramework\T est\A ttribute\K ernelConfiguration;
203+
204+ # [\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
205+ class ConfigureSomeBundle implements KernelConfiguration
206+ {
207+ public function __construct(
208+ private readonly array $config ,
209+ ) {
210+ }
211+
212+ public function configure(TestKernel $kernel ): void
213+ {
214+ $kernel -> addTestBundle(SomeBundle::class);
215+ $kernel -> addTestExtensionConfig(' some' , array_merge(
216+ [' default' => ' config' ],
217+ $this -> config,
218+ ));
219+ }
220+ }
221+ ` ` `
222+
223+ Then you can use the new class as an attribute or inside a data provider.
224+
196225# ## Integration Tests With a Database
197226
198227If you write integration tests that use the database, we' ve got you covered too.
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace Neusta \Pimcore \TestingFramework \Tests \Fixtures \Attribute ;
5+
6+ use Neusta \Pimcore \TestingFramework \Kernel \TestKernel ;
7+ use Neusta \Pimcore \TestingFramework \Test \Attribute \KernelConfiguration ;
8+ use Neusta \Pimcore \TestingFramework \Tests \Fixtures \ConfigurationBundle \ConfigurationBundle ;
9+
10+ #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD )]
11+ final class ConfigureConfigurationBundle implements KernelConfiguration
12+ {
13+ public function __construct (
14+ private readonly array $ config ,
15+ ) {
16+ }
17+
18+ public function configure (TestKernel $ kernel ): void
19+ {
20+ $ kernel ->addTestBundle (ConfigurationBundle::class);
21+ $ kernel ->addTestExtensionConfig ('configuration ' , array_merge (
22+ ['bar ' => ['value2 ' , 'value3 ' ]],
23+ $ this ->config ,
24+ ));
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace Neusta \Pimcore \TestingFramework \Tests \Functional ;
5+
6+ use Neusta \Pimcore \TestingFramework \Test \ConfigurableKernelTestCase ;
7+ use Neusta \Pimcore \TestingFramework \Tests \Fixtures \Attribute \ConfigureConfigurationBundle ;
8+
9+ final class CustomAttributeTest extends ConfigurableKernelTestCase
10+ {
11+ /**
12+ * @test
13+ */
14+ #[ConfigureConfigurationBundle(['foo ' => 'value1 ' ])]
15+ public function configuration_via_attribute (): void
16+ {
17+ $ container = self ::getContainer ();
18+
19+ self ::assertSame ('value1 ' , $ container ->getParameter ('configuration.foo ' ));
20+ self ::assertSame (['value2 ' , 'value3 ' ], $ container ->getParameter ('configuration.bar ' ));
21+ }
22+
23+ public function provideData (): iterable
24+ {
25+ yield [new ConfigureConfigurationBundle (['foo ' => 'test1 ' , 'bar ' => ['test2 ' , 'test3 ' ]])];
26+ }
27+
28+ /**
29+ * @test
30+ *
31+ * @dataProvider provideData
32+ */
33+ public function configuration_via_data_provider (): void
34+ {
35+ $ container = self ::getContainer ();
36+
37+ self ::assertSame ('test1 ' , $ container ->getParameter ('configuration.foo ' ));
38+ self ::assertSame (['test2 ' , 'test3 ' ], $ container ->getParameter ('configuration.bar ' ));
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments