subject = new SearchQueryFactory(); } public function testCreateSearchQuery(): void { $request = $this->createMock(ServerRequestInterface::class); $request ->method('getQueryParams') ->willReturn( [ 'params' => [ 'query' => 'exampleQuery', 'rootNode' => 'exampleRootNode', 'parentNode' => 'exampleParentNode', 'structure' => 'exampleRootNode', ], 'rows' => 1, 'page' => 1, ] ); $resultSearchQuery = $this->subject->create($request); $this->assertEquals($resultSearchQuery->getPage(), 1); $this->assertEquals($resultSearchQuery->getParentClass(), 'exampleParentNode'); $this->assertEquals($resultSearchQuery->getRootClass(), 'exampleRootNode'); $this->assertEquals($resultSearchQuery->getRows(), 1); $this->assertEquals($resultSearchQuery->getTerm(), 'exampleQuery'); $this->assertEquals($resultSearchQuery->getStartRow(), 0); } public function testCreateSearchWithoutwithoutQuery(): void { $request = $this->createMock(ServerRequestInterface::class); $request ->method('getQueryParams') ->willReturn( [ 'params' => [ 'rootNode' => 'exampleRootNode', 'parentNode' => 'exampleParentNode', ], 'rows' => 1, 'page' => 1, ] ); $this->expectException(CreateSearchQueryException::class); $this->expectExceptionMessage('User input is missing'); $this->subject->create($request); } public function testCreateSearchQueryWithPoorRequest(): void { $request = $this->createMock(ServerRequestInterface::class); $request ->method('getQueryParams') ->willReturn( [ 'params' => [ 'query' => 'exampleQuery', 'parentNode' => 'exampleParentNode', ], 'rows' => 1, 'page' => 1, ] ); $this->expectException(CreateSearchQueryException::class); $this->expectExceptionMessage('Root node is missing from request'); $this->subject->create($request); } public function testCreateSearchQueryRequestWithoutPagination(): void { $request = $this->createMock(ServerRequestInterface::class); $request ->method('getQueryParams') ->willReturn( [ 'params' => [ 'query' => 'exampleQuery', 'parentNode' => 'exampleParentNode', 'rootNode' => 'exampleRootNode', 'structure' => 'exampleRootNode', ], ] ); $resultSearchQuery = $this->subject->create($request); $this->assertNull($resultSearchQuery->getRows()); $this->assertNull($resultSearchQuery->getPage()); } }