From e0a0351927d5a45fcdd147bf9af5ba2e935d61de Mon Sep 17 00:00:00 2001 From: Moritz Friedrich Date: Thu, 11 Feb 2021 14:15:58 +0100 Subject: [PATCH] Test improvements --- tests/BodyTest.php | 6 ---- tests/ModelTest.php | 78 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/tests/BodyTest.php b/tests/BodyTest.php index 76868b3..8d0dcef 100755 --- a/tests/BodyTest.php +++ b/tests/BodyTest.php @@ -47,12 +47,6 @@ protected function getExpected(array $body = []): array { $query = $this->getQueryArray(); - if ( ! isset($body['_source'])) { - $body['_source'] = [ - 'include' => [], - 'exclude' => [], - ]; - } $query['body'] = $body; diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 320ddac..14f8ea1 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -27,20 +27,90 @@ class ModelTest extends TestCase { public function testResolveRouteBinding(): void { - // TODO: Create mock connection + /** @var MockObject $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 = $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