Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Ensure unique IDs in randomHtml #1068

Merged
merged 2 commits into from
Oct 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Faker/Provider/HtmlLorem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Faker\Provider;

use Faker\Generator;
use Faker\UniqueGenerator;

class HtmlLorem extends Base
{
Expand Down Expand Up @@ -30,6 +31,8 @@ class HtmlLorem extends Base
const INPUT_TAG = "input";
const LABEL_TAG = "label";

private $idGenerator;

public function __construct(Generator $generator)
{
parent::__construct($generator);
Expand All @@ -43,6 +46,7 @@ public function __construct(Generator $generator)
public function randomHtml($maxDepth = 4, $maxWidth = 4)
{
$document = new \DOMDocument();
$this->idGenerator = new UniqueGenerator($this->generator);

$head = $document->createElement("head");
$this->addRandomTitle($head);
Expand Down Expand Up @@ -122,7 +126,7 @@ private function addRandomAttribute(\DOMElement $node)
$node->setAttribute("class", $this->generator->word);
break;
case 2:
$node->setAttribute("id", (string)$this->generator->randomNumber(5));
$node->setAttribute("id", (string)$this->idGenerator->randomNumber(5));
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/UniqueGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UniqueGenerator
* @param Generator $generator
* @param $maxRetries
*/
public function __construct(Generator $generator, $maxRetries)
public function __construct(Generator $generator, $maxRetries = 10000)
{
$this->generator = $generator;
$this->maxRetries = $maxRetries;
Expand Down