/** * @test */ public function testWordSelectorWithError() { $this->request->shouldReceive('get')->andReturn(null); $this->wordSelector->shouldReceive('getRandomWord')->andThrow(new \InvalidArgumentException('ex-text')); $controller = new WordController($this->wordSelector); $response = $controller->random($this->request); $this->assertInstanceOf(Response::class, $response); $this->assertEquals(json_encode(['error' => 'ex-text']), $response->getContent()); $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode()); $this->assertEquals('application/json', $response->headers->get('Content-Type')); }