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