1010use Codeception \Lib \Framework ;
1111use Codeception \TestInterface ;
1212use DoclerLabs \CodeceptionSlimModule \Lib \Connector \SlimPsr7 ;
13+ use Psr \Container \ContainerInterface ;
1314use Slim \App ;
1415
1516/**
2021 * ### Slim 4.x
2122 *
2223 * * application - Relative path to file which bootstrap and returns your `Slim\App` instance.
24+ * * headers - Default headers to be sent with every request (optional).
2325 *
2426 * #### Example (`test/suite/functional.suite.yml`)
2527 * ```yaml
2628 * modules:
2729 * config:
2830 * DoclerLabs\CodeceptionSlimModule\Module\Slim:
2931 * application: 'app/bootstrap.php'
32+ * headers:
33+ * Content-Type: application/json
3034 * ```
3135 *
3236 * ## Public Properties
4549 * config:
4650 * DoclerLabs\CodeceptionSlimModule\Module\Slim:
4751 * application: 'app/bootstrap.php'
52+ * headers:
53+ * Content-Type: application/json
4854 * ```
4955 */
5056class Slim extends Framework
5157{
52- /** @var App */
53- public $ app ;
58+ /** @var App<ContainerInterface|null> */
59+ public App $ app ;
5460
55- /** @var array */
5661 protected array $ requiredFields = ['application ' ];
5762
58- /** @var string */
59- private $ applicationPath ;
63+ protected array $ config = ['headers ' => []];
64+
65+ private string $ applicationPath ;
6066
6167 public function _initialize (): void
6268 {
63- $ applicationPath = Configuration::projectDir () . $ this ->config ['application ' ];
69+ /** @var string $configApplication */
70+ $ configApplication = $ this ->config ['application ' ];
71+ $ applicationPath = Configuration::projectDir () . $ configApplication ;
6472 if (!is_readable ($ applicationPath )) {
6573 throw new ModuleConfigException (
6674 static ::class,
@@ -75,11 +83,10 @@ public function _initialize(): void
7583
7684 public function _before (TestInterface $ test ): void
7785 {
78- /* @noinspection PhpIncludeInspection */
79- $ this ->app = require $ this ->applicationPath ;
86+ $ app = require $ this ->applicationPath ;
8087
8188 // Check if app instance is ready.
82- if (!$ this -> app instanceof App) {
89+ if (!$ app instanceof App) {
8390 throw new ConfigurationException (
8491 sprintf (
8592 "Unable to bootstrap slim application. \n Application file must return with `%s` instance. " ,
@@ -88,11 +95,17 @@ public function _before(TestInterface $test): void
8895 );
8996 }
9097
98+ $ this ->app = $ app ;
99+
91100 $ connector = new SlimPsr7 ();
92101 $ connector ->setApp ($ this ->app );
93102
94103 $ this ->client = $ connector ;
95104
105+ /** @var array<string, string> $headers */
106+ $ headers = $ this ->config ['headers ' ];
107+ $ this ->headers = $ headers ;
108+
96109 parent ::_before ($ test );
97110 }
98111}
0 commit comments