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