Skip to content

Commit

Permalink
Test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Radiergummi committed Feb 11, 2021
1 parent 073a528 commit e0a0351
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 10 deletions.
6 changes: 0 additions & 6 deletions tests/BodyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ protected function getExpected(array $body = []): array
{
$query = $this->getQueryArray();

if ( ! isset($body['_source'])) {
$body['_source'] = [
'include' => [],
'exclude' => [],
];
}

$query['body'] = $body;

Expand Down
78 changes: 74 additions & 4 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,90 @@ class ModelTest extends TestCase
{
public function testResolveRouteBinding(): void
{
// TODO: Create mock connection
/** @var MockObject<Connection> $connection */
$connection = $this->app
->get(ConnectionResolverInterface::class)
->connection();

$connection
->expects(self::any())
->method('__call')
->with('search', [
[
'body' => [
'query' => [
'bool' => [
'filter' => [
[
'term' => [
'_id' => 42,
],
],
],
],
],
],
'from' => 0,
'size' => 1,
],
])
->willReturn([
'hits' => [
'hits' => [
[
'_id' => '42',
],
],
],
]);

$model = (new Model())->resolveRouteBinding(42);

self::assertSame($model->_id, 42);
self::assertSame($model->_id, '42');
}

public function testResolveRouteBindingFromField(): void
{
// TODO: Create mock connection
/** @var MockObject<Connection> $connection */
$connection = $this->app
->get(ConnectionResolverInterface::class)
->connection();

$connection
->expects(self::any())
->method('__call')
->with('search', [
[
'body' => [
'query' => [
'bool' => [
'filter' => [
[
'term' => [
'foo' => 42,
],
],
],
],
],
],
'from' => 0,
'size' => 1,
],
])
->willReturn([
'hits' => [
'hits' => [
[
'_id' => '42',
],
],
],
]);

$model = (new Model())->resolveRouteBinding(42, 'foo');

self::assertSame($model->_id, 42);
self::assertSame($model->_id, '42');
}

public function testMergeCasts(): void
Expand Down

0 comments on commit e0a0351

Please sign in to comment.