ActiveRecordTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
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\ActiveRecord\Beta;
9
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Customer;
10
use Yiisoft\ActiveRecord\Tests\Support\SqliteHelper;
11
12
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...
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->setId(1337);
38
        $customer->setEmail('[email protected]');
39
        $customer->setName('user1337');
40
        $customer->setAddress('address1337');
41
42
        $this->assertTrue($customer->getIsNewRecord());
43
        $customer->save();
44
45
        $this->assertEquals(1337, $customer->getId());
46
        $this->assertFalse($customer->getIsNewRecord());
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->getAlpha());
67
            $this->assertEquals($beta->getAlphaStringIdentifier(), $beta->getAlpha()->getStringIdentifier());
68
            $alphaIdentifiers[] = $beta->getAlpha()->getStringIdentifier();
69
        }
70
71
        $this->assertEquals(['1', '01', '001', '001', '2', '2b', '2b', '02'], $alphaIdentifiers);
72
    }
73
}
74