Пример #1
0
 /**
  * @param DOMDocument|null $document
  */
 public function __construct(DOMDocument $document = null)
 {
     if (null === $document) {
         $document = new DOMDocument('1.0', 'UTF-8');
     }
     parent::__construct(new Loader(), $document);
 }
Пример #2
0
    /**
     * @covers ::sendRequest
     * @covers ::getFullHtml
     * @covers ::setDocumentContent
     */
    public function testSendRequest()
    {
        $emptyDocument = new DOMDocument();
        $crawler = new Crawler($this->loader, $emptyDocument);
        $responseBody = <<<HTML
<!DOCTYPE html>
<html><body>Success!</body></html>

HTML;
        $request = new ServerRequest('GET', 'http://example.com');
        $response = new Response(200, [], $responseBody);
        $this->loader->expects($this->once())->method('send')->with($request)->willReturn($response);
        $crawler->sendRequest($request);
        $this->assertEquals($responseBody, $crawler->getFullHtml());
        $result = $crawler->getXPath()->query('//body');
        $this->assertEquals(1, $result->length, 'Should be able to use the new html');
    }