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

MagicActiveRecordTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 27
dl 0
loc 60
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testEagerLoadingUsingStringIdentifiers() 0 20 2
A tearDown() 0 7 1
A setUp() 0 6 1
A testExplicitPkOnAutoIncrement() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Tests\Driver\Sqlite;
6
7
use Yiisoft\ActiveRecord\ActiveQuery;
8
use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\Beta;
9
use Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord\Customer;
10
use Yiisoft\ActiveRecord\Tests\Support\SqliteHelper;
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
        $sqliteHelper = new SqliteHelper();
19
        $this->db = $sqliteHelper->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 testExplicitPkOnAutoIncrement(): void
32
    {
33
        $this->checkFixture($this->db, 'customer', true);
34
35
        $customer = new Customer($this->db);
36
37
        $customer->id = 1337;
38
        $customer->email = '[email protected]';
39
        $customer->name = 'user1337';
40
        $customer->address = 'address1337';
41
42
        $this->assertTrue($customer->isNewRecord);
0 ignored issues
show
Bug Best Practice introduced by
The property isNewRecord does not exist on Yiisoft\ActiveRecord\Tes...icActiveRecord\Customer. Since you implemented __get, consider adding a @property annotation.
Loading history...
43
        $customer->save();
44
45
        $this->assertEquals(1337, $customer->id);
46
        $this->assertFalse($customer->isNewRecord);
47
    }
48
49
    /**
50
     * {@see https://github.com/yiisoft/yii2/issues/15482}
51
     */
52
    public function testEagerLoadingUsingStringIdentifiers(): void
53
    {
54
        $this->checkFixture($this->db, 'beta');
55
56
        $betaQuery = new ActiveQuery(Beta::class, $this->db);
57
58
        $betas = $betaQuery->with('alpha')->all();
59
60
        $this->assertNotEmpty($betas);
61
62
        $alphaIdentifiers = [];
63
64
        /** @var Beta[] $betas */
65
        foreach ($betas as $beta) {
66
            $this->assertNotNull($beta->alpha);
67
            $this->assertEquals($beta->alpha_string_identifier, $beta->alpha->string_identifier);
68
            $alphaIdentifiers[] = $beta->alpha->string_identifier;
69
        }
70
71
        $this->assertEquals(['1', '01', '001', '001', '2', '2b', '2b', '02'], $alphaIdentifiers);
72
    }
73
}
74