Completed
Push — master ( 096858...7ec34d )
by Gabriel
03:50
created

ActiveRecordsTraitTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 16
c 1
b 0
f 1
dl 0
loc 29
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A test_insert() 0 27 1
1
<?php
2
3
namespace Nip\Records\Tests\Traits\ActiveRecord;
4
5
use Mockery\Mock;
6
use Nip\Records\EventManager\Events\Event;
7
use Nip\Records\Tests\AbstractTest;
8
use Nip\Records\Tests\Fixtures\Records\Books\Book;
9
use Nip\Records\Tests\Fixtures\Records\Books\Books;
10
11
/**
12
 * Class ActiveRecordsTraitTest
13
 * @package Nip\Records\Tests\Traits\ActiveRecord
14
 */
15
class ActiveRecordsTraitTest extends AbstractTest
16
{
17
    public function test_insert()
18
    {
19
        /** @var Mock|Books $books */
20
        $books = Books::instance();
21
        $listener = [];
22
        $books::creating(
23
            function (Event $event) use (&$listener) {
24
                $listener[] = $event->getName();
25
            }
26
        );
27
        $books::created(
28
            function (Event $event) use (&$listener) {
29
                $listener[] = $event->getName();
30
            }
31
        );
32
33
        $book = new Book(['test' => 'foe']);
0 ignored issues
show
Unused Code introduced by
The call to Nip\Records\Tests\Fixtur...oks\Book::__construct() has too many arguments starting with array('test' => 'foe'). ( Ignorable by Annotation )

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

33
        $book = /** @scrutinizer ignore-call */ new Book(['test' => 'foe']);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
34
        $book->setManager($books);
35
36
        $book->insert();
37
38
        self::assertSame(
39
            [
40
                'orm.creating: Nip\Records\Tests\Fixtures\Records\Books\Books',
41
                'orm.created: Nip\Records\Tests\Fixtures\Records\Books\Books'
42
            ],
43
            $listener
44
        );
45
    }
46
}