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

Add test #269

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
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
25 changes: 8 additions & 17 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,25 @@ final class Application extends BaseApplication
public const APPLICATION_NAME = 'Twig-CS-Fixer';
public const PACKAGE_NAME = 'vincentlanglet/twig-cs-fixer';

public function __construct()
public function __construct(string $name = self::APPLICATION_NAME, string $package = self::PACKAGE_NAME)
{
parent::__construct(self::APPLICATION_NAME, $this->getPackageVersion());
parent::__construct($name, $this->getPackageVersion($package));
}

private function getPackageVersion(): string
private function getPackageVersion(string $package): string
{
foreach (InstalledVersions::getAllRawData() as $installed) {
if (!isset($installed['versions'][self::PACKAGE_NAME])) {
if (!isset($installed['versions'][$package])) {
continue;
}

$version = $installed['versions'][self::PACKAGE_NAME]['pretty_version']
?? $installed['versions'][self::PACKAGE_NAME]['version']
?? 'dev';

$aliases = $installed['versions'][self::PACKAGE_NAME]['aliases'] ?? [];

$reference = InstalledVersions::getReference(self::PACKAGE_NAME);
$version = $installed['versions'][$package]['pretty_version'] ?? 'dev';
$reference = $installed['versions'][$package]['reference'] ?? null;
if (null === $reference) {
return $aliases[0] ?? $version;
return $version;
}

return sprintf(
'%s@%s',
$aliases[0] ?? $version,
substr($reference, 0, 7)
);
return sprintf('%s@%s', $version, substr($reference, 0, 7));
}

return 'UNKNOWN';
Expand Down
2 changes: 1 addition & 1 deletion src/Util/StringUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Symfony\Component\String\UnicodeString;

class StringUtil
final class StringUtil
{
/**
* @see UnicodeString::camel()
Expand Down
32 changes: 32 additions & 0 deletions tests/Console/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace TwigCsFixer\Tests\Console;

use PHPUnit\Framework\TestCase;
use TwigCsFixer\Console\Application;

final class ApplicationTest extends TestCase
{
public function testVersion(): void
{
$app = new Application();
static::assertSame(Application::APPLICATION_NAME, $app->getName());
static::assertMatchesRegularExpression('/^dev-.+@.{7}$/', $app->getVersion());
}

public function testNotInstalledLib(): void
{
$app = new Application('Foo', 'foo');
static::assertSame('Foo', $app->getName());
static::assertSame('UNKNOWN', $app->getVersion());
}

public function testLibWithoutVersion(): void
{
$app = new Application('Psalm', 'psalm/psalm');
static::assertSame('Psalm', $app->getName());
static::assertSame('dev', $app->getVersion());
}
}
2 changes: 1 addition & 1 deletion tests/Rules/Node/ForbiddenBlock/ForbiddenBlockRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use TwigCsFixer\Rules\Node\ForbiddenBlockRule;
use TwigCsFixer\Tests\Rules\AbstractRuleTestCase;

class ForbiddenBlockRuleTest extends AbstractRuleTestCase
final class ForbiddenBlockRuleTest extends AbstractRuleTestCase
{
public function testConfiguration(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use TwigCsFixer\Rules\Node\ForbiddenFilterRule;
use TwigCsFixer\Tests\Rules\AbstractRuleTestCase;

class ForbiddenFilterRuleTest extends AbstractRuleTestCase
final class ForbiddenFilterRuleTest extends AbstractRuleTestCase
{
public function testConfiguration(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use TwigCsFixer\Rules\Node\ForbiddenFunctionRule;
use TwigCsFixer\Tests\Rules\AbstractRuleTestCase;

class ForbiddenFunctionRuleTest extends AbstractRuleTestCase
final class ForbiddenFunctionRuleTest extends AbstractRuleTestCase
{
public function testConfiguration(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Rules/String/HashQuote/HashQuoteRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use TwigCsFixer\Rules\String\HashQuoteRule;
use TwigCsFixer\Tests\Rules\AbstractRuleTestCase;

class HashQuoteRuleTest extends AbstractRuleTestCase
final class HashQuoteRuleTest extends AbstractRuleTestCase
{
public function testConfiguration(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Rules/String/SimpleQuote/SingleQuoteRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use TwigCsFixer\Rules\String\SingleQuoteRule;
use TwigCsFixer\Tests\Rules\AbstractRuleTestCase;

class SingleQuoteRuleTest extends AbstractRuleTestCase
final class SingleQuoteRuleTest extends AbstractRuleTestCase
{
public function testConfiguration(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Util/StringUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PHPUnit\Framework\TestCase;
use TwigCsFixer\Util\StringUtil;

class StringUtilTest extends TestCase
final class StringUtilTest extends TestCase
{
/**
* @dataProvider toSnakeCaseDataProvider
Expand Down
Loading