CreditWorkLogCest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 38
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 9 1
A save() 0 19 1
1
<?php
2
3
namespace models;
4
5
use UnitTester;
6
use app\{
7
    fixtures\CreditWorkLogFixture,
8
    models\CreditWorkLog,
9
    models\User
10
};
11
use Yii;
12
use yii\web\ForbiddenHttpException;
13
14
/**
15
 * Cest to credit worklog model.
16
 *
17
 * @author Carlos (neverabe) Llamosas <[email protected]>
18
 */
19
class CreditWorkLogCest
20
{
21
    /**
22
     * @depends models\CreditCest:save
23
     */
24
    public function validate(UnitTester $I)
25
    {
26
        $creditWorklog = new CreditWorkLog();
27
28
        $creditWorklog->process_id = 4;
29
        $I->assertTrue($creditWorklog->validate(['process_id']));
30
31
        $creditWorklog->stage_id = 5;
32
        $I->assertTrue($creditWorklog->validate(['stage_id']));
33
    }
34
35
    /**
36
     * @depends models\CreditCest:save
37
     */
38
    public function save(UnitTester $I)
39
    {
40
        $creditWorklog = new CreditWorkLog();
41
        $creditWorklog->process_id = 4; // current stage_id = 7
42
        $creditWorklog->stage_id = 4;
43
        $I->expectThrowable(
44
            ForbiddenHttpException::class,
45
            function () use ($creditWorklog) {
46
                $creditWorklog->save();
47
            }
48
        );
49
50
        $auth = Yii::$app->authManager;
51
        $adminRole = $auth->getRole('admin');
52
        $auth->assign($adminRole, 1);
53
        Yii::$app->user->login(User::findOne(1));
0 ignored issues
show
Bug introduced by
app\models\User::findOne(1) of type yii\db\ActiveRecord is incompatible with the type yii\web\IdentityInterface expected by parameter $identity of yii\web\User::login(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
        Yii::$app->user->login(/** @scrutinizer ignore-type */ User::findOne(1));
Loading history...
Bug introduced by
The method login() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        Yii::$app->user->/** @scrutinizer ignore-call */ 
54
                         login(User::findOne(1));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
55
        $I->assertTrue($creditWorklog->save());
56
        $auth->revoke($adminRole, 1);
57
    }
58
}