Search code examples
phpcodeception

Codeception - How can I get the $scenario property inside a cest method?


I have a Cest class where I want to use the scenario property of $I, but it's generated as protected and no getter is defined for it. I want to see if the scenario is running or not. How can I do this?

The code is something like this:

public function testFunction(ApiGuy $I){

    if ($I->scenario->running()){
    } 

}

ApiGuy extends AbstractGuy that has a property: protected $scenario; so $I->scenario is null, as well as $I->getScenario(). I can add a public function to do this, but every time I build the ApiGuy this gets overwritten. Isn't it another way of doing this?


Solution

  • Just add it as a parameter:

     public function testFunction(ApiGuy $I, $scenario ){
    
         if ($scenario->running()){
              .....
    
         } 
    
     }