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

MagicActiveRecordTest::createConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
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
use Yiisoft\Db\Connection\ConnectionInterface;
12
13
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...
14
{
15
    protected function createConnection(): ConnectionInterface
16
    {
17
        return (new MysqlHelper())->createConnection();
18
    }
19
20
    public function testExplicitPkOnAutoIncrement(): void
21
    {
22
        $this->checkFixture($this->db(), 'customer');
23
24
        $customer = new Customer();
25
26
        $customer->id = 1337;
27
        $customer->email = '[email protected]';
28
        $customer->name = 'user1337';
29
        $customer->address = 'address1337';
30
31
        $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...
32
33
        $customer->save();
34
35
        $this->assertEquals(1337, $customer->id);
36
        $this->assertFalse($customer->isNewRecord);
37
    }
38
39
    /**
40
     * {@see https://github.com/yiisoft/yii2/issues/15482}
41
     */
42
    public function testEagerLoadingUsingStringIdentifiers(): void
43
    {
44
        $this->checkFixture($this->db(), 'beta');
45
46
        $betaQuery = new ActiveQuery(Beta::class);
47
48
        $betas = $betaQuery->with('alpha')->all();
49
50
        $this->assertNotEmpty($betas);
51
52
        $alphaIdentifiers = [];
53
54
        /** @var Beta[] $betas */
55
        foreach ($betas as $beta) {
56
            $this->assertNotNull($beta->alpha);
57
            $this->assertEquals($beta->alpha_string_identifier, $beta->alpha->string_identifier);
58
            $alphaIdentifiers[] = $beta->alpha->string_identifier;
59
        }
60
61
        $this->assertEquals(['1', '01', '001', '001', '2', '2b', '2b', '02'], $alphaIdentifiers);
62
    }
63
}
64