Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
MockFileWriter
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 writeFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 clearPath
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 fileExists
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 readContents
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Core\Other;
3
4final class MockFileWriter implements FileWriterInterface, FileReaderInterface
5{
6    /**
7     * @var array<string, string>
8     */
9    public array $writtenFiles = [];
10
11    public function writeFile(string $filename, string $fileContents): void
12    {
13        $this->writtenFiles[$filename] = $fileContents;
14    }
15
16    public function clearPath(string $path): void
17    {
18        $this->writtenFiles = array_filter(
19            $this->writtenFiles,
20            function (string $fileContents, string $fileName) use ($path) {
21                return !str_starts_with($fileName, $path . '/') && $fileName !== $path;
22            },
23            ARRAY_FILTER_USE_BOTH
24        );
25    }
26
27    public function fileExists(string $filePath): bool
28    {
29        return array_key_exists($filePath, $this->writtenFiles);
30    }
31    public function readContents(string $filePath): string
32    {
33        return $this->writtenFiles[$filePath];
34    }
35}