/** * Make a call to the product page to crawl the information * * @param $url * @param array $information * @return array */ protected function getProductInformation($url, $information = []) { $request = $this->httpClient->setUrl($url)->request(); $crawler = new Crawler($request['body']); $information['description'] = trim($crawler->filter('div.productText')->first()->text()); $information['size'] = $request['size']; return $information; }
/** * Test the request call and mock the response */ public function testRequest() { $responseArray = ['headers' => ['Content-Type' => 'text/html'], 'status_code' => 200, 'body' => '<html><body><h1>Ripe & ready</h1></body></html>']; $response = new Response($responseArray['status_code'], $responseArray['headers'], $responseArray['body']); $this->clientMock->shouldReceive('get')->once()->andReturn($response); $httpClient = $this->httpClient->setClient($this->clientMock); $request = $httpClient->request(); $this->assertTrue(is_array($request)); $this->assertArrayHasKey('headers', $request); $this->assertArrayHasKey('body', $request); $this->assertArrayHasKey('status_code', $request); $this->assertArrayHasKey('size', $request); $this->assertEquals($responseArray['headers']['Content-Type'], $request['headers']['Content-Type'][0]); $this->assertEquals($responseArray['body'], $request['body']); $this->assertEquals($responseArray['status_code'], $request['status_code']); }