|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * The MIT License |
| 4 | + * |
| 5 | + * Copyright 2017 Robert Pustułka <[email protected]>. |
| 6 | + * |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in |
| 15 | + * all copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | + * THE SOFTWARE. |
| 24 | + */ |
| 25 | + |
| 26 | +namespace Robotusers\Chunk\Test\TestCase\ORM; |
| 27 | + |
| 28 | +use Cake\ORM\ResultSet as CoreResultSet; |
| 29 | +use Cake\ORM\TableRegistry; |
| 30 | +use Cake\TestSuite\TestCase; |
| 31 | +use Robotusers\Chunk\ORM\Query; |
| 32 | +use Robotusers\Chunk\ORM\ResultSet; |
| 33 | + |
| 34 | +/** |
| 35 | + * Description of QueryTest |
| 36 | + * |
| 37 | + * @author Robert Pustułka <[email protected]> |
| 38 | + */ |
| 39 | +class QueryTest extends TestCase |
| 40 | +{ |
| 41 | + public $fixtures = [ |
| 42 | + 'core.authors' |
| 43 | + ]; |
| 44 | + |
| 45 | + public function testLoad() |
| 46 | + { |
| 47 | + $table = TableRegistry::get('Authors'); |
| 48 | + $query = $table->find(); |
| 49 | + |
| 50 | + $chunkedQuery = new Query($query); |
| 51 | + |
| 52 | + $this->assertSame($query->repository(), $chunkedQuery->repository()); |
| 53 | + $this->assertSame($query->getConnection(), $chunkedQuery->getConnection()); |
| 54 | + $this->assertSame($query->getOptions(), $chunkedQuery->getOptions()); |
| 55 | + } |
| 56 | + |
| 57 | + public function testApplyOptions() |
| 58 | + { |
| 59 | + $table = TableRegistry::get('Authors'); |
| 60 | + $query = $table->find(); |
| 61 | + |
| 62 | + $chunkedQuery = new Query($query); |
| 63 | + $chunkedQuery->applyOptions(['chunkSize' => 100]); |
| 64 | + $this->assertEquals(100, $chunkedQuery->getOptions()['chunkSize']); |
| 65 | + } |
| 66 | + |
| 67 | + public function testAll() |
| 68 | + { |
| 69 | + $table = TableRegistry::get('Authors'); |
| 70 | + $query = $table->find(); |
| 71 | + |
| 72 | + $chunkedQuery = new Query($query); |
| 73 | + $chunkedQuery->applyOptions(['chunkSize' => 100]); |
| 74 | + $results = $chunkedQuery->all(); |
| 75 | + $this->assertInstanceOf(ResultSet::class, $results); |
| 76 | + $this->assertEquals(100, $results->getConfig('size')); |
| 77 | + } |
| 78 | + |
| 79 | + public function testDefaultAll() |
| 80 | + { |
| 81 | + $table = TableRegistry::get('Authors'); |
| 82 | + $query = $table->find(); |
| 83 | + |
| 84 | + $chunkedQuery = new Query($query); |
| 85 | + $results = $chunkedQuery->defaultAll(); |
| 86 | + $this->assertInstanceOf(CoreResultSet::class, $results); |
| 87 | + } |
| 88 | +} |
0 commit comments