Codeception / Codeception/module-lumen

Multiple inititalize in Lumen module

Abierto
#5 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
PHP
Estrellas
0
Forks
5
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Hey Guys!

I'm here again with an another issue with the Lumen module. When I'd like to make tests that contains more than one facade mocks, then the second mock won't be applied (it remains the original class).

for example:
```php
// this is a facade mock:
\AnyNamespace\Facades\Classname::shouldReceive('command1')->andReturnTrue();
$I->sendGET('/path');

// this isn't:
\AnyNamespace\Facades\Classname::shouldReceive('command2')->andReturnTrue();
$I->sendGET('/path');
```
...because the Lumen connector initialize the client again after the second REST call (see doRequest method below), and this function will clear the previously resolved instances.

```php
// in Codeception/Lib/Connector/Lumen.php
public function __construct($module)
{
...
// constructor already initialize the module
$this->initialize();
}
...
protected function doRequest($request)
{
// firstRequest is true by default
if (!$this->firstRequest) {
// I really don't know why suppose to re-initialize the whole module,
// it's already initilaized in the constructor method
$this->initialize($request);
}
$this->firstRequest = false;
....
}

private function initialize($request = null)
{
....
if (class_exists(Facade::class)) {
// this will drop all previously resolved facades,
// and won't let my tests run correctly
Facade::clearResolvedInstances();
}
....
```
The whole firstRequest check should be removed in my opinion. I can make a PR for this.

* Codeception version: 2.5.6
* PHP Version: 7.2.13

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.