Skip to content
/ intl Public

Commit 8d04926

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: fix merge do not use PHPUnit mock objects without configured expectations [String] Fix UnicodeString::startsWith()/endsWith() on strings that start/end with a zero fix low deps test with Console component < 6.4 [FrameworkBundle] Check for console package before register `CommandDataCollector` do not use PHPUnit mock objects without configured expectations [FrameworkBundle] Ensure a fresh container is used after cache warmup in KernelTestCase do not use PHPUnit mock objects without configured expectations add back missing enabled key in normalization step do not use PHPUnit mock objects without configured expectations [Finder] Fix `Finder::append()` breaking generic typing contract
2 parents f9eca21 + 7fa2d46 commit 8d04926

File tree

1 file changed

+66
-49
lines changed

1 file changed

+66
-49
lines changed

Tests/Data/Bundle/Reader/BundleEntryReaderTest.php

Lines changed: 66 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\Intl\Tests\Data\Bundle\Reader;
1313

1414
use PHPUnit\Framework\Attributes\DataProvider;
15-
use PHPUnit\Framework\MockObject\MockObject;
1615
use PHPUnit\Framework\TestCase;
1716
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReader;
1817
use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface;
@@ -26,9 +25,6 @@ class BundleEntryReaderTest extends TestCase
2625
{
2726
private const RES_DIR = '/res/dir';
2827

29-
private BundleEntryReader $reader;
30-
private MockObject&BundleEntryReaderInterface $readerImpl;
31-
3228
private const DATA = [
3329
'Entries' => [
3430
'Foo' => 'Bar',
@@ -58,25 +54,21 @@ class BundleEntryReaderTest extends TestCase
5854
'Foo' => 'Bar',
5955
];
6056

61-
protected function setUp(): void
62-
{
63-
$this->readerImpl = $this->createMock(BundleEntryReaderInterface::class);
64-
$this->reader = new BundleEntryReader($this->readerImpl);
65-
}
66-
6757
public function testForwardCallToRead()
6858
{
69-
$this->readerImpl->expects($this->once())
59+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
60+
$readerImpl->expects($this->once())
7061
->method('read')
7162
->with(self::RES_DIR, 'root')
7263
->willReturn(self::DATA);
7364

74-
$this->assertSame(self::DATA, $this->reader->read(self::RES_DIR, 'root'));
65+
$this->assertSame(self::DATA, $this->getReader($readerImpl)->read(self::RES_DIR, 'root'));
7566
}
7667

7768
public function testReadEntireDataFileIfNoIndicesGiven()
7869
{
79-
$this->readerImpl->expects($this->exactly(2))
70+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
71+
$readerImpl->expects($this->exactly(2))
8072
->method('read')
8173
->willReturnCallback(function (...$args) {
8274
static $series = [
@@ -91,33 +83,36 @@ public function testReadEntireDataFileIfNoIndicesGiven()
9183
})
9284
;
9385

94-
$this->assertSame(self::MERGED_DATA, $this->reader->readEntry(self::RES_DIR, 'en', []));
86+
$this->assertSame(self::MERGED_DATA, $this->getReader($readerImpl)->readEntry(self::RES_DIR, 'en', []));
9587
}
9688

9789
public function testReadExistingEntry()
9890
{
99-
$this->readerImpl->expects($this->once())
91+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
92+
$readerImpl->expects($this->once())
10093
->method('read')
10194
->with(self::RES_DIR, 'root')
10295
->willReturn(self::DATA);
10396

104-
$this->assertSame('Bar', $this->reader->readEntry(self::RES_DIR, 'root', ['Entries', 'Foo']));
97+
$this->assertSame('Bar', $this->getReader($readerImpl)->readEntry(self::RES_DIR, 'root', ['Entries', 'Foo']));
10598
}
10699

107100
public function testReadNonExistingEntry()
108101
{
109102
$this->expectException(MissingResourceException::class);
110-
$this->readerImpl->expects($this->once())
103+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
104+
$readerImpl->expects($this->once())
111105
->method('read')
112106
->with(self::RES_DIR, 'root')
113107
->willReturn(self::DATA);
114108

115-
$this->reader->readEntry(self::RES_DIR, 'root', ['Entries', 'NonExisting']);
109+
$this->getReader($readerImpl)->readEntry(self::RES_DIR, 'root', ['Entries', 'NonExisting']);
116110
}
117111

118112
public function testFallbackIfEntryDoesNotExist()
119113
{
120-
$this->readerImpl->expects($this->exactly(2))
114+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
115+
$readerImpl->expects($this->exactly(2))
121116
->method('read')
122117
->willReturnCallback(function (...$args) {
123118
static $series = [
@@ -132,18 +127,19 @@ public function testFallbackIfEntryDoesNotExist()
132127
})
133128
;
134129

135-
$this->assertSame('Lah', $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam']));
130+
$this->assertSame('Lah', $this->getReader($readerImpl)->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam']));
136131
}
137132

138133
public function testDontFallbackIfEntryDoesNotExistAndFallbackDisabled()
139134
{
140135
$this->expectException(MissingResourceException::class);
141-
$this->readerImpl->expects($this->once())
136+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
137+
$readerImpl->expects($this->once())
142138
->method('read')
143139
->with(self::RES_DIR, 'en_GB')
144140
->willReturn(self::DATA);
145141

146-
$this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam'], false);
142+
$this->getReader($readerImpl)->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam'], false);
147143
}
148144

149145
public function testFallbackIfLocaleDoesNotExist()
@@ -154,7 +150,8 @@ public function testFallbackIfLocaleDoesNotExist()
154150
[[self::RES_DIR, 'en'], self::FALLBACK_DATA],
155151
];
156152

157-
$this->readerImpl->expects($this->exactly(2))
153+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
154+
$readerImpl->expects($this->exactly(2))
158155
->method('read')
159156
->willReturnCallback(function (...$args) use (&$series) {
160157
[$expectedArgs, $return] = array_shift($series);
@@ -168,18 +165,19 @@ public function testFallbackIfLocaleDoesNotExist()
168165
})
169166
;
170167

171-
$this->assertSame('Lah', $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam']));
168+
$this->assertSame('Lah', $this->getReader($readerImpl)->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam']));
172169
}
173170

174171
public function testDontFallbackIfLocaleDoesNotExistAndFallbackDisabled()
175172
{
176173
$this->expectException(MissingResourceException::class);
177-
$this->readerImpl->expects($this->once())
174+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
175+
$readerImpl->expects($this->once())
178176
->method('read')
179177
->with(self::RES_DIR, 'en_GB')
180178
->willThrowException(new ResourceBundleNotFoundException());
181179

182-
$this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam'], false);
180+
$this->getReader($readerImpl)->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam'], false);
183181
}
184182

185183
public static function provideMergeableValues()
@@ -198,13 +196,15 @@ public static function provideMergeableValues()
198196
#[DataProvider('provideMergeableValues')]
199197
public function testMergeDataWithFallbackData($childData, $parentData, $result)
200198
{
199+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
200+
201201
if (null === $childData || \is_array($childData)) {
202202
$series = [
203203
[[self::RES_DIR, 'en'], $childData],
204204
[[self::RES_DIR, 'root'], $parentData],
205205
];
206206

207-
$this->readerImpl->expects($this->exactly(2))
207+
$readerImpl->expects($this->exactly(2))
208208
->method('read')
209209
->willReturnCallback(function (...$args) use (&$series) {
210210
[$expectedArgs, $return] = array_shift($series);
@@ -214,36 +214,39 @@ public function testMergeDataWithFallbackData($childData, $parentData, $result)
214214
})
215215
;
216216
} else {
217-
$this->readerImpl->expects($this->once())
217+
$readerImpl->expects($this->once())
218218
->method('read')
219219
->with(self::RES_DIR, 'en')
220220
->willReturn($childData);
221221
}
222222

223-
$this->assertSame($result, $this->reader->readEntry(self::RES_DIR, 'en', [], true));
223+
$this->assertSame($result, $this->getReader($readerImpl)->readEntry(self::RES_DIR, 'en', [], true));
224224
}
225225

226226
#[DataProvider('provideMergeableValues')]
227227
public function testDontMergeDataIfFallbackDisabled($childData, $parentData, $result)
228228
{
229-
$this->readerImpl->expects($this->once())
229+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
230+
$readerImpl->expects($this->once())
230231
->method('read')
231232
->with(self::RES_DIR, 'en_GB')
232233
->willReturn($childData);
233234

234-
$this->assertSame($childData, $this->reader->readEntry(self::RES_DIR, 'en_GB', [], false));
235+
$this->assertSame($childData, $this->getReader($readerImpl)->readEntry(self::RES_DIR, 'en_GB', [], false));
235236
}
236237

237238
#[DataProvider('provideMergeableValues')]
238239
public function testMergeExistingEntryWithExistingFallbackEntry($childData, $parentData, $result)
239240
{
241+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
242+
240243
if (null === $childData || \is_array($childData)) {
241244
$series = [
242245
[[self::RES_DIR, 'en'], ['Foo' => ['Bar' => $childData]]],
243246
[[self::RES_DIR, 'root'], ['Foo' => ['Bar' => $parentData]]],
244247
];
245248

246-
$this->readerImpl->expects($this->exactly(2))
249+
$readerImpl->expects($this->exactly(2))
247250
->method('read')
248251
->willReturnCallback(function (...$args) use (&$series) {
249252
[$expectedArgs, $return] = array_shift($series);
@@ -253,13 +256,13 @@ public function testMergeExistingEntryWithExistingFallbackEntry($childData, $par
253256
})
254257
;
255258
} else {
256-
$this->readerImpl->expects($this->once())
259+
$readerImpl->expects($this->once())
257260
->method('read')
258261
->with(self::RES_DIR, 'en')
259262
->willReturn(['Foo' => ['Bar' => $childData]]);
260263
}
261264

262-
$this->assertSame($result, $this->reader->readEntry(self::RES_DIR, 'en', ['Foo', 'Bar'], true));
265+
$this->assertSame($result, $this->getReader($readerImpl)->readEntry(self::RES_DIR, 'en', ['Foo', 'Bar'], true));
263266
}
264267

265268
#[DataProvider('provideMergeableValues')]
@@ -270,7 +273,8 @@ public function testMergeNonExistingEntryWithExistingFallbackEntry($childData, $
270273
[[self::RES_DIR, 'en'], ['Foo' => ['Bar' => $parentData]]],
271274
];
272275

273-
$this->readerImpl
276+
$readerImpl = $this->createStub(BundleEntryReaderInterface::class);
277+
$readerImpl
274278
->method('read')
275279
->willReturnCallback(function (...$args) use (&$series) {
276280
[$expectedArgs, $return] = array_shift($series);
@@ -279,7 +283,7 @@ public function testMergeNonExistingEntryWithExistingFallbackEntry($childData, $
279283
})
280284
;
281285

282-
$this->assertSame($parentData, $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true));
286+
$this->assertSame($parentData, $this->getReader($readerImpl)->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true));
283287
}
284288

285289
#[DataProvider('provideMergeableValues')]
@@ -291,7 +295,8 @@ public function testMergeExistingEntryWithNonExistingFallbackEntry($childData, $
291295
[[self::RES_DIR, 'en'], ['Foo' => 'Bar']],
292296
];
293297

294-
$this->readerImpl
298+
$readerImpl = $this->createStub(BundleEntryReaderInterface::class);
299+
$readerImpl
295300
->method('read')
296301
->willReturnCallback(function (...$args) use (&$series) {
297302
[$expectedArgs, $return] = array_shift($series);
@@ -300,20 +305,22 @@ public function testMergeExistingEntryWithNonExistingFallbackEntry($childData, $
300305
})
301306
;
302307
} else {
303-
$this->readerImpl->expects($this->once())
308+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
309+
$readerImpl->expects($this->once())
304310
->method('read')
305311
->with(self::RES_DIR, 'en_GB')
306312
->willReturn(['Foo' => ['Bar' => $childData]]);
307313
}
308314

309-
$this->assertSame($childData, $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true));
315+
$this->assertSame($childData, $this->getReader($readerImpl)->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true));
310316
}
311317

312318
public function testFailIfEntryFoundNeitherInParentNorChild()
313319
{
314320
$this->expectException(MissingResourceException::class);
315321

316-
$this->readerImpl
322+
$readerImpl = $this->createStub(BundleEntryReaderInterface::class);
323+
$readerImpl
317324
->method('read')
318325
->willReturnCallback(function (...$args) {
319326
static $series = [
@@ -327,7 +334,7 @@ public function testFailIfEntryFoundNeitherInParentNorChild()
327334
})
328335
;
329336

330-
$this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true);
337+
$this->getReader($readerImpl)->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true);
331338
}
332339

333340
#[DataProvider('provideMergeableValues')]
@@ -342,7 +349,8 @@ public function testMergeTraversables($childData, $parentData, $result)
342349
[[self::RES_DIR, 'en'], ['Foo' => ['Bar' => $parentData]]],
343350
];
344351

345-
$this->readerImpl
352+
$readerImpl = $this->createStub(BundleEntryReaderInterface::class);
353+
$readerImpl
346354
->method('read')
347355
->willReturnCallback(function (...$args) use (&$series) {
348356
[$expectedArgs, $return] = array_shift($series);
@@ -351,28 +359,28 @@ public function testMergeTraversables($childData, $parentData, $result)
351359
})
352360
;
353361
} else {
354-
$this->readerImpl->expects($this->once())
362+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
363+
$readerImpl->expects($this->once())
355364
->method('read')
356365
->with(self::RES_DIR, 'en_GB')
357366
->willReturn(['Foo' => ['Bar' => $childData]]);
358367
}
359368

360-
$this->assertSame($result, $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true));
369+
$this->assertSame($result, $this->getReader($readerImpl)->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true));
361370
}
362371

363372
#[DataProvider('provideMergeableValues')]
364373
public function testFollowLocaleAliases($childData, $parentData, $result)
365374
{
366-
$this->reader->setLocaleAliases(['mo' => 'ro_MD']);
367-
368375
if (null === $childData || \is_array($childData)) {
369376
$series = [
370377
[[self::RES_DIR, 'ro_MD'], ['Foo' => ['Bar' => $childData]]],
371378
// Read fallback locale of aliased locale ("ro_MD" -> "ro")
372379
[[self::RES_DIR, 'ro'], ['Foo' => ['Bar' => $parentData]]],
373380
];
374381

375-
$this->readerImpl
382+
$readerImpl = $this->createStub(BundleEntryReaderInterface::class);
383+
$readerImpl
376384
->method('read')
377385
->willReturnCallback(function (...$args) use (&$series) {
378386
[$expectedArgs, $return] = array_shift($series);
@@ -381,12 +389,21 @@ public function testFollowLocaleAliases($childData, $parentData, $result)
381389
})
382390
;
383391
} else {
384-
$this->readerImpl->expects($this->once())
392+
$readerImpl = $this->createMock(BundleEntryReaderInterface::class);
393+
$readerImpl->expects($this->once())
385394
->method('read')
386395
->with(self::RES_DIR, 'ro_MD')
387396
->willReturn(['Foo' => ['Bar' => $childData]]);
388397
}
389398

390-
$this->assertSame($result, $this->reader->readEntry(self::RES_DIR, 'mo', ['Foo', 'Bar'], true));
399+
$reader = $this->getReader($readerImpl);
400+
$reader->setLocaleAliases(['mo' => 'ro_MD']);
401+
402+
$this->assertSame($result, $reader->readEntry(self::RES_DIR, 'mo', ['Foo', 'Bar'], true));
403+
}
404+
405+
private function getReader(?BundleEntryReaderInterface $entryReader = null): BundleEntryReader
406+
{
407+
return new BundleEntryReader($entryReader ?? $this->createStub(BundleEntryReaderInterface::class));
391408
}
392409
}

0 commit comments

Comments
 (0)