Commit c1febb74 by Carsten Brandt

reduce randomness in test results

parent 613758dd
...@@ -148,6 +148,51 @@ class ActiveRecordTest extends RedisTestCase ...@@ -148,6 +148,51 @@ class ActiveRecordTest extends RedisTestCase
$this->assertTrue($customers['3-user3'] instanceof $customerClass); $this->assertTrue($customers['3-user3'] instanceof $customerClass);
} }
public function testFindLimit()
{
// TODO this test is duplicated because of missing orderBy support in redis
/** @var TestCase|ActiveRecordTestTrait $this */
// all()
$customers = $this->callCustomerFind()->all();
$this->assertEquals(3, count($customers));
$customers = $this->callCustomerFind()/*->orderBy('id')*/->limit(1)->all();
$this->assertEquals(1, count($customers));
$this->assertEquals('user1', $customers[0]->name);
$customers = $this->callCustomerFind()/*->orderBy('id')*/->limit(1)->offset(1)->all();
$this->assertEquals(1, count($customers));
$this->assertEquals('user2', $customers[0]->name);
$customers = $this->callCustomerFind()/*->orderBy('id')*/->limit(1)->offset(2)->all();
$this->assertEquals(1, count($customers));
$this->assertEquals('user3', $customers[0]->name);
$customers = $this->callCustomerFind()/*->orderBy('id')*/->limit(2)->offset(1)->all();
$this->assertEquals(2, count($customers));
$this->assertEquals('user2', $customers[0]->name);
$this->assertEquals('user3', $customers[1]->name);
$customers = $this->callCustomerFind()->limit(2)->offset(3)->all();
$this->assertEquals(0, count($customers));
// one()
$customer = $this->callCustomerFind()/*->orderBy('id')*/->one();
$this->assertEquals('user1', $customer->name);
$customer = $this->callCustomerFind()/*->orderBy('id')*/->offset(0)->one();
$this->assertEquals('user1', $customer->name);
$customer = $this->callCustomerFind()/*->orderBy('id')*/->offset(1)->one();
$this->assertEquals('user2', $customer->name);
$customer = $this->callCustomerFind()/*->orderBy('id')*/->offset(2)->one();
$this->assertEquals('user3', $customer->name);
$customer = $this->callCustomerFind()->offset(3)->one();
$this->assertNull($customer);
}
public function testFindEagerViaRelation() public function testFindEagerViaRelation()
{ {
/** @var TestCase|ActiveRecordTestTrait $this */ /** @var TestCase|ActiveRecordTestTrait $this */
......
...@@ -174,7 +174,7 @@ trait ActiveRecordTestTrait ...@@ -174,7 +174,7 @@ trait ActiveRecordTestTrait
public function testFindColumn() public function testFindColumn()
{ {
/** @var TestCase|ActiveRecordTestTrait $this */ /** @var TestCase|ActiveRecordTestTrait $this */
$this->assertEquals(['user1', 'user2', 'user3'], $this->callCustomerFind()->column('name')); $this->assertEquals(['user1', 'user2', 'user3'], $this->callCustomerFind()->orderBy(['name' => SORT_ASC])->column('name'));
$this->assertEquals(['user3', 'user2', 'user1'], $this->callCustomerFind()->orderBy(['name' => SORT_DESC])->column('name')); $this->assertEquals(['user3', 'user2', 'user1'], $this->callCustomerFind()->orderBy(['name' => SORT_DESC])->column('name'));
} }
...@@ -255,19 +255,19 @@ trait ActiveRecordTestTrait ...@@ -255,19 +255,19 @@ trait ActiveRecordTestTrait
$customers = $this->callCustomerFind()->all(); $customers = $this->callCustomerFind()->all();
$this->assertEquals(3, count($customers)); $this->assertEquals(3, count($customers));
$customers = $this->callCustomerFind()->limit(1)->all(); $customers = $this->callCustomerFind()->orderBy('id')->limit(1)->all();
$this->assertEquals(1, count($customers)); $this->assertEquals(1, count($customers));
$this->assertEquals('user1', $customers[0]->name); $this->assertEquals('user1', $customers[0]->name);
$customers = $this->callCustomerFind()->limit(1)->offset(1)->all(); $customers = $this->callCustomerFind()->orderBy('id')->limit(1)->offset(1)->all();
$this->assertEquals(1, count($customers)); $this->assertEquals(1, count($customers));
$this->assertEquals('user2', $customers[0]->name); $this->assertEquals('user2', $customers[0]->name);
$customers = $this->callCustomerFind()->limit(1)->offset(2)->all(); $customers = $this->callCustomerFind()->orderBy('id')->limit(1)->offset(2)->all();
$this->assertEquals(1, count($customers)); $this->assertEquals(1, count($customers));
$this->assertEquals('user3', $customers[0]->name); $this->assertEquals('user3', $customers[0]->name);
$customers = $this->callCustomerFind()->limit(2)->offset(1)->all(); $customers = $this->callCustomerFind()->orderBy('id')->limit(2)->offset(1)->all();
$this->assertEquals(2, count($customers)); $this->assertEquals(2, count($customers));
$this->assertEquals('user2', $customers[0]->name); $this->assertEquals('user2', $customers[0]->name);
$this->assertEquals('user3', $customers[1]->name); $this->assertEquals('user3', $customers[1]->name);
...@@ -276,16 +276,16 @@ trait ActiveRecordTestTrait ...@@ -276,16 +276,16 @@ trait ActiveRecordTestTrait
$this->assertEquals(0, count($customers)); $this->assertEquals(0, count($customers));
// one() // one()
$customer = $this->callCustomerFind()->one(); $customer = $this->callCustomerFind()->orderBy('id')->one();
$this->assertEquals('user1', $customer->name); $this->assertEquals('user1', $customer->name);
$customer = $this->callCustomerFind()->offset(0)->one(); $customer = $this->callCustomerFind()->orderBy('id')->offset(0)->one();
$this->assertEquals('user1', $customer->name); $this->assertEquals('user1', $customer->name);
$customer = $this->callCustomerFind()->offset(1)->one(); $customer = $this->callCustomerFind()->orderBy('id')->offset(1)->one();
$this->assertEquals('user2', $customer->name); $this->assertEquals('user2', $customer->name);
$customer = $this->callCustomerFind()->offset(2)->one(); $customer = $this->callCustomerFind()->orderBy('id')->offset(2)->one();
$this->assertEquals('user3', $customer->name); $this->assertEquals('user3', $customer->name);
$customer = $this->callCustomerFind()->offset(3)->one(); $customer = $this->callCustomerFind()->offset(3)->one();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment