Passed
Pull Request — master (#368)
by Sergei
02:42
created

ActiveRecordTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ActiveRecordTest::createConnection() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Tests\Driver\Mssql;
6
7
use Yiisoft\ActiveRecord\ActiveQuery;
8
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\TestTrigger;
9
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\TestTriggerAlert;
10
use Yiisoft\ActiveRecord\Tests\Support\MssqlHelper;
11
use Yiisoft\Db\Connection\ConnectionInterface;
12
13
final class ActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\ActiveRecordTest
0 ignored issues
show
Bug introduced by
The type Yiisoft\ActiveRecord\Tests\ActiveRecordTest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
{
15
    protected function createConnection(): ConnectionInterface
16
    {
17
        return (new MssqlHelper())->createConnection();
18
    }
19
20
    public function testSaveWithTrigger(): void
21
    {
22
        $this->checkFixture($this->db(), 'test_trigger');
23
24
        // drop trigger if exist
25
        $sql = <<<SQL
26
        IF (OBJECT_ID('[dbo].[test_alert]') IS NOT NULL)
27
        BEGIN
28
            DROP TRIGGER [dbo].[test_alert];
29
        END
30
        SQL;
31
        $this->db()->createCommand($sql)->execute();
32
33
        // create trigger
34
        $sql = <<<SQL
35
        CREATE TRIGGER [dbo].[test_alert] ON [dbo].[test_trigger]
36
        AFTER INSERT
37
        AS
38
        BEGIN
39
            INSERT INTO [dbo].[test_trigger_alert] ( [stringcol] )
40
            SELECT [stringcol]
41
            FROM [inserted]
42
        END
43
        SQL;
44
        $this->db()->createCommand($sql)->execute();
45
46
        $record = new TestTrigger($this->db());
0 ignored issues
show
Unused Code introduced by
The call to Yiisoft\ActiveRecord\Tes...tTrigger::__construct() has too many arguments starting with $this->db(). ( Ignorable by Annotation )

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

46
        $record = /** @scrutinizer ignore-call */ new TestTrigger($this->db());

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...
47
48
        $record->stringcol = 'test';
49
50
        $this->assertTrue($record->save());
51
        $this->assertEquals(1, $record->id);
52
53
        $testRecordQuery = new ActiveQuery(TestTriggerAlert::class);
54
55
        $this->assertEquals('test', $testRecordQuery->findOne(1)->stringcol);
0 ignored issues
show
Bug introduced by
Accessing stringcol on the interface Yiisoft\ActiveRecord\ActiveRecordInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
56
    }
57
}
58