Skip to content

Commit

Permalink
BUGFIX: resource formatter for non-persistent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simstern committed Mar 8, 2021
1 parent 42bd1d7 commit fc883b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions Classes/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function __construct(ObjectManagerInterface $objectManager, bool $persist

foreach ($this->settings['fakerProviders'] as $fakerProviderSetting) {
$options = $fakerProviderSetting['options'] ?? [];
$options['persistenceEnabled'] = $persistenceEnabled;
$provider = $fakerProviderFactory->create($fakerProviderSetting['provider'], $options);
$this->faker->addProvider($provider);
}
Expand Down
40 changes: 25 additions & 15 deletions Classes/Provider/ResourceFakerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,50 @@ public function setOptions(array $options): void
* A persistent resource
*
* @param string $fileName
* @return PersistentResource
* @return PersistentResource|null
*/
public function persistentResource(string $fileName): PersistentResource
public function persistentResource(string $fileName): ?PersistentResource
{
return $this->resourceManager->importResource($this->options['fixturePath'] . $fileName);
if ($this->options['persistenceEnabled'] === true) {
return $this->resourceManager->importResource($this->options['fixturePath'] . $fileName);
} else {
return null;
}
}

/**
* Document asset with reference to a persistent resource.
*
* @param string $fileName
* @return Document
* @return Document|null
*/
public function persistentResourceDocument(string $fileName): Document
public function persistentResourceDocument(string $fileName): ?Document
{
$resource = $this->persistentResource($fileName);
$image = new Document($resource);
$image->setTitle($fileName);
if ($resource = $this->persistentResource($fileName)) {
$image = new Document($resource);
$image->setTitle($fileName);

return $image;
return $image;
}

return null;
}

/**
* Image asset with reference to a persistent resource.
*
* @param string $fileName
* @return Image
* @return Image|null
*/
public function persistentResourceImage(string $fileName): Image
public function persistentResourceImage(string $fileName): ?Image
{
$resource = $this->persistentResource($fileName);
$image = new Image($resource);
$image->setTitle($fileName);
if ($resource = $this->persistentResource($fileName)) {
$image = new Image($resource);
$image->setTitle($fileName);

return $image;
}

return $image;
return null;
}
}

0 comments on commit fc883b7

Please sign in to comment.