Skip to content

Commit 6ba8cef

Browse files
committed
allow bundle specific php preloads
1 parent 6bead14 commit 6ba8cef

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ include_once $bootstrap;
3434
## Setup File
3535
Create a file called `config.yml` in `tests/_etc/config.yml`.
3636

37-
> ! Files in `setup_files` node needs to stored in `/tests/_etc/config`.
38-
3937
```yaml
4038
setup_files:
4139
- { path: app/config.yml, dest: ./app/config/config.yml }
4240
- { path: app/system.yml, dest: ./var/config/system.yml }
4341
- { path: app/controller/DefaultController.php, dest: ./src/AppBundle/Controller/DefaultController.php }
4442
- { path: app/views/default.html.twig, dest: ./app/Resources/views/Default/default.html.twig }
4543
- { path: app/views/snippet.html.twig, dest: ./app/Resources/views/Default/snippet.html.twig }
44+
preload_files:
45+
- { path: Services/MySpecialTestService.php }
4646
```
47+
### Configuration
48+
- **setup_files**: All your template files which should to be available during test cycles. These files need to be stored under `/tests/_etc/config`
49+
- **preload_files** _(optional)_: These files will be included at kernel setup. Since these files are not included via composer autoload, we need to define them here.
4750

4851
## Bundle Configuration Files
4952
This Framework allows you to use multiple (bundle) configuration setups.

src/_support/App/TestKernel.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
99
use Symfony\Component\DependencyInjection\ContainerBuilder;
1010
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
11+
use Symfony\Component\Yaml\Yaml;
1112

1213
class TestKernel extends Kernel
1314
{
@@ -66,10 +67,22 @@ protected function build(ContainerBuilder $container)
6667
protected function preloadClasses()
6768
{
6869
$fwDir = sprintf('%s/src', $_SERVER['PIMCORE_CODECEPTION_FRAMEWORK']);
70+
$bDir = sprintf('%s', $_SERVER['TEST_BUNDLE_TEST_DIR']);
6971

70-
foreach (self::PRELOAD_FILES as $class) {
71-
$classPath = sprintf('%s/_support/%s', $fwDir, $class);
72-
include_once $classPath;
72+
$bundlesFiles = [];
73+
$data = Yaml::parse(file_get_contents(sprintf('%s/_etc/config.yml', $_SERVER['TEST_BUNDLE_TEST_DIR'])));
74+
75+
if (isset($data['preload_files']) && is_array($data['preload_files'])) {
76+
foreach ($data['preload_files'] as $bpFile) {
77+
$bundlesFiles[] = $bpFile['path'];
78+
}
79+
}
80+
81+
foreach ([$bDir => $bundlesFiles, $fwDir => self::PRELOAD_FILES] as $dir => $files) {
82+
foreach ($files as $class) {
83+
$classPath = sprintf('%s/_support/%s', $dir, $class);
84+
include_once $classPath;
85+
}
7386
}
7487
}
7588

0 commit comments

Comments
 (0)