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
|
|
|
use Yiisoft\Db\Connection\ConnectionInterface; |
11
|
|
|
|
12
|
|
|
final class ActiveQueryFindTest extends \Yiisoft\ActiveRecord\Tests\ActiveQueryFindTest |
13
|
|
|
{ |
14
|
|
|
protected function createConnection(): ConnectionInterface |
15
|
|
|
{ |
16
|
|
|
return (new PgsqlHelper())->createConnection(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testFindAsArray(): void |
20
|
|
|
{ |
21
|
|
|
$this->checkFixture($this->db(), 'customer', true); |
22
|
|
|
|
23
|
|
|
/** asArray */ |
24
|
|
|
$customerQuery = new ActiveQuery(Customer::class); |
25
|
|
|
$customer = $customerQuery->where(['id' => 2])->asArray()->onePopulate(); |
26
|
|
|
$this->assertEquals([ |
27
|
|
|
'id' => 2, |
28
|
|
|
'email' => '[email protected]', |
29
|
|
|
'name' => 'user2', |
30
|
|
|
'address' => 'address2', |
31
|
|
|
'status' => 1, |
32
|
|
|
'bool_status' => true, |
33
|
|
|
'profile_id' => null, |
34
|
|
|
], $customer); |
35
|
|
|
|
36
|
|
|
/** find all asArray */ |
37
|
|
|
$customerQuery = new ActiveQuery(Customer::class); |
38
|
|
|
$customers = $customerQuery->asArray()->all(); |
39
|
|
|
$this->assertCount(3, $customers); |
40
|
|
|
$this->assertArrayHasKey('id', $customers[0]); |
41
|
|
|
$this->assertArrayHasKey('name', $customers[0]); |
42
|
|
|
$this->assertArrayHasKey('email', $customers[0]); |
43
|
|
|
$this->assertArrayHasKey('address', $customers[0]); |
44
|
|
|
$this->assertArrayHasKey('status', $customers[0]); |
45
|
|
|
$this->assertArrayHasKey('bool_status', $customers[0]); |
46
|
|
|
$this->assertArrayHasKey('id', $customers[1]); |
47
|
|
|
$this->assertArrayHasKey('name', $customers[1]); |
48
|
|
|
$this->assertArrayHasKey('email', $customers[1]); |
49
|
|
|
$this->assertArrayHasKey('address', $customers[1]); |
50
|
|
|
$this->assertArrayHasKey('status', $customers[1]); |
51
|
|
|
$this->assertArrayHasKey('bool_status', $customers[1]); |
52
|
|
|
$this->assertArrayHasKey('id', $customers[2]); |
53
|
|
|
$this->assertArrayHasKey('name', $customers[2]); |
54
|
|
|
$this->assertArrayHasKey('email', $customers[2]); |
55
|
|
|
$this->assertArrayHasKey('address', $customers[2]); |
56
|
|
|
$this->assertArrayHasKey('status', $customers[2]); |
57
|
|
|
$this->assertArrayHasKey('bool_status', $customers[2]); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|