ModelTestTrait   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 2
Metric Value
eloc 17
c 4
b 1
f 2
dl 0
loc 37
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testAttributeHintsForExistingAttributesOnly() 0 4 2
A testRulesForExistingAttributesOnly() 0 6 4
A testAttributeLabelsForExistingAttributesOnly() 0 4 2
A baseUserStringsAttributes() 0 8 1
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, array_merge(get_object_vars($this->model), $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, array_merge(get_object_vars($this->model), $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, array_merge(get_object_vars($this->model), $this->model->attributes));
26
        }
27
    }
28
    public function testRulesForExistingAttributesOnly() {
29
        // labels only for actually existing attributes
30
        foreach ($this->model->rules() as $rule) {
31
            $rules = (is_array($rule[0]) ? $rule[0] : [$rule[0]] );
32
            foreach ($rules as $attribute) {
33
                $this->assertArrayHasKey($attribute, array_merge(get_object_vars($this->model), $this->model->attributes));
34
            }
35
        }
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    public function baseUserStringsAttributes() {
42
        return [
43
            'user_created' => 1,
44
            'user_updated' => 1,
45
            'user_closed' => null,
46
            'time_created' => "2018-11-10 10:10:10",
47
            'time_updated' => "2018-11-10 10:10:10",
48
            'time_closed' => "3333-11-10 10:10:10",
49
        ];
50
    }
51
52
53
}