|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\ActiveRecord\Tests\Driver\Oracle; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\ActiveRecord\ActiveQuery; |
|
8
|
|
|
use Yiisoft\ActiveRecord\Tests\Driver\Oracle\Stubs\Customer; |
|
9
|
|
|
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\CustomerClosureField; |
|
10
|
|
|
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\CustomerForArrayable; |
|
11
|
|
|
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Type; |
|
12
|
|
|
use Yiisoft\ActiveRecord\Tests\Support\OracleHelper; |
|
13
|
|
|
|
|
14
|
|
|
final class ActiveRecordTest extends \Yiisoft\ActiveRecord\Tests\ActiveRecordTest |
|
|
|
|
|
|
15
|
|
|
{ |
|
16
|
|
|
public function setUp(): void |
|
17
|
|
|
{ |
|
18
|
|
|
parent::setUp(); |
|
19
|
|
|
|
|
20
|
|
|
$oracleHelper = new OracleHelper(); |
|
21
|
|
|
$this->db = $oracleHelper->createConnection(); |
|
|
|
|
|
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
protected function tearDown(): void |
|
25
|
|
|
{ |
|
26
|
|
|
parent::tearDown(); |
|
27
|
|
|
|
|
28
|
|
|
$this->db->close(); |
|
29
|
|
|
|
|
30
|
|
|
unset($this->db); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testCastValues(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->markTestSkipped('Cant bind floats without support from a custom PDO driver.'); |
|
36
|
|
|
|
|
37
|
|
|
$this->checkFixture($this->db, 'customer'); |
|
38
|
|
|
|
|
39
|
|
|
$arClass = new Type($this->db); |
|
40
|
|
|
$arClass->int_col = 123; |
|
41
|
|
|
$arClass->int_col2 = 456; |
|
42
|
|
|
$arClass->smallint_col = 42; |
|
43
|
|
|
$arClass->char_col = '1337'; |
|
44
|
|
|
$arClass->char_col2 = 'test'; |
|
45
|
|
|
$arClass->char_col3 = 'test123'; |
|
46
|
|
|
/** can't bind floats without support from a custom PDO driver */ |
|
47
|
|
|
$arClass->float_col = 2; |
|
48
|
|
|
$arClass->float_col2 = 1; |
|
49
|
|
|
$arClass->bool_col = 1; |
|
|
|
|
|
|
50
|
|
|
$arClass->bool_col2 = 0; |
|
|
|
|
|
|
51
|
|
|
$arClass->save(); |
|
52
|
|
|
|
|
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(2.0, $query->float_col); |
|
|
|
|
|
|
63
|
|
|
$this->assertSame(1.0, $query->float_col2); |
|
|
|
|
|
|
64
|
|
|
$this->assertEquals('1', $query->bool_col); |
|
|
|
|
|
|
65
|
|
|
$this->assertEquals('0', $query->bool_col2); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testDefaultValues(): void |
|
69
|
|
|
{ |
|
70
|
|
|
$this->checkFixture($this->db, 'customer'); |
|
71
|
|
|
|
|
72
|
|
|
$arClass = new Type($this->db); |
|
73
|
|
|
$arClass->loadDefaultValues(); |
|
74
|
|
|
$this->assertEquals(1, $arClass->int_col2); |
|
75
|
|
|
$this->assertEquals('something', $arClass->char_col2); |
|
76
|
|
|
$this->assertEquals(1.23, $arClass->float_col2); |
|
77
|
|
|
$this->assertEquals(33.22, $arClass->numeric_col); |
|
78
|
|
|
$this->assertEquals('1', $arClass->bool_col2); |
|
79
|
|
|
|
|
80
|
|
|
// not testing $arClass->time, because oci\Schema can't read default value |
|
81
|
|
|
|
|
82
|
|
|
$arClass = new Type($this->db); |
|
83
|
|
|
$arClass->char_col2 = 'not something'; |
|
84
|
|
|
|
|
85
|
|
|
$arClass->loadDefaultValues(); |
|
86
|
|
|
$this->assertEquals('not something', $arClass->char_col2); |
|
87
|
|
|
|
|
88
|
|
|
$arClass = new Type($this->db); |
|
89
|
|
|
$arClass->char_col2 = 'not something'; |
|
90
|
|
|
|
|
91
|
|
|
$arClass->loadDefaultValues(false); |
|
92
|
|
|
$this->assertEquals('something', $arClass->char_col2); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Some PDO implementations (e.g. cubrid) do not support boolean values. |
|
97
|
|
|
* |
|
98
|
|
|
* Make sure this does not affect AR layer. |
|
99
|
|
|
*/ |
|
100
|
|
|
public function testBooleanAttribute(): void |
|
101
|
|
|
{ |
|
102
|
|
|
$this->checkFixture($this->db, 'customer', true); |
|
103
|
|
|
|
|
104
|
|
|
$customer = new Customer($this->db); |
|
105
|
|
|
|
|
106
|
|
|
$customer->name = 'boolean customer'; |
|
107
|
|
|
$customer->email = '[email protected]'; |
|
108
|
|
|
$customer->status = '1'; |
|
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
$customer->save(); |
|
111
|
|
|
$customer->refresh(); |
|
112
|
|
|
$this->assertEquals('1', $customer->status); |
|
113
|
|
|
|
|
114
|
|
|
$customer->status = '0'; |
|
115
|
|
|
$customer->save(); |
|
116
|
|
|
|
|
117
|
|
|
$customer->refresh(); |
|
118
|
|
|
$this->assertEquals('0', $customer->status); |
|
119
|
|
|
|
|
120
|
|
|
$customerQuery = new ActiveQuery(Customer::class, $this->db); |
|
121
|
|
|
$customers = $customerQuery->where(['status' => '1'])->all(); |
|
122
|
|
|
$this->assertCount(2, $customers); |
|
123
|
|
|
|
|
124
|
|
|
$customerQuery = new ActiveQuery(Customer::class, $this->db); |
|
125
|
|
|
$customers = $customerQuery->where(['status' => '0'])->all(); |
|
126
|
|
|
$this->assertCount(1, $customers); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function testToArray(): void |
|
130
|
|
|
{ |
|
131
|
|
|
$this->checkFixture($this->db, 'customer', true); |
|
132
|
|
|
|
|
133
|
|
|
$customerQuery = new ActiveQuery(Customer::class, $this->db); |
|
134
|
|
|
$customer = $customerQuery->findOne(1); |
|
135
|
|
|
|
|
136
|
|
|
$this->assertSame( |
|
137
|
|
|
[ |
|
138
|
|
|
'id' => 1, |
|
139
|
|
|
'email' => '[email protected]', |
|
140
|
|
|
'name' => 'user1', |
|
141
|
|
|
'address' => 'address1', |
|
142
|
|
|
'status' => 1, |
|
143
|
|
|
'bool_status' => '1', |
|
144
|
|
|
'profile_id' => 1, |
|
145
|
|
|
], |
|
146
|
|
|
$customer->toArray(), |
|
147
|
|
|
); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
public function testToArrayWithClosure(): void |
|
151
|
|
|
{ |
|
152
|
|
|
$this->checkFixture($this->db, 'customer', true); |
|
153
|
|
|
|
|
154
|
|
|
$customerQuery = new ActiveQuery(CustomerClosureField::class, $this->db); |
|
155
|
|
|
$customer = $customerQuery->findOne(1); |
|
156
|
|
|
|
|
157
|
|
|
$this->assertSame( |
|
158
|
|
|
[ |
|
159
|
|
|
'id' => 1, |
|
160
|
|
|
'email' => '[email protected]', |
|
161
|
|
|
'name' => 'user1', |
|
162
|
|
|
'address' => 'address1', |
|
163
|
|
|
'status' => 'active', |
|
164
|
|
|
'bool_status' => '1', |
|
165
|
|
|
'profile_id' => 1, |
|
166
|
|
|
], |
|
167
|
|
|
$customer->toArray(), |
|
168
|
|
|
); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
public function testToArrayForArrayable(): void |
|
172
|
|
|
{ |
|
173
|
|
|
$this->checkFixture($this->db, 'customer', true); |
|
174
|
|
|
|
|
175
|
|
|
$customerQuery = new ActiveQuery(CustomerForArrayable::class, $this->db); |
|
176
|
|
|
|
|
177
|
|
|
/** @var CustomerForArrayable $customer */ |
|
178
|
|
|
$customer = $customerQuery->findOne(1); |
|
179
|
|
|
/** @var CustomerForArrayable $customer2 */ |
|
180
|
|
|
$customer2 = $customerQuery->findOne(2); |
|
181
|
|
|
/** @var CustomerForArrayable $customer3 */ |
|
182
|
|
|
$customer3 = $customerQuery->findOne(3); |
|
183
|
|
|
|
|
184
|
|
|
$customer->setItem($customer2); |
|
185
|
|
|
$customer->setItems($customer3); |
|
186
|
|
|
|
|
187
|
|
|
$this->assertSame( |
|
188
|
|
|
[ |
|
189
|
|
|
'id' => 1, |
|
190
|
|
|
'name' => 'user1', |
|
191
|
|
|
'email' => '[email protected]', |
|
192
|
|
|
'address' => 'address1', |
|
193
|
|
|
'status' => 'active', |
|
194
|
|
|
'item' => [ |
|
195
|
|
|
'id' => 2, |
|
196
|
|
|
'name' => 'user2', |
|
197
|
|
|
'email' => '[email protected]', |
|
198
|
|
|
'status' => 'active', |
|
199
|
|
|
], |
|
200
|
|
|
'items' => [ |
|
201
|
|
|
[ |
|
202
|
|
|
'id' => 3, |
|
203
|
|
|
'name' => 'user3', |
|
204
|
|
|
'email' => '[email protected]', |
|
205
|
|
|
'status' => 'inactive', |
|
206
|
|
|
], |
|
207
|
|
|
], |
|
208
|
|
|
], |
|
209
|
|
|
$customer->toArray([ |
|
210
|
|
|
'id', |
|
211
|
|
|
'name', |
|
212
|
|
|
'email', |
|
213
|
|
|
'address', |
|
214
|
|
|
'status', |
|
215
|
|
|
'item.id', |
|
216
|
|
|
'item.name', |
|
217
|
|
|
'item.email', |
|
218
|
|
|
'items.0.id', |
|
219
|
|
|
'items.0.name', |
|
220
|
|
|
'items.0.email', |
|
221
|
|
|
]), |
|
222
|
|
|
); |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
|
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