1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\ActiveRecord\Tests\Driver\Pgsql; |
6
|
|
|
|
7
|
|
|
use Yiisoft\ActiveRecord\ActiveQuery; |
8
|
|
|
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Customer; |
9
|
|
|
use Yiisoft\ActiveRecord\Tests\Support\PgsqlHelper; |
10
|
|
|
|
11
|
|
|
final class ActiveQueryFindTest extends \Yiisoft\ActiveRecord\Tests\ActiveQueryFindTest |
12
|
|
|
{ |
13
|
|
|
public function setUp(): void |
14
|
|
|
{ |
15
|
|
|
parent::setUp(); |
16
|
|
|
|
17
|
|
|
$pgsqlHelper = new PgsqlHelper(); |
18
|
|
|
$this->db = $pgsqlHelper->createConnection(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
protected function tearDown(): void |
22
|
|
|
{ |
23
|
|
|
parent::tearDown(); |
24
|
|
|
|
25
|
|
|
$this->db->close(); |
26
|
|
|
|
27
|
|
|
unset($this->db); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testFindAsArray(): void |
31
|
|
|
{ |
32
|
|
|
$this->checkFixture($this->db, 'customer', true); |
33
|
|
|
|
34
|
|
|
/** asArray */ |
35
|
|
|
$customerQuery = new ActiveQuery(Customer::class, $this->db); |
36
|
|
|
$customer = $customerQuery->where(['id' => 2])->asArray()->onePopulate(); |
37
|
|
|
$this->assertEquals([ |
38
|
|
|
'id' => 2, |
39
|
|
|
'email' => '[email protected]', |
40
|
|
|
'name' => 'user2', |
41
|
|
|
'address' => 'address2', |
42
|
|
|
'status' => 1, |
43
|
|
|
'bool_status' => true, |
44
|
|
|
'profile_id' => null, |
45
|
|
|
], $customer); |
46
|
|
|
|
47
|
|
|
/** find all asArray */ |
48
|
|
|
$customerQuery = new ActiveQuery(Customer::class, $this->db); |
49
|
|
|
$customers = $customerQuery->asArray()->all(); |
50
|
|
|
$this->assertCount(3, $customers); |
51
|
|
|
$this->assertArrayHasKey('id', $customers[0]); |
52
|
|
|
$this->assertArrayHasKey('name', $customers[0]); |
53
|
|
|
$this->assertArrayHasKey('email', $customers[0]); |
54
|
|
|
$this->assertArrayHasKey('address', $customers[0]); |
55
|
|
|
$this->assertArrayHasKey('status', $customers[0]); |
56
|
|
|
$this->assertArrayHasKey('bool_status', $customers[0]); |
57
|
|
|
$this->assertArrayHasKey('id', $customers[1]); |
58
|
|
|
$this->assertArrayHasKey('name', $customers[1]); |
59
|
|
|
$this->assertArrayHasKey('email', $customers[1]); |
60
|
|
|
$this->assertArrayHasKey('address', $customers[1]); |
61
|
|
|
$this->assertArrayHasKey('status', $customers[1]); |
62
|
|
|
$this->assertArrayHasKey('bool_status', $customers[1]); |
63
|
|
|
$this->assertArrayHasKey('id', $customers[2]); |
64
|
|
|
$this->assertArrayHasKey('name', $customers[2]); |
65
|
|
|
$this->assertArrayHasKey('email', $customers[2]); |
66
|
|
|
$this->assertArrayHasKey('address', $customers[2]); |
67
|
|
|
$this->assertArrayHasKey('status', $customers[2]); |
68
|
|
|
$this->assertArrayHasKey('bool_status', $customers[2]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|