class FormatterTest in Telephone Formatter 8
Formatter test.
@coversDefaultClass Drupal\telephone_formatter\Formatter
@group Telephone
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\telephone_formatter\Unit\FormatterTest
Expanded class hierarchy of FormatterTest
File
- tests/
src/ Unit/ FormatterTest.php, line 16
Namespace
Drupal\Tests\telephone_formatter\UnitView source
class FormatterTest extends UnitTestCase {
/**
* Formatter service.
*
* @var \Drupal\telephone_formatter\FormatterInterface
*/
protected $formatterService;
/**
* Language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->languageManager = $this
->createMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
$this->formatterService = new Formatter($this->languageManager);
}
/**
* Test formatter service.
*
* ::covers format.
*/
public function testFormatterService() {
$test_country = 'NO';
$test_value = '98765432';
$this
->assertEquals('987 65 432', $this->formatterService
->format($test_value, PhoneNumberFormat::NATIONAL, $test_country));
$this
->assertEquals('+47 987 65 432', $this->formatterService
->format($test_value, PhoneNumberFormat::INTERNATIONAL, $test_country));
$this
->assertEquals('+4798765432', $this->formatterService
->format($test_value, PhoneNumberFormat::E164, $test_country));
$this
->assertEquals('tel:+47-987-65-432', $this->formatterService
->format($test_value, PhoneNumberFormat::RFC3966, $test_country));
}
/**
* Valid national number but missing region code.
*
* ::covers format.
*
* @expectedException \libphonenumber\NumberParseException
*/
public function testUnparsableNumber() {
$this->formatterService
->format('98765432', PhoneNumberFormat::NATIONAL);
}
/**
* Number was successfully parsed but invalid.
*
* ::covers format.
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Number is invalid.
*/
public function testInvalidNumber() {
$this->formatterService
->format('987654320', PhoneNumberFormat::NATIONAL, 'NO');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FormatterTest:: |
protected | property | Formatter service. | |
FormatterTest:: |
protected | property | Language manager. | |
FormatterTest:: |
public | function |
Overrides UnitTestCase:: |
|
FormatterTest:: |
public | function | Test formatter service. | |
FormatterTest:: |
public | function | Number was successfully parsed but invalid. | |
FormatterTest:: |
public | function | Valid national number but missing region code. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |