Skip to content

Commit

Permalink
updated text test
Browse files Browse the repository at this point in the history
  • Loading branch information
johnykvsky committed Dec 23, 2024
1 parent 7ce8242 commit cd2b039
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ No problem, just try this:

Text extension is a bit different for one reason - it uses external `txt` file as source to large test. By default it's in `resources/en_US.txt` but you can either:

* pass file location to `Text` constructor
* pass text to `Text` constructor (i.e. `$text = new Text(file_get_contents('my_file.txt'));`)
* extend `Text` class and use different location in `$defaultText` property
7 changes: 3 additions & 4 deletions src/Core/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ class Text implements

public function __construct(string $baseText = null)
{
if (null !== $baseText && $file = file_get_contents($baseText)) {
if (null !== $baseText) {
$this->baseText = $baseText;
} elseif ($file = file_get_contents($this->defaultText)) {
$this->baseText = $file;
} else {
$file = file_get_contents($this->defaultText);
$this->baseText = $file !== false ? $file : '';
}
}

Expand Down
29 changes: 28 additions & 1 deletion test/Extension/TextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use DummyGenerator\Definitions\Replacer\ReplacerInterface;
use DummyGenerator\Definitions\Transliterator\TransliteratorInterface;
use DummyGenerator\DummyGenerator;
use DummyGenerator\Test\Fixtures\TextProvider;
use PHPUnit\Framework\TestCase;

class TextTest extends TestCase
Expand All @@ -41,4 +40,32 @@ public function testRealText(): void

self::assertTrue($length >= 5 && $length <= 50);
}

public function testRealTextConstructor(): void
{
$text = <<<'EOT'
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
EOT;

$container = new DefinitionContainer([]);
$container->add(RandomizerInterface::class, Randomizer::class);
$container->add(TransliteratorInterface::class, Transliterator::class);
$container->add(ReplacerInterface::class, Replacer::class);
$container->add(TextExtensionInterface::class, new Text($text));
$this->generator = new DummyGenerator($container);

$realText = $this->generator->realText(min: 5, max: 50, indexSize: 3);

// @phpstan-ignore-next-line
$length = $this->generator->ext(ReplacerInterface::class)->strlen($realText);

self::assertTrue($length >= 5 && $length <= 50);
self::assertTrue(str_contains($text, rtrim($realText, '.')));
}
}

0 comments on commit cd2b039

Please sign in to comment.