Passed
Pull Request — master (#368)
by Sergei
03:20
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\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
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 SqliteHelper())->createConnection();
18
    }
19
20
    public function testExplicitPkOnAutoIncrement(): void
21
    {
22
        $this->checkFixture($this->db(), 'customer', true);
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
        $customer->save();
33
34
        $this->assertEquals(1337, $customer->id);
35
        $this->assertFalse($customer->isNewRecord);
36
    }
37
38
    /**
39
     * {@see https://github.com/yiisoft/yii2/issues/15482}
40
     */
41
    public function testEagerLoadingUsingStringIdentifiers(): void
42
    {
43
        $this->checkFixture($this->db(), 'beta');
44
45
        $betaQuery = new ActiveQuery(Beta::class);
46
47
        $betas = $betaQuery->with('alpha')->all();
48
49
        $this->assertNotEmpty($betas);
50
51
        $alphaIdentifiers = [];
52
53
        /** @var Beta[] $betas */
54
        foreach ($betas as $beta) {
55
            $this->assertNotNull($beta->alpha);
56
            $this->assertEquals($beta->alpha_string_identifier, $beta->alpha->string_identifier);
57
            $alphaIdentifiers[] = $beta->alpha->string_identifier;
58
        }
59
60
        $this->assertEquals(['1', '01', '001', '001', '2', '2b', '2b', '02'], $alphaIdentifiers);
61
    }
62
}
63