Skip to content

Commit

Permalink
Prepare to release
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Jun 1, 2024
1 parent 40443d4 commit 980874d
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Concerns/HasKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

trait HasKey
{
protected function resolveKey(BackedEnum|int|string $key): int|string
protected function resolveKey(BackedEnum | int | string $key): int | string
{
if ($key instanceof BackedEnum) {
return $key->value ?? $key->name;
Expand Down
16 changes: 11 additions & 5 deletions src/Concerns/HasValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@ trait HasValues
{
use HasKey;

public function get(BackedEnum|int|string $key): mixed
public function get(BackedEnum | int | string $key): mixed
{
$key = $this->resolveKey($key);

$main = $this->key . '.' . $key;
$main = $this->key . '.' . $key;
$default = $this->default ? $this->default . '.' . $key : null;

if ($this->default) {
return $this->value($main, $default) ?? $this->value($this->default);
}

return $this->value($main, $default);
}

protected function value(string $key, ?string $default = null): mixed
{
return $default
? config()->get($key, config()->get($default))
: config()->get($key);
if ($default) {
return config()->get($key) ?: config()->get($default);
}

return config()->get($key);
}
}
43 changes: 43 additions & 0 deletions tests/Unit/Facades/Config/HiddenWithoutEnvTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

use LaravelLang\Config\Facades\Config;

test('plugins', function () {
config(['localization-private.plugins' => ['foo', 'bar']]);

expect(Config::hidden()->plugins->all())
->toBeArray()
->toBe(['foo', 'bar'])
->toBe(config('localization-private.plugins'));

Config::hidden()->plugins->push('baz');

expect(Config::hidden()->plugins->all())
->toBeArray()
->toBe(['foo', 'bar', 'baz'])
->toBe(config('localization-private.plugins'));
});

test('packages', function () {
config(['localization-private.packages' => ['foo', 'bar']]);

expect(Config::hidden()->packages->all())
->toBeArray()
->toBe(['foo', 'bar'])
->toBe(config('localization-private.packages'));

Config::hidden()->packages->push('baz');

expect(Config::hidden()->packages->all())
->toBeArray()
->toBe(['foo', 'bar', 'baz'])
->toBe(config('localization-private.packages'));
});

test('map', function () {
expect(Config::hidden()->map->all())
->toBeArray()
->toBe(config('localization-private.map'));
});
2 changes: 1 addition & 1 deletion tests/Unit/Facades/Config/SharedWithEnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
});

test('aliases', function () {
expect(Config::shared()->aliases)
expect(Config::shared()->aliases->all())
->toBeArray()
->toBe(config('localization.aliases'));
});
Expand Down
63 changes: 63 additions & 0 deletions tests/Unit/Facades/Config/SharedWithoutEnvTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

use LaravelLang\Config\Facades\Config;
use LaravelLang\LocaleList\Locale;

beforeAll(function () {
putenv('LOCALIZATION_INLINE=true');
putenv('LOCALIZATION_ALIGN=false');
putenv('LOCALIZATION_SMART_ENABLED=true');
});

test('inline', function () {
expect(Config::shared()->inline)
->toBeBool()
->toBeTrue()
->toBe(config('localization.inline'));
});

test('align', function () {
expect(Config::shared()->align)
->toBeBool()
->toBeFalse()
->toBe(config('localization.align'));
});

test('aliases', function () {
expect(Config::shared()->aliases->all())
->toBeArray()
->toBe(config('localization.aliases'));
});

test('smart punctuation: enabled', function () {
expect(Config::shared()->punctuation->enabled)
->toBeBool()
->toBeTrue()
->toBe(config('localization.smart_punctuation.enabled'));
});

test('smart punctuation: common', function () {
expect(Config::shared()->punctuation->common)
->toBeArray()
->toBe(config('localization.smart_punctuation.common'));
});

test('smart punctuation: locales', function () {
expect(Config::shared()->punctuation->locales->all())
->toBeArray()
->toBe(config('localization.smart_punctuation.locales'));
});

test('smart punctuation: get locale', function () {
expect(Config::shared()->punctuation->locales->get(Locale::French))
->toBeArray()
->toBe(config('localization.smart_punctuation.locales.' . Locale::French->value));
});

test('smart punctuation: get default locale', function () {
expect(Config::shared()->punctuation->locales->get(Locale::Zulu))
->toBeArray()
->toBe(config('localization.smart_punctuation.common'));
});

0 comments on commit 980874d

Please sign in to comment.