Skip to content

Commit

Permalink
Fix found mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jul 18, 2024
1 parent 0c89a57 commit 352430b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ composer require internal/dload -W
[![Latest Version on Packagist](https://img.shields.io/packagist/v/internal/dload.svg?style=flat-square&logo=packagist)](https://packagist.org/packages/internal/dload)
[![License](https://img.shields.io/packagist/l/internal/dload.svg?style=flat-square)](LICENSE.md)
[![Total DLoads](https://img.shields.io/packagist/dt/internal/dload.svg?style=flat-square)](https://packagist.org/packages/internal/dload/stats)

## Usage

```bash
./vendor/bin/dload dolt
```
2 changes: 1 addition & 1 deletion src/Module/Archive/Internal/PharAwareArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(\SplFileInfo $archive)

public function extract(): \Generator
{
$phar = $this->open($this->archive);
$phar = $this->archive;
$phar->isReadable() or throw new \LogicException(
\sprintf('Could not open "%s" for reading.', $this->archive->getPathname()),
);
Expand Down
2 changes: 1 addition & 1 deletion src/Module/Common/Architecture.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function tryFromString(string $arch): ?self

public static function tryFromBuildName(string $name): ?self
{
if (\preg_match('/\b(amd64|arm64|aarch64|x86_64|x64|x86)\b/i', $name, $matches) !== 1) {
if (\preg_match('/(?:\b|_)(amd64|arm64|aarch64|x86_64|x64|x86)(?:\b|_)/i', $name, $matches) !== 1) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Module/Common/OperatingSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static function tryFromString(string $name): ?self

public static function tryFromBuildName(string $name): ?self
{
if (\preg_match('/\b(windows|linux|darwin|alpine|bsd|freebsd)\b/i', $name, $matches) !== 1) {
if (\preg_match('/(?:\b|_)(windows|linux|darwin|alpine|bsd|freebsd)(?:\b|_)/i', $name, $matches) !== 1) {
return null;
}

Expand Down
1 change: 0 additions & 1 deletion src/Module/Downloader/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function download(
);
} catch (\Throwable $e) {
$this->logger->exception($e);
yield;
goto start;
} finally {
$repository instanceof Destroyable and $repository->destroy();
Expand Down
6 changes: 5 additions & 1 deletion src/Module/Repository/Internal/ReleasesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ private function comparisonVersionString(ReleaseInterface $release): string
{
$stability = $release->getStability();

return \str_replace('-' . $stability->value, '.' . $stability->getWeight() . '.', $release->getVersion());
return \ltrim(\str_replace(
'-' . $stability->value,
'.' . $stability->getWeight() . '.',
$release->getVersion(),
), 'v');
}
}
27 changes: 27 additions & 0 deletions tests/Unit/Module/Common/ArchitectureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Internal\DLoad\Tests\Unit\Module\Common;

use Internal\DLoad\Module\Common\Architecture;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class ArchitectureTest extends TestCase
{
public static function provideBuildNames(): iterable
{
yield ['roadrunner-2024.1.5-windows-amd64.zip', Architecture::X86_64];
yield ['temporal_cli_0.13.2_windows_amd64.tar.gz', Architecture::X86_64];
yield ['temporal_cli_0.13.2_windows_aaamd64.tar.gz', null];
yield ['temporal_cli_0.13.2_windows.amd644.tar.gz', null];
yield ['roadrunner-2024.1.5-windows.zip', null];
}

#[DataProvider('provideBuildNames')]
public function testTryFromBuildName(string $name, ?Architecture $expected): void
{
self::assertSame($expected, Architecture::tryFromBuildName($name));
}
}

0 comments on commit 352430b

Please sign in to comment.