Skip to content

Commit 8fc7bd4

Browse files
authored
[10.x] Test Improvements (#50642)
* 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>
1 parent fc7b8f6 commit 8fc7bd4

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"league/flysystem-sftp-v3": "^3.0",
106106
"mockery/mockery": "^1.5.1",
107107
"nyholm/psr7": "^1.2",
108-
"orchestra/testbench-core": "^8.18",
108+
"orchestra/testbench-core": "^8.23.4",
109109
"pda/pheanstalk": "^4.0",
110110
"phpstan/phpstan": "^1.4.7",
111111
"phpunit/phpunit": "^10.0.7",

tests/Support/SupportCollectionTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,8 @@ public function testSortByAlwaysReturnsAssoc($collection)
20952095
#[DataProvider('collectionClassProvider')]
20962096
public function testSortByMany($collection)
20972097
{
2098+
$defaultLocale = setlocale(LC_ALL, 0);
2099+
20982100
$data = new $collection([['item' => '1'], ['item' => '10'], ['item' => 5], ['item' => 20]]);
20992101
$expected = $data->pluck('item')->toArray();
21002102

@@ -2172,6 +2174,8 @@ public function testSortByMany($collection)
21722174
sort($expected, SORT_LOCALE_STRING);
21732175
$data = $data->sortBy(['item'], SORT_LOCALE_STRING);
21742176
$this->assertEquals($data->pluck('item')->toArray(), $expected);
2177+
2178+
setlocale(LC_ALL, $defaultLocale);
21752179
}
21762180

21772181
/**

tests/Support/SupportNumberTest.php

+9-23
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace Illuminate\Tests\Support;
44

55
use Illuminate\Support\Number;
6+
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
67
use PHPUnit\Framework\TestCase;
78

89
class SupportNumberTest extends TestCase
910
{
11+
#[RequiresPhpExtension('intl')]
1012
public function testFormat()
1113
{
12-
$this->needsIntlExtension();
13-
1414
$this->assertSame('0', Number::format(0));
1515
$this->assertSame('0', Number::format(0.0));
1616
$this->assertSame('0', Number::format(0.00));
@@ -40,21 +40,19 @@ public function testFormat()
4040
$this->assertSame('NaN', Number::format(NAN));
4141
}
4242

43+
#[RequiresPhpExtension('intl')]
4344
public function testFormatWithDifferentLocale()
4445
{
45-
$this->needsIntlExtension();
46-
4746
$this->assertSame('123,456,789', Number::format(123456789, locale: 'en'));
4847
$this->assertSame('123.456.789', Number::format(123456789, locale: 'de'));
4948
$this->assertSame('123 456 789', Number::format(123456789, locale: 'fr'));
5049
$this->assertSame('123 456 789', Number::format(123456789, locale: 'ru'));
5150
$this->assertSame('123 456 789', Number::format(123456789, locale: 'sv'));
5251
}
5352

53+
#[RequiresPhpExtension('intl')]
5454
public function testFormatWithAppLocale()
5555
{
56-
$this->needsIntlExtension();
57-
5856
$this->assertSame('123,456,789', Number::format(123456789));
5957

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

71+
#[RequiresPhpExtension('intl')]
7372
public function testSpelloutWithLocale()
7473
{
75-
$this->needsIntlExtension();
76-
7774
$this->assertSame('trois', Number::spell(3, 'fr'));
7875
}
7976

77+
#[RequiresPhpExtension('intl')]
8078
public function testSpelloutWithThreshold()
8179
{
82-
$this->needsIntlExtension();
83-
8480
$this->assertSame('9', Number::spell(9, after: 10));
8581
$this->assertSame('10', Number::spell(10, after: 10));
8682
$this->assertSame('eleven', Number::spell(11, after: 10));
@@ -100,10 +96,9 @@ public function testOrdinal()
10096
$this->assertSame('3rd', Number::ordinal(3));
10197
}
10298

99+
#[RequiresPhpExtension('intl')]
103100
public function testToPercent()
104101
{
105-
$this->needsIntlExtension();
106-
107102
$this->assertSame('0%', Number::percentage(0, precision: 0));
108103
$this->assertSame('0%', Number::percentage(0));
109104
$this->assertSame('1%', Number::percentage(1));
@@ -124,10 +119,9 @@ public function testToPercent()
124119
$this->assertSame('0.1235%', Number::percentage(0.12345, precision: 4));
125120
}
126121

122+
#[RequiresPhpExtension('intl')]
127123
public function testToCurrency()
128124
{
129-
$this->needsIntlExtension();
130-
131125
$this->assertSame('$0.00', Number::currency(0));
132126
$this->assertSame('$1.00', Number::currency(1));
133127
$this->assertSame('$10.00', Number::currency(10));
@@ -141,10 +135,9 @@ public function testToCurrency()
141135
$this->assertSame('$5.32', Number::currency(5.325));
142136
}
143137

138+
#[RequiresPhpExtension('intl')]
144139
public function testToCurrencyWithDifferentLocale()
145140
{
146-
$this->needsIntlExtension();
147-
148141
$this->assertSame('1,00 €', Number::currency(1, 'EUR', 'de'));
149142
$this->assertSame('1,00 $', Number::currency(1, 'USD', 'de'));
150143
$this->assertSame('1,00 £', Number::currency(1, 'GBP', 'de'));
@@ -293,11 +286,4 @@ public function testSummarize()
293286
$this->assertSame('-1Q', Number::abbreviate(-1000000000000000));
294287
$this->assertSame('-1KQ', Number::abbreviate(-1000000000000000000));
295288
}
296-
297-
protected function needsIntlExtension()
298-
{
299-
if (! extension_loaded('intl')) {
300-
$this->markTestSkipped('The intl extension is not installed. Please install the extension to enable '.__CLASS__);
301-
}
302-
}
303289
}

0 commit comments

Comments
 (0)