Skip to content

Commit

Permalink
[10.x] Test Improvements (#50642)
Browse files Browse the repository at this point in the history
* Test Improvements

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* Update composer.json

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone authored Mar 19, 2024
1 parent fc7b8f6 commit 8fc7bd4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"league/flysystem-sftp-v3": "^3.0",
"mockery/mockery": "^1.5.1",
"nyholm/psr7": "^1.2",
"orchestra/testbench-core": "^8.18",
"orchestra/testbench-core": "^8.23.4",
"pda/pheanstalk": "^4.0",
"phpstan/phpstan": "^1.4.7",
"phpunit/phpunit": "^10.0.7",
Expand Down
4 changes: 4 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,8 @@ public function testSortByAlwaysReturnsAssoc($collection)
#[DataProvider('collectionClassProvider')]
public function testSortByMany($collection)
{
$defaultLocale = setlocale(LC_ALL, 0);

$data = new $collection([['item' => '1'], ['item' => '10'], ['item' => 5], ['item' => 20]]);
$expected = $data->pluck('item')->toArray();

Expand Down Expand Up @@ -2172,6 +2174,8 @@ public function testSortByMany($collection)
sort($expected, SORT_LOCALE_STRING);
$data = $data->sortBy(['item'], SORT_LOCALE_STRING);
$this->assertEquals($data->pluck('item')->toArray(), $expected);

setlocale(LC_ALL, $defaultLocale);
}

/**
Expand Down
32 changes: 9 additions & 23 deletions tests/Support/SupportNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace Illuminate\Tests\Support;

use Illuminate\Support\Number;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use PHPUnit\Framework\TestCase;

class SupportNumberTest extends TestCase
{
#[RequiresPhpExtension('intl')]
public function testFormat()
{
$this->needsIntlExtension();

$this->assertSame('0', Number::format(0));
$this->assertSame('0', Number::format(0.0));
$this->assertSame('0', Number::format(0.00));
Expand Down Expand Up @@ -40,21 +40,19 @@ public function testFormat()
$this->assertSame('NaN', Number::format(NAN));
}

#[RequiresPhpExtension('intl')]
public function testFormatWithDifferentLocale()
{
$this->needsIntlExtension();

$this->assertSame('123,456,789', Number::format(123456789, locale: 'en'));
$this->assertSame('123.456.789', Number::format(123456789, locale: 'de'));
$this->assertSame('123 456 789', Number::format(123456789, locale: 'fr'));
$this->assertSame('123 456 789', Number::format(123456789, locale: 'ru'));
$this->assertSame('123 456 789', Number::format(123456789, locale: 'sv'));
}

#[RequiresPhpExtension('intl')]
public function testFormatWithAppLocale()
{
$this->needsIntlExtension();

$this->assertSame('123,456,789', Number::format(123456789));

Number::useLocale('de');
Expand All @@ -70,17 +68,15 @@ public function testSpellout()
$this->assertSame('one point two', Number::spell(1.2));
}

#[RequiresPhpExtension('intl')]
public function testSpelloutWithLocale()
{
$this->needsIntlExtension();

$this->assertSame('trois', Number::spell(3, 'fr'));
}

#[RequiresPhpExtension('intl')]
public function testSpelloutWithThreshold()
{
$this->needsIntlExtension();

$this->assertSame('9', Number::spell(9, after: 10));
$this->assertSame('10', Number::spell(10, after: 10));
$this->assertSame('eleven', Number::spell(11, after: 10));
Expand All @@ -100,10 +96,9 @@ public function testOrdinal()
$this->assertSame('3rd', Number::ordinal(3));
}

#[RequiresPhpExtension('intl')]
public function testToPercent()
{
$this->needsIntlExtension();

$this->assertSame('0%', Number::percentage(0, precision: 0));
$this->assertSame('0%', Number::percentage(0));
$this->assertSame('1%', Number::percentage(1));
Expand All @@ -124,10 +119,9 @@ public function testToPercent()
$this->assertSame('0.1235%', Number::percentage(0.12345, precision: 4));
}

#[RequiresPhpExtension('intl')]
public function testToCurrency()
{
$this->needsIntlExtension();

$this->assertSame('$0.00', Number::currency(0));
$this->assertSame('$1.00', Number::currency(1));
$this->assertSame('$10.00', Number::currency(10));
Expand All @@ -141,10 +135,9 @@ public function testToCurrency()
$this->assertSame('$5.32', Number::currency(5.325));
}

#[RequiresPhpExtension('intl')]
public function testToCurrencyWithDifferentLocale()
{
$this->needsIntlExtension();

$this->assertSame('1,00 €', Number::currency(1, 'EUR', 'de'));
$this->assertSame('1,00 $', Number::currency(1, 'USD', 'de'));
$this->assertSame('1,00 £', Number::currency(1, 'GBP', 'de'));
Expand Down Expand Up @@ -293,11 +286,4 @@ public function testSummarize()
$this->assertSame('-1Q', Number::abbreviate(-1000000000000000));
$this->assertSame('-1KQ', Number::abbreviate(-1000000000000000000));
}

protected function needsIntlExtension()
{
if (! extension_loaded('intl')) {
$this->markTestSkipped('The intl extension is not installed. Please install the extension to enable '.__CLASS__);
}
}
}

0 comments on commit 8fc7bd4

Please sign in to comment.