Completed
Push — master ( 998d49...8eb231 )
by Tõnis
03:03
created

ModelTestTrait::invokeMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace andmemasin\myabstract\test;
4
use yii\base\Model;
5
6
/**
7
 * Trait ModelTestTrait
8
 * @package andmemasin\myabstract\traits
9
 * @author Tõnis Ormisson <[email protected]>
10
 * @property Model $model
11
 */
12
trait ModelTestTrait
13
{
14
    use InvokeProtectedTrait;
15
16
    public function testAttributeLabelsForExistingAttributesOnly() {
17
        // labels only for actually existing attributes
18
        foreach ($this->model->attributeLabels() as $key => $label) {
19
            $this->assertArrayHasKey($key, $this->model->attributes);
0 ignored issues
show
Bug introduced by
It seems like assertArrayHasKey() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

19
            $this->/** @scrutinizer ignore-call */ 
20
                   assertArrayHasKey($key, $this->model->attributes);
Loading history...
20
        }
21
    }
22
    public function testAttributeHintsForExistingAttributesOnly() {
23
        // labels only for actually existing attributes
24
        foreach ($this->model->attributeHints() as $key => $label) {
25
            $this->assertArrayHasKey($key, $this->model->attributes);
26
        }
27
    }
28
    public function testRulesForExistingAttributesOnly() {
29
        // labels only for actually existing attributes
30
        foreach ($this->model->rules() as $rule) {
31
            foreach ($rule[0] as $attribute) {
32
                $this->assertArrayHasKey($attribute, $this->model->attributes);
33
            }
34
        }
35
    }
36
37
38
}