Skip to content

Commit 0f3fd98

Browse files
authored
Update tests (#408)
1 parent 7c6656d commit 0f3fd98

15 files changed

+75
-303
lines changed

tests/ActiveQueryTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2222,8 +2222,8 @@ public function testIsPropertyChanged(): void
22222222
$query = new ActiveQuery(Customer::class);
22232223

22242224
$customer = $query->findOne(1);
2225-
$this->assertEquals(true, $customer->get('bool_status'));
2226-
$this->assertEquals(true, $customer->oldValue('bool_status'));
2225+
$this->assertTrue($customer->get('bool_status'));
2226+
$this->assertTrue($customer->oldValue('bool_status'));
22272227

22282228
$customer->set('bool_status', 1);
22292229

tests/ActiveRecordTest.php

+19-22
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ public function testDefaultValues(): void
162162

163163
$arClass->loadDefaultValues();
164164

165-
$this->assertEquals(1, $arClass->int_col2);
166-
$this->assertEquals('something', $arClass->char_col2);
167-
$this->assertEquals(1.23, $arClass->float_col2);
168-
$this->assertEquals(33.22, $arClass->numeric_col);
165+
$this->assertSame(1, $arClass->int_col2);
166+
$this->assertSame('something', $arClass->char_col2);
167+
$this->assertSame(1.23, $arClass->float_col2);
168+
$this->assertSame(33.22, $arClass->numeric_col);
169169
$this->assertTrue($arClass->bool_col2);
170-
$this->assertEquals('2002-01-01 00:00:00', $arClass->time);
170+
$this->assertSame('2002-01-01 00:00:00', $arClass->time);
171171

172172
if ($this->db()->getDriverName() !== 'mysql') {
173173
$this->assertSame(['a' => 1], $arClass->json_col);
@@ -177,13 +177,13 @@ public function testDefaultValues(): void
177177
$arClass->char_col2 = 'not something';
178178

179179
$arClass->loadDefaultValues();
180-
$this->assertEquals('not something', $arClass->char_col2);
180+
$this->assertSame('not something', $arClass->char_col2);
181181

182182
$arClass = new Type();
183183
$arClass->char_col2 = 'not something';
184184

185185
$arClass->loadDefaultValues(false);
186-
$this->assertEquals('something', $arClass->char_col2);
186+
$this->assertSame('something', $arClass->char_col2);
187187
}
188188

189189
public function testCastValues(): void
@@ -219,8 +219,8 @@ public function testCastValues(): void
219219
$this->assertSame('test123', $query->char_col3);
220220
$this->assertSame(3.742, $query->float_col);
221221
$this->assertSame(42.1337, $query->float_col2);
222-
$this->assertEquals(true, $query->bool_col);
223-
$this->assertEquals(false, $query->bool_col2);
222+
$this->assertTrue($query->bool_col);
223+
$this->assertFalse($query->bool_col2);
224224
$this->assertSame(['a' => 'b', 'c' => null, 'd' => [1, 2, 3]], $query->json_col);
225225
}
226226

@@ -452,12 +452,9 @@ public function testSetProperties(): void
452452
'name' => 'samdark',
453453
'address' => 'rusia',
454454
'status' => 1,
455+
'bool_status' => true,
455456
];
456457

457-
if ($this->db()->getDriverName() === 'pgsql') {
458-
$properties['bool_status'] = true;
459-
}
460-
461458
$properties['profile_id'] = null;
462459

463460
$customer = new Customer();
@@ -564,25 +561,25 @@ public function testBooleanProperty(): void
564561

565562
$customer->setName('boolean customer');
566563
$customer->setEmail('[email protected]');
567-
$customer->setStatus(1);
564+
$customer->setBoolStatus(true);
568565

569566
$customer->save();
570567
$customer->refresh();
571-
$this->assertEquals(1, $customer->getStatus());
568+
$this->assertTrue($customer->getBoolStatus());
572569

573-
$customer->setStatus(0);
570+
$customer->setBoolStatus(false);
574571
$customer->save();
575572

576573
$customer->refresh();
577-
$this->assertEquals(0, $customer->getStatus());
574+
$this->assertFalse($customer->getBoolStatus());
578575

579576
$customerQuery = new ActiveQuery(Customer::class);
580-
$customers = $customerQuery->where(['status' => 1])->all();
577+
$customers = $customerQuery->where(['bool_status' => true])->all();
581578
$this->assertCount(2, $customers);
582579

583580
$customerQuery = new ActiveQuery(Customer::class);
584-
$customers = $customerQuery->where(['status' => 0])->all();
585-
$this->assertCount(1, $customers);
581+
$customers = $customerQuery->where(['bool_status' => false])->all();
582+
$this->assertCount(2, $customers);
586583
}
587584

588585
public function testPropertyAccess(): void
@@ -823,7 +820,7 @@ public function testGetDirtyValuesOnNewRecord(): void
823820
$customer->set('email', '[email protected]');
824821
$customer->set('address', null);
825822

826-
$this->assertEquals([], $customer->newValues([]));
823+
$this->assertSame([], $customer->newValues([]));
827824

828825
$this->assertEquals(
829826
[
@@ -836,7 +833,7 @@ public function testGetDirtyValuesOnNewRecord(): void
836833
],
837834
$customer->newValues()
838835
);
839-
$this->assertEquals(
836+
$this->assertSame(
840837
[
841838
'email' => '[email protected]',
842839
'address' => null,

tests/Driver/Oracle/ActiveQueryFindTest.php

-80
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
use Yiisoft\ActiveRecord\ActiveQuery;
88
use Yiisoft\ActiveRecord\Tests\Driver\Oracle\Stubs\Customer as CustomerWithRownumid;
9-
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Customer;
10-
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Order;
119
use Yiisoft\ActiveRecord\Tests\Support\OracleHelper;
1210
use Yiisoft\Db\Connection\ConnectionInterface;
1311

@@ -68,82 +66,4 @@ public function testFindLimit(): void
6866
$customer = $customerQuery->offset(3)->one();
6967
$this->assertNull($customer);
7068
}
71-
72-
public function testFindEager(): void
73-
{
74-
$this->checkFixture($this->db(), 'customer', true);
75-
76-
$customerQuery = new ActiveQuery(Customer::class);
77-
$customers = $customerQuery->with('orders')->indexBy('id')->all();
78-
79-
ksort($customers);
80-
$this->assertCount(3, $customers);
81-
$this->assertTrue($customers[1]->isRelationPopulated('orders'));
82-
$this->assertTrue($customers[2]->isRelationPopulated('orders'));
83-
$this->assertTrue($customers[3]->isRelationPopulated('orders'));
84-
$this->assertCount(1, $customers[1]->getOrders());
85-
$this->assertCount(2, $customers[2]->getOrders());
86-
$this->assertCount(0, $customers[3]->getOrders());
87-
88-
$customers[1]->resetRelation('orders');
89-
$this->assertFalse($customers[1]->isRelationPopulated('orders'));
90-
91-
$customer = $customerQuery->where(['id' => 1])->with('orders')->one();
92-
$this->assertTrue($customer->isRelationPopulated('orders'));
93-
$this->assertCount(1, $customer->getOrders());
94-
$this->assertCount(1, $customer->getRelatedRecords());
95-
96-
/** multiple with() calls */
97-
$orderQuery = new ActiveQuery(Order::class);
98-
$orders = $orderQuery->with('customer', 'items')->all();
99-
$this->assertCount(3, $orders);
100-
$this->assertTrue($orders[0]->isRelationPopulated('customer'));
101-
$this->assertTrue($orders[0]->isRelationPopulated('items'));
102-
103-
$orders = $orderQuery->with('customer')->with('items')->all();
104-
$this->assertCount(3, $orders);
105-
$this->assertTrue($orders[0]->isRelationPopulated('customer'));
106-
$this->assertTrue($orders[0]->isRelationPopulated('items'));
107-
}
108-
109-
public function testFindAsArray(): void
110-
{
111-
$this->checkFixture($this->db(), 'customer');
112-
113-
/** asArray */
114-
$customerQuery = new ActiveQuery(Customer::class);
115-
$customer = $customerQuery->where(['[[id]]' => 2])->asArray()->one();
116-
$this->assertEquals([
117-
'id' => 2,
118-
'email' => '[email protected]',
119-
'name' => 'user2',
120-
'address' => 'address2',
121-
'status' => 1,
122-
'profile_id' => null,
123-
'bool_status' => true,
124-
], $customer);
125-
126-
/** find all asArray */
127-
$customerQuery = new ActiveQuery(Customer::class);
128-
$customers = $customerQuery->asArray()->all();
129-
$this->assertCount(3, $customers);
130-
$this->assertArrayHasKey('id', $customers[0]);
131-
$this->assertArrayHasKey('name', $customers[0]);
132-
$this->assertArrayHasKey('email', $customers[0]);
133-
$this->assertArrayHasKey('address', $customers[0]);
134-
$this->assertArrayHasKey('status', $customers[0]);
135-
$this->assertArrayHasKey('bool_status', $customers[0]);
136-
$this->assertArrayHasKey('id', $customers[1]);
137-
$this->assertArrayHasKey('name', $customers[1]);
138-
$this->assertArrayHasKey('email', $customers[1]);
139-
$this->assertArrayHasKey('address', $customers[1]);
140-
$this->assertArrayHasKey('status', $customers[1]);
141-
$this->assertArrayHasKey('bool_status', $customers[1]);
142-
$this->assertArrayHasKey('id', $customers[2]);
143-
$this->assertArrayHasKey('name', $customers[2]);
144-
$this->assertArrayHasKey('email', $customers[2]);
145-
$this->assertArrayHasKey('address', $customers[2]);
146-
$this->assertArrayHasKey('status', $customers[2]);
147-
$this->assertArrayHasKey('bool_status', $customers[2]);
148-
}
14969
}

tests/Driver/Oracle/ActiveQueryTest.php

-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Throwable;
88
use Yiisoft\ActiveRecord\ActiveQuery;
99
use Yiisoft\ActiveRecord\Tests\Driver\Oracle\Stubs\Order;
10-
use Yiisoft\ActiveRecord\Tests\Driver\Oracle\Stubs\BitValues;
1110
use Yiisoft\ActiveRecord\Tests\Support\OracleHelper;
1211
use Yiisoft\Db\Connection\ConnectionInterface;
1312
use Yiisoft\Db\Exception\Exception;
@@ -388,17 +387,4 @@ public function testJoinWithSameTable(): void
388387
$this->assertEquals(2, $orders[0]->getId());
389388
$this->assertTrue($orders[0]->isRelationPopulated('itemsIndexed'));
390389
}
391-
392-
public function testBit(): void
393-
{
394-
$this->checkFixture($this->db(), 'bit_values');
395-
396-
$bitValueQuery = new ActiveQuery(BitValues::class);
397-
$falseBit = $bitValueQuery->findOne(1);
398-
$this->assertSame('0', $falseBit->val);
399-
400-
$bitValueQuery = new ActiveQuery(BitValues::class);
401-
$trueBit = $bitValueQuery->findOne(2);
402-
$this->assertSame('1', $trueBit->val);
403-
}
404390
}

tests/Driver/Oracle/ActiveRecordTest.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ public function testDefaultValues(): void
2929

3030
$arClass = new Type();
3131
$arClass->loadDefaultValues();
32-
$this->assertEquals(1, $arClass->int_col2);
33-
$this->assertEquals('something', $arClass->char_col2);
34-
$this->assertEquals(1.23, $arClass->float_col2);
35-
$this->assertEquals(33.22, $arClass->numeric_col);
36-
$this->assertEquals('1', $arClass->bool_col2);
32+
$this->assertSame(1, $arClass->int_col2);
33+
$this->assertSame('something', $arClass->char_col2);
34+
$this->assertSame(1.23, $arClass->float_col2);
35+
$this->assertSame(33.22, $arClass->numeric_col);
36+
$this->assertTrue($arClass->bool_col2);
3737

3838
// not testing $arClass->time, because oci\Schema can't read default value
3939

4040
$arClass = new Type();
4141
$arClass->char_col2 = 'not something';
4242

4343
$arClass->loadDefaultValues();
44-
$this->assertEquals('not something', $arClass->char_col2);
44+
$this->assertSame('not something', $arClass->char_col2);
4545

4646
$arClass = new Type();
4747
$arClass->char_col2 = 'not something';
4848

4949
$arClass->loadDefaultValues(false);
50-
$this->assertEquals('something', $arClass->char_col2);
50+
$this->assertSame('something', $arClass->char_col2);
5151
}
5252

5353
/**
@@ -63,24 +63,24 @@ public function testBooleanProperty(): void
6363

6464
$customer->setName('boolean customer');
6565
$customer->setEmail('[email protected]');
66-
$customer->setStatus(1);
66+
$customer->setBoolStatus(true);
6767

6868
$customer->save();
6969
$customer->refresh();
70-
$this->assertEquals(1, $customer->getStatus());
70+
$this->assertTrue($customer->getBoolStatus());
7171

72-
$customer->setStatus(0);
72+
$customer->setBoolStatus(false);
7373
$customer->save();
7474

7575
$customer->refresh();
76-
$this->assertEquals(0, $customer->getStatus());
76+
$this->assertFalse($customer->getBoolStatus());
7777

7878
$customerQuery = new ActiveQuery(Customer::class);
79-
$customers = $customerQuery->where(['status' => 1])->all();
79+
$customers = $customerQuery->where(['bool_status' => '1'])->all();
8080
$this->assertCount(2, $customers);
8181

8282
$customerQuery = new ActiveQuery(Customer::class);
83-
$customers = $customerQuery->where(['status' => '0'])->all();
84-
$this->assertCount(1, $customers);
83+
$customers = $customerQuery->where(['bool_status' => '0'])->all();
84+
$this->assertCount(2, $customers);
8585
}
8686
}

tests/Driver/Oracle/ArrayableTraitTest.php

-45
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
namespace Yiisoft\ActiveRecord\Tests\Driver\Oracle;
66

7-
use Yiisoft\ActiveRecord\ActiveQuery;
8-
use Yiisoft\ActiveRecord\Tests\Driver\Oracle\Stubs\Customer;
9-
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\CustomerClosureField;
107
use Yiisoft\ActiveRecord\Tests\Support\OracleHelper;
118
use Yiisoft\Db\Connection\ConnectionInterface;
129

@@ -16,46 +13,4 @@ protected function createConnection(): ConnectionInterface
1613
{
1714
return (new OracleHelper())->createConnection();
1815
}
19-
20-
public function testToArray(): void
21-
{
22-
$this->checkFixture($this->db(), 'customer', true);
23-
24-
$customerQuery = new ActiveQuery(Customer::class);
25-
$customer = $customerQuery->findOne(1);
26-
27-
$this->assertSame(
28-
[
29-
'id' => 1,
30-
'email' => '[email protected]',
31-
'name' => 'user1',
32-
'address' => 'address1',
33-
'status' => 1,
34-
'bool_status' => '1',
35-
'profile_id' => 1,
36-
],
37-
$customer->toArray(),
38-
);
39-
}
40-
41-
public function testToArrayWithClosure(): void
42-
{
43-
$this->checkFixture($this->db(), 'customer', true);
44-
45-
$customerQuery = new ActiveQuery(CustomerClosureField::class);
46-
$customer = $customerQuery->findOne(1);
47-
48-
$this->assertSame(
49-
[
50-
'id' => 1,
51-
'email' => '[email protected]',
52-
'name' => 'user1',
53-
'address' => 'address1',
54-
'status' => 'active',
55-
'bool_status' => '1',
56-
'profile_id' => 1,
57-
],
58-
$customer->toArray(),
59-
);
60-
}
6116
}

0 commit comments

Comments
 (0)