Skip to content

Commit

Permalink
test improvement for exception
Browse files Browse the repository at this point in the history
  • Loading branch information
hkulekci committed Oct 6, 2023
1 parent 2e303e0 commit 48b8e3d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/SearchEndpoint/KnnEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function add(BuilderInterface $builder, $key = null)
return parent::add($builder, $key);
}

throw new \LogicException('You need to add Knn builder!');
throw new \LogicException('Add Knn builder instead!');
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/SearchEndpoint/KnnEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace ONGR\ElasticsearchDSL\Tests\Unit\SearchEndpoint;

use ONGR\ElasticsearchDSL\Knn\Knn;
use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
use ONGR\ElasticsearchDSL\SearchEndpoint\KnnEndpoint;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -45,6 +46,18 @@ public function testEndpointGetter(): void
$this->assertSame($knn, $builders['knn']);
}

/**
* Tests if endpoint returns builders.
*/
public function testEndpointException(): void
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Add Knn builder instead!');
$knn = new MatchAllQuery();
$endpoint = new KnnEndpoint();
$endpoint->add($knn);
}

/**
* Tests if endpoint returns builders.
*/
Expand Down

0 comments on commit 48b8e3d

Please sign in to comment.