Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
BackgroundFileFaker
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 createOriginalFilename
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createMimeType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isSupported
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createResource
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Faker\FileFakers;
3
4use Apie\Core\FileStorage\StoredFile;
5use Apie\Faker\Interfaces\ApieImageFileFaker;
6use Faker\Generator;
7use Symfony\Component\Finder\Finder;
8
9final class BackgroundFileFaker implements ApieImageFileFaker
10{
11    public function createOriginalFilename(Generator $faker): string
12    {
13        return $faker->word() . '.jpg';
14    }
15    public function createMimeType(): string
16    {
17        return 'image/jpeg';
18    }
19    public static function isSupported(): bool
20    {
21        return true;
22    }
23
24    /** @return resource */
25    public function createResource(Generator $faker, string $originalFilename, string $mimeType): mixed
26    {
27        $serverPath = __DIR__ .  '/../../fixtures/images/backgrounds';
28        $files = iterator_to_array(Finder::create()->in($serverPath)->files());
29
30        $file = StoredFile::createFromLocalFile($faker->randomElement($files), $this->createMimeType());
31        return $file->getStream()->detach();
32    }
33}