This repository has been archived by the owner on Sep 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make file matching more strict (#70)
* Make file matching more strict. Do it directly on filenames and wrap each regex with ^ and $ * Only output "For more info" link once per file group * Set maximum number of steps for the upload progress bar
- Loading branch information
1 parent
24eb648
commit 73f3508
Showing
7 changed files
with
102 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Tests\Model; | ||
|
||
use App\Model\DependencyFileFormat; | ||
use App\Tests\Command\FindAndUploadFilesCommandTest; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DependencyFileFormatTest extends TestCase | ||
{ | ||
public function testMake(): void | ||
{ | ||
$this->assertIsArray(DependencyFileFormat::make(self::getFormats())); | ||
} | ||
|
||
public function testFindFormatByFileName(): void | ||
{ | ||
$formats = DependencyFileFormat::make(self::getFormats()); | ||
$this->assertNull(DependencyFileFormat::findFormatByFileName($formats, 'test')); | ||
// Test valid file | ||
$fileName = 'package.json'; | ||
$format = DependencyFileFormat::findFormatByFileName($formats, $fileName); | ||
$this->assertInstanceOf(DependencyFileFormat::class, $format); | ||
$this->assertMatchesRegularExpression("/^{$format->getRegex()}$/", $fileName); | ||
// Test match Lock file | ||
$this->assertNull(DependencyFileFormat::findFormatByFileName($formats, $fileName, true)); | ||
$lockFileName = 'yarn.lock'; | ||
$format = DependencyFileFormat::findFormatByFileName($formats, $lockFileName, true); | ||
$this->assertInstanceOf(DependencyFileFormat::class, $format); | ||
$this->assertMatchesRegularExpression("/^{$format->getRegex()}$/", $fileName); | ||
|
||
// Test semi-valid file | ||
$this->assertNull(DependencyFileFormat::findFormatByFileName($formats, 'dev-package.json')); | ||
} | ||
|
||
private static function getFormats(): array | ||
{ | ||
return \json_decode(FindAndUploadFilesCommandTest::FORMATS_JSON_STRING, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Tests\Utility; | ||
|
||
use App\Utility\Utility; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class UtilityTest extends TestCase | ||
{ | ||
public function testPregMatchInArray(): void | ||
{ | ||
// Test exact match | ||
$this->assertTrue(Utility::pregMatchInArray('test', ['no-match', 'test'])); | ||
// Test no match with prefix | ||
$this->assertFalse(Utility::pregMatchInArray('dev-test', ['no-match', 'test'])); | ||
// Test no match with postfix | ||
$this->assertFalse(Utility::pregMatchInArray('test-dev', ['no-match', 'test'])); | ||
// Test no match | ||
$this->assertFalse(Utility::pregMatchInArray('test', ['no-match'])); | ||
} | ||
} |