Skip to content

Commit

Permalink
Merge pull request #2 from Oleksandr-Moik/shift-112999
Browse files Browse the repository at this point in the history
PHPUnit 10 Shift
  • Loading branch information
Oleksandr-Moik authored Mar 17, 2024
2 parents 1a13780 + 1b47948 commit e05dcec
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/vendor/
/composer.lock
/coverage/
/.phpunit.result.cache
/.phpunit.cache
/build/
/coverage.clover
/.idea
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"laravel/pint": "^1.14",
"mockery/mockery": "^1.3.3",
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpunit/phpunit": "^9.0 || ^10.0"
"phpunit/phpunit": "^10.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
13 changes: 7 additions & 6 deletions tests/EloquentOverrideTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace Astrotomic\Translatable\Tests;

use PHPUnit\Framework\Attributes\Test;
use Astrotomic\Translatable\Tests\Eloquent\Vegetable;

final class EloquentOverrideTest extends TestCase
{
/** @test */
#[Test]
public function to_array_returns_translated_attributes(): void
{
$vegetable = factory(Vegetable::class)->make(['name:en' => 'Peas']);
Expand All @@ -15,15 +16,15 @@ public function to_array_returns_translated_attributes(): void
static::assertEquals('Peas', $vegetable->toArray()['name']);
}

/** @test */
#[Test]
public function to_array_wont_break_if_no_translations_exist(): void
{
$vegetable = factory(Vegetable::class)->make();

static::assertIsArray($vegetable->toArray());
}

/** @test */
#[Test]
public function translated_attributes_can_be_accessed_as_properties(): void
{
$vegetable = factory(Vegetable::class)->make(['name:en' => 'Peas']);
Expand All @@ -32,7 +33,7 @@ public function translated_attributes_can_be_accessed_as_properties(): void
static::assertEquals('Peas', $vegetable->name);
}

/** @test */
#[Test]
public function it_can_hide_translated_attributes(): void
{
$vegetable = factory(Vegetable::class)->make(['name:en' => 'Peas']);
Expand All @@ -44,15 +45,15 @@ public function it_can_hide_translated_attributes(): void
static::assertFalse(isset($vegetable->toArray()['name']));
}

/** @test */
#[Test]
public function it_finds_custom_primary_keys(): void
{
$vegetable = new Vegetable();

static::assertEquals('vegetable_identity', $vegetable->getTranslationRelationKey());
}

/** @test */
#[Test]
public function setAttribute_returns_parent_setAttribute(): void
{
$vegetable = new Vegetable();
Expand Down
45 changes: 23 additions & 22 deletions tests/LocalesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Astrotomic\Translatable\Tests;

use PHPUnit\Framework\Attributes\Test;
use Astrotomic\Translatable\Exception\LocalesNotDefinedException;
use Astrotomic\Translatable\Locales;

final class LocalesTest extends TestCase
{
/** @test */
#[Test]
public function locales_is_declared_as_a_singleton_instance(): void
{
$singletonHash = spl_object_hash(app(Locales::class));
Expand All @@ -16,7 +17,7 @@ public function locales_is_declared_as_a_singleton_instance(): void
static::assertEquals($singletonHash, spl_object_hash($this->app->make(Locales::class)));
}

/** @test */
#[Test]
public function it_loads_the_locales_from_the_configuration(): void
{
$this->app['config']->set('translatable.locales', [
Expand All @@ -34,7 +35,7 @@ public function it_loads_the_locales_from_the_configuration(): void
static::assertEquals(['de', 'en'], $this->app->make('translatable.locales')->all());
}

/** @test */
#[Test]
public function it_throws_an_exception_if_there_are_no_locales(): void
{
$this->expectException(LocalesNotDefinedException::class);
Expand All @@ -43,7 +44,7 @@ public function it_throws_an_exception_if_there_are_no_locales(): void
$this->app->make('translatable.locales')->load();
}

/** @test */
#[Test]
public function all_language_locales_are_loaded_from_the_configuration(): void
{
$this->app['config']->set('translatable.locales', [
Expand All @@ -58,7 +59,7 @@ public function all_language_locales_are_loaded_from_the_configuration(): void
static::assertEquals(['el', 'en', 'fr', 'de', 'id'], $this->app->make('translatable.locales')->all());
}

/** @test */
#[Test]
public function it_loads_locales_and_countries(): void
{
$this->app['config']->set('translatable.locales', [
Expand All @@ -76,7 +77,7 @@ public function it_loads_locales_and_countries(): void
static::assertEquals(['en', 'en-GB', 'en-US', 'de', 'de-DE', 'de-CH'], $this->app->make('translatable.locales')->all());
}

/** @test */
#[Test]
public function can_return_locales_as_array(): void
{
$this->app['config']->set('translatable.locales', [
Expand All @@ -91,15 +92,15 @@ public function can_return_locales_as_array(): void
static::assertEquals(['el', 'en', 'fr', 'de', 'id'], $this->app->make('translatable.locales')->toArray());
}

/** @test */
#[Test]
public function can_retrieve_current_configuration(): void
{
$this->app['config']->set('translatable.locale', 'de');

static::assertEquals('de', $this->app->make('translatable.locales')->current());
}

/** @test */
#[Test]
public function current_can_return_the_translator_locale_if_configuration_is_empty(): void
{
$this->app['config']->set('translatable.locale', null);
Expand All @@ -108,7 +109,7 @@ public function current_can_return_the_translator_locale_if_configuration_is_emp
static::assertEquals('en', $this->app->make('translatable.locales')->current());
}

/** @test */
#[Test]
public function it_checks_if_it_has_a_locale(): void
{
$this->app['config']->set('translatable.locales', [
Expand All @@ -124,7 +125,7 @@ public function it_checks_if_it_has_a_locale(): void
static::assertFalse($this->app->make('translatable.locales')->has('jp'));
}

/** @test */
#[Test]
public function can_access_as_an_array(): void
{
$this->app['config']->set('translatable.locales', [
Expand All @@ -140,7 +141,7 @@ public function can_access_as_an_array(): void
static::assertFalse(isset($this->app->make('translatable.locales')['jp']));
}

/** @test */
#[Test]
public function can_retrieve_a_specific_locale_by_get(): void
{
$this->app['config']->set('translatable.locales', [
Expand All @@ -156,7 +157,7 @@ public function can_retrieve_a_specific_locale_by_get(): void
static::assertNull($this->app->make('translatable.locales')->get('jp'));
}

/** @test */
#[Test]
public function missing_locale_returns_null_by_get(): void
{
$this->app['config']->set('translatable.locales', [
Expand All @@ -172,7 +173,7 @@ public function missing_locale_returns_null_by_get(): void
static::assertNull($this->app->make('translatable.locales')['jp']);
}

/** @test */
#[Test]
public function it_can_add_a_locale(): void
{
$this->app['config']->set('translatable.locales', [
Expand All @@ -186,7 +187,7 @@ public function it_can_add_a_locale(): void
static::assertTrue($this->app->make('translatable.locales')->has('en'));
}

/** @test */
#[Test]
public function locale_can_be_added_by_accessing_as_an_array(): void
{
$this->app['config']->set('translatable.locales', [
Expand All @@ -200,7 +201,7 @@ public function locale_can_be_added_by_accessing_as_an_array(): void
static::assertTrue($this->app->make('translatable.locales')->has('en'));
}

/** @test */
#[Test]
public function locale_country_can_be_added_by_accessing_as_an_array(): void
{
$this->app['config']->set('translatable.locales', [
Expand All @@ -214,7 +215,7 @@ public function locale_country_can_be_added_by_accessing_as_an_array(): void
static::assertTrue($this->app->make('translatable.locales')->has('de-AT'));
}

/** @test */
#[Test]
public function can_forget_a_locale(): void
{
$this->app['config']->set('translatable.locales', [
Expand All @@ -229,7 +230,7 @@ public function can_forget_a_locale(): void
static::assertFalse($this->app->make('translatable.locales')->has('en'));
}

/** @test */
#[Test]
public function can_forget_a_locale_using_unset_as_an_array(): void
{
$this->app['config']->set('translatable.locales', [
Expand All @@ -244,36 +245,36 @@ public function can_forget_a_locale_using_unset_as_an_array(): void
static::assertFalse($this->app->make('translatable.locales')->has('en'));
}

/** @test */
#[Test]
public function can_retrieve_the_locale_country_separator(): void
{
$this->app['config']->set('translatable.locale_separator', '_');

static::assertEquals('_', $this->app->make('translatable.locales')->getLocaleSeparator());
}

/** @test */
#[Test]
public function can_set_a_default_locale_country_separator_if_configuration_is_missing(): void
{
$this->app['config']->set('translatable.locale_separator', null);

static::assertEquals('-', $this->app->make('translatable.locales')->getLocaleSeparator());
}

/** @test */
#[Test]
public function can_get_a_country_locale_formatted_with_separator(): void
{
static::assertEquals('de-AT', $this->app->make('translatable.locales')->getCountryLocale('de', 'AT'));
}

/** @test */
#[Test]
public function can_determine_if_a_locale_is_country_based(): void
{
static::assertTrue($this->app->make('translatable.locales')->isLocaleCountryBased('de-AT'));
static::assertFalse($this->app->make('translatable.locales')->isLocaleCountryBased('de'));
}

/** @test */
#[Test]
public function can_get_a_locale_from_the_country_locale(): void
{
static::assertEquals('de', $this->app->make('translatable.locales')->getLanguageFromCountryBasedLocale('de-AT'));
Expand Down
Loading

0 comments on commit e05dcec

Please sign in to comment.