Skip to content

Commit

Permalink
fix(resultSet): Fix buildModel argument order when called via buildMo…
Browse files Browse the repository at this point in the history
…delFromIndexAndData (#159)
  • Loading branch information
benji07 committed Mar 30, 2023
1 parent 08b1ab0 commit 07a6b8f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ResultSetBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function buildResultSet(Response $response, Query $query): ResultSet

public function buildModelFromIndexAndData(string $indexName, $source)
{
return $this->buildModel($indexName, $source, []);
return $this->buildModel($source, $indexName, []);
}

public function buildModelFromDocument(ElasticaDocument $document)
Expand Down
70 changes: 70 additions & 0 deletions tests/ResultSetBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/*
* This file is part of the jolicode/elastically library.
*
* (c) JoliCode <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace JoliCode\Elastically\Tests;

use JoliCode\Elastically\IndexNameMapper;
use JoliCode\Elastically\ResultSetBuilder;
use JoliCode\Elastically\Serializer\ContextBuilderInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

class ResultSetBuilderTest extends TestCase
{
public function testBuildModelFromIndexAndData(): void
{
$indexNameMapper = $this->getMockBuilder(IndexNameMapper::class)
->disableOriginalConstructor()
->getMock()
;

$indexNameMapper
->expects($this->once())
->method('getPureIndexName')
->with($this->equalTo('indexName'))
->willReturn('indexName')
;

$indexNameMapper
->expects($this->once())
->method('getClassFromIndexName')
->with($this->equalTo('indexName'))
->willReturn(TestDTO::class)
;

$contextBuilder = $this->getMockBuilder(ContextBuilderInterface::class)
->disableOriginalConstructor()
->getMock()
;

$contextBuilder
->expects($this->once())
->method('buildContext')
->with($this->equalTo(TestDTO::class))
->willReturn([])
;

$denormalizer = $this->getMockBuilder(DenormalizerInterface::class)
->disableOriginalConstructor()
->getMock()
;

$denormalizer
->expects($this->once())
->method('denormalize')
->with(['id' => 1234], TestDTO::class, null, [])
->willReturn([])
;

$resultSetBuilder = new ResultSetBuilder($indexNameMapper, $contextBuilder, $denormalizer);
$resultSetBuilder->buildModelFromIndexAndData('indexName', ['id' => 1234]);
}
}

0 comments on commit 07a6b8f

Please sign in to comment.