|
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\ActiveQueryFindTest as AbstractActiveQueryFindTest; |
|
9
|
|
|
use Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Customer; |
|
10
|
|
|
use Yiisoft\Db\Connection\ConnectionInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @group pgsql |
|
14
|
|
|
*/ |
|
15
|
|
|
final class ActiveQueryFindTest extends AbstractActiveQueryFindTest |
|
16
|
|
|
{ |
|
17
|
|
|
protected string $driverName = 'pgsql'; |
|
18
|
|
|
protected ConnectionInterface $db; |
|
19
|
|
|
|
|
20
|
|
|
public function setUp(): void |
|
21
|
|
|
{ |
|
22
|
|
|
parent::setUp(); |
|
23
|
|
|
|
|
24
|
|
|
$this->db = $this->pgsqlConnection; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
protected function tearDown(): void |
|
28
|
|
|
{ |
|
29
|
|
|
parent::tearDown(); |
|
30
|
|
|
|
|
31
|
|
|
$this->pgsqlConnection->close(); |
|
32
|
|
|
|
|
33
|
|
|
unset($this->pgsqlConnection); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testFindAsArray(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->checkFixture($this->db, 'customer'); |
|
39
|
|
|
|
|
40
|
|
|
/** asArray */ |
|
41
|
|
|
$customerQuery = new ActiveQuery(Customer::class, $this->db); |
|
42
|
|
|
$customer = $customerQuery->where(['id' => 2])->asArray()->one(); |
|
43
|
|
|
$this->assertEquals([ |
|
44
|
|
|
'id' => 2, |
|
45
|
|
|
'email' => '[email protected]', |
|
46
|
|
|
'name' => 'user2', |
|
47
|
|
|
'address' => 'address2', |
|
48
|
|
|
'status' => 1, |
|
49
|
|
|
'bool_status' => true, |
|
50
|
|
|
'profile_id' => null, |
|
51
|
|
|
], $customer); |
|
52
|
|
|
|
|
53
|
|
|
/** find all asArray */ |
|
54
|
|
|
$customerQuery = new ActiveQuery(Customer::class, $this->db); |
|
55
|
|
|
$customers = $customerQuery->asArray()->all(); |
|
56
|
|
|
$this->assertCount(3, $customers); |
|
57
|
|
|
$this->assertArrayHasKey('id', $customers[0]); |
|
58
|
|
|
$this->assertArrayHasKey('name', $customers[0]); |
|
59
|
|
|
$this->assertArrayHasKey('email', $customers[0]); |
|
60
|
|
|
$this->assertArrayHasKey('address', $customers[0]); |
|
61
|
|
|
$this->assertArrayHasKey('status', $customers[0]); |
|
62
|
|
|
$this->assertArrayHasKey('bool_status', $customers[0]); |
|
63
|
|
|
$this->assertArrayHasKey('id', $customers[1]); |
|
64
|
|
|
$this->assertArrayHasKey('name', $customers[1]); |
|
65
|
|
|
$this->assertArrayHasKey('email', $customers[1]); |
|
66
|
|
|
$this->assertArrayHasKey('address', $customers[1]); |
|
67
|
|
|
$this->assertArrayHasKey('status', $customers[1]); |
|
68
|
|
|
$this->assertArrayHasKey('bool_status', $customers[1]); |
|
69
|
|
|
$this->assertArrayHasKey('id', $customers[2]); |
|
70
|
|
|
$this->assertArrayHasKey('name', $customers[2]); |
|
71
|
|
|
$this->assertArrayHasKey('email', $customers[2]); |
|
72
|
|
|
$this->assertArrayHasKey('address', $customers[2]); |
|
73
|
|
|
$this->assertArrayHasKey('status', $customers[2]); |
|
74
|
|
|
$this->assertArrayHasKey('bool_status', $customers[2]); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|