Passed
Push — master ( bc8b6f...7a9b1f )
by Sergei
02:57
created

MagicActiveRecordTest::testSaveWithTrigger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 36
rs 9.52
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\MagicActiveRecord\TestTrigger;
9
use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\TestTriggerAlert;
10
use Yiisoft\ActiveRecord\Tests\Support\MssqlHelper;
11
12
final class MagicActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\MagicActiveRecordTest
0 ignored issues
show
Bug introduced by
The type Yiisoft\ActiveRecord\Tests\MagicActiveRecordTest 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...
13
{
14
    public function setUp(): void
15
    {
16
        parent::setUp();
17
18
        $mssqlHelper = new MssqlHelper();
19
        $this->db = $mssqlHelper->createConnection();
0 ignored issues
show
Bug Best Practice introduced by
The property db does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
20
    }
21
22
    protected function tearDown(): void
23
    {
24
        parent::tearDown();
25
26
        $this->db->close();
27
28
        unset($this->db);
29
    }
30
31
    public function testSaveWithTrigger(): void
32
    {
33
        $this->checkFixture($this->db, 'test_trigger');
34
35
        // drop trigger if exist
36
        $sql = <<<SQL
37
        IF (OBJECT_ID('[dbo].[test_alert]') IS NOT NULL)
38
        BEGIN
39
            DROP TRIGGER [dbo].[test_alert];
40
        END
41
        SQL;
42
        $this->db->createCommand($sql)->execute();
43
44
        // create trigger
45
        $sql = <<<SQL
46
        CREATE TRIGGER [dbo].[test_alert] ON [dbo].[test_trigger]
47
        AFTER INSERT
48
        AS
49
        BEGIN
50
            INSERT INTO [dbo].[test_trigger_alert] ( [stringcol] )
51
            SELECT [stringcol]
52
            FROM [inserted]
53
        END
54
        SQL;
55
        $this->db->createCommand($sql)->execute();
56
57
        $record = new TestTrigger($this->db);
58
59
        $record->stringcol = 'test';
60
61
        $this->assertTrue($record->save());
62
        $this->assertEquals(1, $record->id);
63
64
        $testRecordQuery = new ActiveQuery(TestTriggerAlert::class, $this->db);
65
66
        $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...
67
    }
68
}
69