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

ActiveRecordTest::testExplicitPkOnAutoIncrement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 16
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\Sqlite;
6
7
use Yiisoft\ActiveRecord\ActiveQuery;
8
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Beta;
9
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Customer;
10
use Yiisoft\ActiveRecord\Tests\Support\SqliteHelper;
11
use Yiisoft\Db\Connection\ConnectionInterface;
12
13
final class ActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\ActiveRecordTest
0 ignored issues
show
Bug introduced by
The type Yiisoft\ActiveRecord\Tests\ActiveRecordTest 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->setId(1337);
27
        $customer->setEmail('[email protected]');
28
        $customer->setName('user1337');
29
        $customer->setAddress('address1337');
30
31
        $this->assertTrue($customer->getIsNewRecord());
32
        $customer->save();
33
34
        $this->assertEquals(1337, $customer->getId());
35
        $this->assertFalse($customer->getIsNewRecord());
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->getAlpha());
56
            $this->assertEquals($beta->getAlphaStringIdentifier(), $beta->getAlpha()->getStringIdentifier());
57
            $alphaIdentifiers[] = $beta->getAlpha()->getStringIdentifier();
58
        }
59
60
        $this->assertEquals(['1', '01', '001', '001', '2', '2b', '2b', '02'], $alphaIdentifiers);
61
    }
62
}
63