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\Driver\Mysql\Stubs\Type; |
9
|
|
|
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Beta; |
10
|
|
|
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Customer; |
11
|
|
|
use Yiisoft\ActiveRecord\Tests\Support\MysqlHelper; |
12
|
|
|
|
13
|
|
|
final class ActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\ActiveRecordTest |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
public function setUp(): void |
16
|
|
|
{ |
17
|
|
|
parent::setUp(); |
18
|
|
|
|
19
|
|
|
$mysqlHelper = new MysqlHelper(); |
20
|
|
|
$this->db = $mysqlHelper->createConnection(); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
protected function tearDown(): void |
24
|
|
|
{ |
25
|
|
|
parent::tearDown(); |
26
|
|
|
|
27
|
|
|
$this->db->close(); |
28
|
|
|
|
29
|
|
|
unset($this->db); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testCastValues(): void |
33
|
|
|
{ |
34
|
|
|
$this->checkFixture($this->db, 'type'); |
35
|
|
|
|
36
|
|
|
$arClass = new Type($this->db); |
37
|
|
|
|
38
|
|
|
$arClass->int_col = 123; |
39
|
|
|
$arClass->int_col2 = 456; |
40
|
|
|
$arClass->smallint_col = 42; |
41
|
|
|
$arClass->char_col = '1337'; |
42
|
|
|
$arClass->char_col2 = 'test'; |
43
|
|
|
$arClass->char_col3 = 'test123'; |
44
|
|
|
$arClass->enum_col = 'B'; |
45
|
|
|
$arClass->float_col = 3.742; |
46
|
|
|
$arClass->float_col2 = 42.1337; |
47
|
|
|
$arClass->bool_col = true; |
48
|
|
|
$arClass->bool_col2 = false; |
49
|
|
|
|
50
|
|
|
$arClass->save(); |
51
|
|
|
|
52
|
|
|
/** @var $model Type */ |
53
|
|
|
$aqClass = new ActiveQuery(Type::class, $this->db); |
54
|
|
|
$query = $aqClass->onePopulate(); |
55
|
|
|
|
56
|
|
|
$this->assertSame(123, $query->int_col); |
|
|
|
|
57
|
|
|
$this->assertSame(456, $query->int_col2); |
|
|
|
|
58
|
|
|
$this->assertSame(42, $query->smallint_col); |
|
|
|
|
59
|
|
|
$this->assertSame('1337', trim($query->char_col)); |
|
|
|
|
60
|
|
|
$this->assertSame('test', $query->char_col2); |
|
|
|
|
61
|
|
|
$this->assertSame('test123', $query->char_col3); |
|
|
|
|
62
|
|
|
$this->assertSame('B', $query->enum_col); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testExplicitPkOnAutoIncrement(): void |
66
|
|
|
{ |
67
|
|
|
$this->checkFixture($this->db, 'customer'); |
68
|
|
|
|
69
|
|
|
$customer = new Customer($this->db); |
70
|
|
|
|
71
|
|
|
$customer->setId(1337); |
72
|
|
|
$customer->setEmail('[email protected]'); |
73
|
|
|
$customer->setName('user1337'); |
74
|
|
|
$customer->setAddress('address1337'); |
75
|
|
|
|
76
|
|
|
$this->assertTrue($customer->getIsNewRecord()); |
77
|
|
|
|
78
|
|
|
$customer->save(); |
79
|
|
|
|
80
|
|
|
$this->assertEquals(1337, $customer->getId()); |
81
|
|
|
$this->assertFalse($customer->getIsNewRecord()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@see https://github.com/yiisoft/yii2/issues/15482} |
86
|
|
|
*/ |
87
|
|
|
public function testEagerLoadingUsingStringIdentifiers(): void |
88
|
|
|
{ |
89
|
|
|
$this->checkFixture($this->db, 'beta'); |
90
|
|
|
|
91
|
|
|
$betaQuery = new ActiveQuery(Beta::class, $this->db); |
92
|
|
|
|
93
|
|
|
$betas = $betaQuery->with('alpha')->all(); |
94
|
|
|
|
95
|
|
|
$this->assertNotEmpty($betas); |
96
|
|
|
|
97
|
|
|
$alphaIdentifiers = []; |
98
|
|
|
|
99
|
|
|
/** @var Beta[] $betas */ |
100
|
|
|
foreach ($betas as $beta) { |
101
|
|
|
$this->assertNotNull($beta->getAlpha()); |
102
|
|
|
$this->assertEquals($beta->getAlphaStringIdentifier(), $beta->getAlpha()->getStringIdentifier()); |
103
|
|
|
$alphaIdentifiers[] = $beta->getAlpha()->getStringIdentifier(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$this->assertEquals(['1', '01', '001', '001', '2', '2b', '2b', '02'], $alphaIdentifiers); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths