I
I
Ilya Ryabtsev2018-03-05 13:29:15
Software testing
Ilya Ryabtsev, 2018-03-05 13:29:15

Codeception + yii2, who will explain the truthway for working with behaviors (upload pictures), working with databases and fixtures?

A short introduction:
We have many large and medium-sized projects written in Yii2. The problem is as old as the world: testing is needed to reduce the time it takes to maintain existing applications. In tests, we only understand that they are needed like air;)
- I decided to use Codeception,
- We deployed it, made basic tests, + - I understand where everything is and why.
- I deployed the project specifically with a bug, which I try to catch but it doesn't work - the test completes successfully.
Urgent questions:
- There is a site with goods, there are labels for goods (ala action, discount, etc.) It looks like this: joxi.ru/4AkOBRPfMzdVnA On the left is a display on the site, on the right is a form for editing.
- The bug I'm trying to catch, (the picture for the sticker is required) - when editing an existing sticker, and saving it unchanged, an error is generated: "It is necessary to fill in the "Image."" Screen shot: joxi.ru/ZrJq8oLH14X04A
- The test code looks like this:

$I->amOnPage('/admin/products/site-stickers/update/5');
        $I->attachFile('#sitestickers-image', 'lace.png');
        $I->See('StickerForTest');
        $I->click('Сохранить');
        $I->dontSeeElement('.has-error');

- Test result: ✔ SiteStickersCest: Edit correct sticker (0.09s)
*The model uses behavior, didn't think of anything except debugging it (otherwise error status 0 - the file is loaded, but gives an error (apparently due to the need for further manipulations with it) )):
public function actionUpdate($id)
    {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
           if (YII_ENV=='test') {
                $model->detachBehavior('photo');
            }
            $model->save( false );
            return $this->redirect(['index']);


        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    }

- Tell me what I'm doing wrong?
- - The task is to cover the project not completely with tests, but to test the main critical functionality,
- - I would like to fully test the loading of the image, its further processing, writing to the model database, and checking its recording.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Ryabtsev, 2018-03-05
@codepug

Colleagues, we are looking for an enthusiast who is ready to explain for $ on Skype or in an office in Moscow, the main approaches, and, for example, cover a working application with tests with my hands.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question