yii2 Testing How to mock ActiveRecord


If you want to mock AR that doesn't try to connect to database you can do it in the following way (if using PHPUnit):

$post = $this->getMockBuilder('\app\model\Post')
    ->setMethods(['save', 'attributes'])

The catch is that we need to override attributes() method since ActiveRecord by default is getting attributes list from database schema which we're trying to avoid.