Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT Make asset variant unit tests order agnostic #535

Merged
merged 1 commit into from
Dec 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions tests/php/FilenameParsing/FileIDHelperResolutionStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,13 @@ public function testFindVariant($strategy, $tuple)
$variantGenerator = $strategy->findVariants($tuple, $this->fs);

/** @var ParsedFileID $parsedFileID */
$c = 0;
foreach ($variantGenerator as $parsedFileID) {
$this->assertNotEmpty($expectedPaths);
$expectedPath = array_shift($expectedPaths);
$this->assertEquals($expectedPath, $parsedFileID->getFileID());
$this->assertTrue(in_array($parsedFileID->getFileID(), $expectedPaths));
$this->assertEquals('mockedvariant', $parsedFileID->getVariant());
$c++;
}

$this->assertEmpty($expectedPaths);
$this->assertSame(count($expectedPaths), $c);
}

public function testFindHashlessVariant()
Expand All @@ -555,24 +554,23 @@ public function testFindHashlessVariant()
);
$this->fs->write('Folder/FolderFile__mockedvariant.pdf', 'version 1 -- mockedvariant');

$expectedPaths = [
['Folder/FolderFile.pdf', ''],
['Folder/FolderFile__mockedvariant.pdf', 'mockedvariant']
$expectedPathsVariants = [
'Folder/FolderFile.pdf|',
'Folder/FolderFile__mockedvariant.pdf|mockedvariant'
// The hash path won't be match, because we're not providing a hash
];

$variantGenerator = $strategy->findVariants(new ParsedFileID('Folder/FolderFile.pdf'), $this->fs);

$c = 0;
/** @var ParsedFileID $parsedFileID */
foreach ($variantGenerator as $parsedFileID) {
$this->assertNotEmpty($expectedPaths, 'More files were returned than expected');
$expectedPath = array_shift($expectedPaths);
$this->assertEquals($expectedPath[0], $parsedFileID->getFileID());
$this->assertEquals($expectedPath[1], $parsedFileID->getVariant());
$pathVariant = implode('|', [$parsedFileID->getFileID(), $parsedFileID->getVariant()]);
$this->assertTrue(in_array($pathVariant, $expectedPathsVariants));
$this->assertEquals($expectedHash, $parsedFileID->getHash());
$c++;
}

$this->assertEmpty($expectedPaths, "Not all expected files were returned");
$this->assertSame(count($expectedPathsVariants), $c);
}

public function testParseFileID()
Expand Down