A
A
Andrey Pavlenko2017-10-20 10:57:25
Yii
Andrey Pavlenko, 2017-10-20 10:57:25

Is Codeception Functional behavior with Yii2 intended?

I came across an interesting feature of Codeception in functional mode.
It can be described in this way.
First: we have a simple controller

class TestController extends Controller
{
public function actionIndex()
{
return $this->renderPartial('test');
}
}

Inside the test template:
<?php
function test() { }

And now back to functional testing.
Let's do a simple check:
public function checkTest(\FunctionalTester $I)
{
        $I->amOnRoute('test/index');
        $I->amOnRoute('test/index');
        //На второй строчке скрипт упадет
}

For some reason, I thought that the script makes requests to the server, but it turns out that a kind of cheat is triggered - the framework, in fact, makes an internal call to actionIndex () twice in a row, as if emulating an HTTP call, and if there is some function inside the template, it will throw an error since we are redefining it a second time. That is, in this case, the framework does not behave like "born to die" every time after the action is called, but will run different actions several times to speed up the process, and if a function is defined in global visibility, will it lay down checks?
PS Let's leave aside that using a function in a template is a code, this is purely an example of a more complicated and tricky hack. I spent 3 hours to figure it out, and it will be a valuable lesson for me to do less dirty code

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question