1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
<?php
declare(strict_types=1);
namespace libphonenumber\Tests\core;
use libphonenumber\MultiFileMetadataSourceImpl;
use libphonenumber\PhoneNumberUtil;
use PHPUnit\Framework\TestCase;
use RuntimeException;
class MultiFileMetadataSourceImplTest extends TestCase
{
private MultiFileMetadataSourceImpl $multiFileMetadataSource;
public function setUp(): void
{
$this->multiFileMetadataSource = new MultiFileMetadataSourceImpl(
__NAMESPACE__ . '\data\PhoneNumberMetadataForTesting_',
);
}
public function testMissingMetadataFileThrowsRuntimeException(): void
{
// In normal usage we should never get a state where we are asking to load metadata that doesn't
// exist. However if the library is packaged incorrectly, this could happen and the best we can
// do is make sure the exception has the file name in it.
try {
$this->multiFileMetadataSource->loadMetadataFromFile('no/such/file', 'XX', -1);
self::fail('Expected Exception');
} catch (RuntimeException $e) {
self::assertStringContainsString(
'missing metadata: no/such/fileXX',
$e->getMessage(),
'Unexpected error: ' . $e->getMessage()
);
}
try {
$this->multiFileMetadataSource->loadMetadataFromFile(
'no/such/file',
PhoneNumberUtil::REGION_CODE_FOR_NON_GEO_ENTITY,
123,
);
self::fail('Expected Exception');
} catch (RuntimeException $e) {
self::assertStringContainsString(
'missing metadata: no/such/file123',
$e->getMessage(),
'Unexpected error: ' . $e->getMessage()
);
}
}
}
|