Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 2 additions & 60 deletions tests/ActiveQueryFindTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ abstract class ActiveQueryFindTest extends TestCase
{
public function testFindAll(): void
{
$this->checkFixture($this->db(), 'customer', true);

$customerQuery = new ActiveQuery(Customer::class);
$this->assertCount(1, $customerQuery->findAll(['id' => 1]));
$this->assertCount(3, $customerQuery->findAll(['id' => [1, 2, 3]]));
}

public function testFindScalar(): void
{
$this->checkFixture($this->db(), 'customer');

$customerQuery = new ActiveQuery(Customer::class);

/** query scalar */
Expand All @@ -41,8 +37,6 @@ public function testFindScalar(): void

public function testFindExists(): void
{
$this->checkFixture($this->db(), 'customer');

$customerQuery = new ActiveQuery(Customer::class);

$this->assertTrue($customerQuery->where(['[[id]]' => 2])->exists());
Expand All @@ -54,25 +48,21 @@ public function testFindExists(): void

public function testFindColumn(): void
{
$this->checkFixture($this->db(), 'customer');

$customerQuery = new ActiveQuery(Customer::class);

$this->assertEquals(
['user1', 'user2', 'user3'],
$customerQuery->select('[[name]]')->column()
);

$this->assertEquals(
$this->assertSame(
['user3', 'user2', 'user1'],
$customerQuery->orderBy(['[[name]]' => SORT_DESC])->select('[[name]]')->column()
);
}

public function testFindBySql(): void
{
$this->checkFixture($this->db(), 'customer');

$customerQuery = new ActiveQuery(Customer::class);

/** find one() */
Expand All @@ -94,8 +84,6 @@ public function testFindBySql(): void

public function testFindLazyViaTable(): void
{
$this->checkFixture($this->db(), 'order');

$orderQuery = new ActiveQuery(Order::class);

$orders = $orderQuery->findByPk(2);
Expand All @@ -108,8 +96,6 @@ public function testFindLazyViaTable(): void

public function testFindEagerViaTable(): void
{
$this->checkFixture($this->db(), 'order');

$orderQuery = new ActiveQuery(Order::class);
$orders = $orderQuery->with('books')->orderBy('id')->all();
$this->assertCount(3, $orders);
Expand Down Expand Up @@ -149,8 +135,6 @@ public function testFindEagerViaTable(): void
*/
public function testFindCompositeRelationWithJoin(): void
{
$this->checkFixture($this->db(), 'order_item');

$orderItemQuery = new ActiveQuery(OrderItem::class);

/** @var $orderItems OrderItem */
Expand All @@ -165,8 +149,6 @@ public function testFindCompositeRelationWithJoin(): void

public function testFindSimpleRelationWithJoin(): void
{
$this->checkFixture($this->db(), 'order');

$orderQuery = new ActiveQuery(Order::class);

$orders = $orderQuery->findByPk(1);
Expand All @@ -184,8 +166,6 @@ public function testFindSimpleRelationWithJoin(): void

public function testFindOneByColumnName(): void
{
$this->checkFixture($this->db(), 'customer');

$customer = new ActiveQuery(Customer::class);
$customerQuery = new CustomerQuery(Customer::class);

Expand All @@ -202,8 +182,6 @@ public function testFindOneByColumnName(): void

public function testFind(): void
{
$this->checkFixture($this->db(), 'customer');

$customerQuery = new ActiveQuery(Customer::class);
$this->assertInstanceOf(ActiveQueryInterface::class, $customerQuery);

Expand Down Expand Up @@ -264,8 +242,6 @@ public function testFind(): void

public function testFindAsArray(): void
{
$this->checkFixture($this->db(), 'customer');

/** asArray */
$customerQuery = new ActiveQuery(Customer::class);
$customer = $customerQuery->where(['id' => 2])->asArray()->one();
Expand Down Expand Up @@ -302,8 +278,6 @@ public function testFindAsArray(): void

public function testFindIndexBy(): void
{
$this->checkFixture($this->db(), 'customer');

$customerQuery = new ActiveQuery(Customer::class);

$customers = $customerQuery->indexBy('name')->orderBy('id')->all();
Expand All @@ -329,8 +303,6 @@ public function testFindIndexBy(): void

public function testFindIndexByAsArray(): void
{
$this->checkFixture($this->db(), 'customer');

$customerQuery = new ActiveQuery(Customer::class);
$customers = $customerQuery->asArray()->indexBy('name')->all();
$this->assertCount(3, $customers);
Expand Down Expand Up @@ -373,8 +345,6 @@ public function testFindIndexByAsArray(): void

public function testFindCount(): void
{
$this->checkFixture($this->db(), 'customer');

$customerQuery = new ActiveQuery(Customer::class);
$this->assertEquals(3, $customerQuery->count());
$this->assertEquals(1, $customerQuery->where(['id' => 1])->count());
Expand All @@ -391,8 +361,6 @@ public function testFindCount(): void

public function testFindLimit(): void
{
$this->checkFixture($this->db(), 'customer');

/** one */
$customerQuery = new ActiveQuery(Customer::class);
$customer = $customerQuery->orderBy('id')->one();
Expand Down Expand Up @@ -442,8 +410,6 @@ public function testFindLimit(): void

public function testFindComplexCondition(): void
{
$this->checkFixture($this->db(), 'customer');

$customerQuery = new ActiveQuery(Customer::class);

$this->assertEquals(
Expand Down Expand Up @@ -479,7 +445,7 @@ public function testFindComplexCondition(): void

public function testFindNullValues(): void
{
$this->checkFixture($this->db(), 'customer');
$this->reloadFixtureAfterTest();

$customerQuery = new ActiveQuery(Customer::class);

Expand All @@ -494,8 +460,6 @@ public function testFindNullValues(): void

public function testFindEager(): void
{
$this->checkFixture($this->db(), 'customer');

$customerQuery = new ActiveQuery(Customer::class);
$customers = $customerQuery->with('orders')->indexBy('id')->all();

Expand Down Expand Up @@ -531,8 +495,6 @@ public function testFindEager(): void

public function testFindEagerViaRelation(): void
{
$this->checkFixture($this->db(), 'order');

$orderQuery = new ActiveQuery(Order::class);
$orders = $orderQuery->with('items')->orderBy('id')->all();
$this->assertCount(3, $orders);
Expand All @@ -547,8 +509,6 @@ public function testFindEagerViaRelation(): void

public function testFindNestedRelation(): void
{
$this->checkFixture($this->db(), 'customer');

$customerQuery = new ActiveQuery(Customer::class);
$customers = $customerQuery->with('orders', 'orders.items')->indexBy('id')->all();

Expand Down Expand Up @@ -583,8 +543,6 @@ public function testFindNestedRelation(): void
*/
public function testFindEagerViaRelationPreserveOrder(): void
{
$this->checkFixture($this->db(), 'order');

$orderQuery = new ActiveQuery(Order::class);
$orders = $orderQuery->with('itemsInOrder1')->orderBy('created_at')->all();
$this->assertCount(3, $orders);
Expand Down Expand Up @@ -613,8 +571,6 @@ public function testFindEagerViaRelationPreserveOrder(): void

public function testFindEagerViaRelationPreserveOrderB(): void
{
$this->checkFixture($this->db(), 'order');

/** different order in via table. */
$orderQuery = new ActiveQuery(Order::class);
$orders = $orderQuery->with('itemsInOrder2')->orderBy('created_at')->all();
Expand Down Expand Up @@ -644,8 +600,6 @@ public function testFindEagerViaRelationPreserveOrderB(): void

public function testFindEmptyInCondition(): void
{
$this->checkFixture($this->db(), 'customer');

$customerQuery = new ActiveQuery(Customer::class);
$customers = $customerQuery->where(['id' => [1]])->all();
$this->assertCount(1, $customers);
Expand All @@ -662,8 +616,6 @@ public function testFindEmptyInCondition(): void

public function testFindEagerIndexBy(): void
{
$this->checkFixture($this->db(), 'order');

$orderQuery = new ActiveQuery(Order::class);
$order = $orderQuery->with('itemsIndexed')->where(['id' => 1])->one();
$this->assertTrue($order->isRelationPopulated('itemsIndexed'));
Expand All @@ -685,8 +637,6 @@ public function testFindEagerIndexBy(): void

public function testFindLazy(): void
{
$this->checkFixture($this->db(), 'customer');

$customerQuery = new ActiveQuery(Customer::class);
$customer = $customerQuery->findByPk(2);
$this->assertFalse($customer->isRelationPopulated('orders'));
Expand All @@ -711,8 +661,6 @@ public function testFindLazy(): void

public function testFindLazyVia(): void
{
$this->checkFixture($this->db(), 'order');

$orderQuery = new ActiveQuery(Order::class);
$order = $orderQuery->findByPk(1);

Expand All @@ -724,8 +672,6 @@ public function testFindLazyVia(): void

public function testFindByPkComposite(): void
{
$this->checkFixture($this->db(), 'order_item');

$query = new ActiveQuery(OrderItem::class);

$orderItem = $query->findByPk([1, 1]);
Expand All @@ -742,8 +688,6 @@ public function testFindByPkComposite(): void

public function testFindByPkWithoutPk(): void
{
$this->checkFixture($this->db(), 'type');

$query = new ActiveQuery(Type::class);

$this->expectException(InvalidConfigException::class);
Expand All @@ -754,8 +698,6 @@ public function testFindByPkWithoutPk(): void

public function testFindByPkWithJoin(): void
{
$this->checkFixture($this->db(), 'order');

$query = new ActiveQuery(Order::class);

$query->joinWith('items');
Expand Down
Loading