|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Apisearch PHP Client. |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + * |
| 9 | + * Feel free to edit as you please, and have fun. |
| 10 | + * |
| 11 | + * @author Marc Morera <yuhu@mmoreram.com> |
| 12 | + */ |
| 13 | + |
| 14 | +declare(strict_types=1); |
| 15 | + |
| 16 | +namespace Apisearch\Tests\Repository; |
| 17 | + |
| 18 | +use Apisearch\Model\Item; |
| 19 | +use Apisearch\Query\Query; |
| 20 | +use Apisearch\Repository\Repository; |
| 21 | +use Apisearch\Repository\TransformableRepository; |
| 22 | +use Apisearch\Result\Result; |
| 23 | +use Apisearch\Transformer\Transformer; |
| 24 | +use PHPUnit\Framework\TestCase; |
| 25 | + |
| 26 | +/** |
| 27 | + * Class TransformableRepositoryTest. |
| 28 | + */ |
| 29 | +class TransformableRepositoryTest extends TestCase |
| 30 | +{ |
| 31 | + public function testResultTransformer() |
| 32 | + { |
| 33 | + $repository = $this->createMock(Repository::class); |
| 34 | + $result = new Result( |
| 35 | + Query::createMatchAll()->identifyWith('123'), |
| 36 | + 1, 1 |
| 37 | + ); |
| 38 | + $result->addItem(Item::createFromArray(['uuid' => ['id' => '1', 'type' => 'a']])); |
| 39 | + $repository->method('query')->willReturn($result); |
| 40 | + |
| 41 | + $transformer = $this->createMock(Transformer::class); |
| 42 | + $transformer->method('fromItem')->willReturn(['a']); |
| 43 | + $transformer->method('fromItems')->willReturn([['a']]); |
| 44 | + |
| 45 | + $transformableRepository = new TransformableRepository($repository, $transformer); |
| 46 | + $result = $transformableRepository->query(Query::createMatchAll()); |
| 47 | + |
| 48 | + $this->assertEquals( |
| 49 | + [['a']], $result->getItems() |
| 50 | + ); |
| 51 | + } |
| 52 | +} |
0 commit comments