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

testExplicitPkOnAutoIncrement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 17
rs 9.9332
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\Mysql;
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\MysqlHelper;
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
        $mysqlHelper = new MysqlHelper();
19
        $this->db = $mysqlHelper->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');
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
44
        $customer->save();
45
46
        $this->assertEquals(1337, $customer->id);
47
        $this->assertFalse($customer->isNewRecord);
48
    }
49
50
    /**
51
     * {@see https://github.com/yiisoft/yii2/issues/15482}
52
     */
53
    public function testEagerLoadingUsingStringIdentifiers(): void
54
    {
55
        $this->checkFixture($this->db, 'beta');
56
57
        $betaQuery = new ActiveQuery(Beta::class, $this->db);
58
59
        $betas = $betaQuery->with('alpha')->all();
60
61
        $this->assertNotEmpty($betas);
62
63
        $alphaIdentifiers = [];
64
65
        /** @var Beta[] $betas */
66
        foreach ($betas as $beta) {
67
            $this->assertNotNull($beta->alpha);
68
            $this->assertEquals($beta->alpha_string_identifier, $beta->alpha->string_identifier);
69
            $alphaIdentifiers[] = $beta->alpha->string_identifier;
70
        }
71
72
        $this->assertEquals(['1', '01', '001', '001', '2', '2b', '2b', '02'], $alphaIdentifiers);
73
    }
74
}
75