Unable to save new "ActiveRecord" in database through Codeception

Hi .

I have a simple Unit test :




<?php

namespace frontend\tests\unit\models;


// use common\fixtures\UserFixture;

use frontend\components\Payments;

use common\models\order\Order;


class PaymentCreditCardPayPalTest extends \Codeception\Test\Unit

{

    /**

     * @var \frontend\tests\UnitTester

     */

    protected $tester;


    protected $order;


    public function _before(){

        //this doesn't work

        $this->order = $this->tester->haveRecord(Order::class,

            [

                'id' => 577,

                'payment_type' => 4,

                'status' => 1,

                'amount' => 1,

                'created_by' => 561,

                'updated_by' => 561,

            ]);

    }


    public function testDirectCreditCardPayment(){

        //this does not work either

        /*$model = new Order;

        $model->detachBehavior('BlameableBehavior');

        $model->payment_type = 4;

        $model->status = 1;

        $model->amount = 1;

        $model->created_by = 561;

        $model->updated_by = 561;

        $model->save();*/

    }

}



in which I’m trying to create a new record in “orders” table . So when the test is run it throws an exception :




[yii\db\IntegrityException] SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'created_by' cannot be null



I guess this is due to the so called "BlamemableBehavior" trying to update the "created_by" column . So I tried to detach it and to manually pass the "created_by" value . Neither of both worked . Can you please help ?