|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace LdapRecord\Tests\Integration; |
| 4 | + |
| 5 | +use Illuminate\Support\LazyCollection; |
| 6 | +use LdapRecord\Models\OpenLDAP\User; |
| 7 | +use LdapRecord\Query\Collection; |
| 8 | +use LdapRecord\Tests\Integration\Concerns\MakesUsers; |
| 9 | +use LdapRecord\Tests\Integration\Concerns\SetupTestConnection; |
| 10 | +use LdapRecord\Tests\Integration\Concerns\SetupTestOu; |
| 11 | + |
| 12 | +class QueryTest extends TestCase |
| 13 | +{ |
| 14 | + use MakesUsers; |
| 15 | + use SetupTestConnection; |
| 16 | + use SetupTestOu; |
| 17 | + |
| 18 | + protected function setUp(): void |
| 19 | + { |
| 20 | + parent::setUp(); |
| 21 | + |
| 22 | + $this->setupTestOu(); |
| 23 | + } |
| 24 | + |
| 25 | + public function test_it_can_paginate() |
| 26 | + { |
| 27 | + foreach (LazyCollection::range(1, 10) as $index) { |
| 28 | + $this->makeUser($this->ou)->save(); |
| 29 | + } |
| 30 | + |
| 31 | + $this->assertCount(10, User::paginate(5)); |
| 32 | + } |
| 33 | + |
| 34 | + public function test_it_can_chunk() |
| 35 | + { |
| 36 | + foreach (LazyCollection::range(1, 10) as $index) { |
| 37 | + $this->makeUser($this->ou)->save(); |
| 38 | + } |
| 39 | + |
| 40 | + $pages = 0; |
| 41 | + |
| 42 | + User::chunk(5, function (Collection $results) use (&$pages) { |
| 43 | + $pages++; |
| 44 | + |
| 45 | + $this->assertCount(5, $results); |
| 46 | + }); |
| 47 | + |
| 48 | + $this->assertEquals(2, $pages); |
| 49 | + } |
| 50 | + |
| 51 | + public function test_it_cannot_override_limit_when_chunking() |
| 52 | + { |
| 53 | + foreach (LazyCollection::range(1, 10) as $index) { |
| 54 | + $this->makeUser($this->ou)->save(); |
| 55 | + } |
| 56 | + |
| 57 | + $pages = 0; |
| 58 | + |
| 59 | + User::limit(1)->chunk(5, function (Collection $results) use (&$pages) { |
| 60 | + $pages++; |
| 61 | + |
| 62 | + $this->assertCount(5, $results); |
| 63 | + }); |
| 64 | + |
| 65 | + $this->assertEquals(2, $pages); |
| 66 | + } |
| 67 | +} |
0 commit comments