|
|
@@ -115,18 +115,30 @@ class CleanTempFilesTest extends TestCase
|
|
|
'List temporary files created before 2022-01-01T12:00:00+00:00'
|
|
|
);
|
|
|
|
|
|
- $files = new ArrayCollection([
|
|
|
- $this->getMockBuilder(File::class)->getMock(),
|
|
|
- $this->getMockBuilder(File::class)->getMock(),
|
|
|
- $this->getMockBuilder(File::class)->getMock()
|
|
|
- ]);
|
|
|
+ $file1 = $this->getMockBuilder(File::class)->getMock(); // Temporary, but recent : do not remove
|
|
|
+ $file1->method('getId')->willReturn(1);
|
|
|
+ $file1->method('getCreateDate')->willReturn(new \DateTime('2022-01-02'));
|
|
|
+ $file1->method('getIsTemporaryFile')->willReturn(true);
|
|
|
+
|
|
|
+ $file2 = $this->getMockBuilder(File::class)->getMock(); // Temporary and 1-year-old : remove
|
|
|
+ $file1->method('getId')->willReturn(2);
|
|
|
+ $file2->method('getCreateDate')->willReturn(new \DateTime('2021-01-01'));
|
|
|
+ $file2->method('getIsTemporaryFile')->willReturn(true);
|
|
|
+
|
|
|
+ $file3 = $this->getMockBuilder(File::class)->getMock(); // 2 years old but not temporary : do not remove
|
|
|
+ $file1->method('getId')->willReturn(3);
|
|
|
+ $file3->method('getCreateDate')->willReturn(new \DateTime('2020-01-01'));
|
|
|
+ $file3->method('getIsTemporaryFile')->willReturn(false);
|
|
|
+
|
|
|
+ $files = new ArrayCollection([$file1, $file2, $file3]);
|
|
|
|
|
|
$this->fileRepository
|
|
|
->expects(self::once())
|
|
|
->method('matching')
|
|
|
->with(
|
|
|
- self::callback(static function (Criteria $c) {
|
|
|
- return $c instanceof Criteria; // TODO: trouver un moyen de tester le critère de façon plus précise
|
|
|
+ self::callback(static function (Criteria $c) use ($files) {
|
|
|
+ $matching = $files->matching($c)->toArray();
|
|
|
+ return count($matching) === 1 && array_values($matching)[0] === $files[1];
|
|
|
})
|
|
|
)->willReturn($files);
|
|
|
|