class ChainCountryResolverTest in Commerce Core 8.2
@coversDefaultClass Drupal\commerce\Resolver\ChainCountryResolver @group commerce
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\commerce\Unit\Resolver\ChainCountryResolverTest
Expanded class hierarchy of ChainCountryResolverTest
File
- tests/
src/ Unit/ Resolver/ ChainCountryResolverTest.php, line 13
Namespace
Drupal\Tests\commerce\Unit\ResolverView source
class ChainCountryResolverTest extends UnitTestCase {
/**
* The chain country resolver.
*
* @var \Drupal\commerce\Resolver\ChainCountryResolver
*/
protected $chainCountryResolver;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->chainCountryResolver = new ChainCountryResolver();
}
/**
* Tests the resolver and priority.
*
* ::covers addResolver
* ::covers getResolvers
* ::covers resolve.
*/
public function testResolver() {
$container = new ContainerBuilder();
$mock_builder = $this
->getMockBuilder('Drupal\\commerce\\Resolver\\CountryResolverInterface')
->disableOriginalConstructor();
$first_resolver = $mock_builder
->getMock();
$first_resolver
->expects($this
->once())
->method('resolve');
$container
->set('commerce.first_resolver', $first_resolver);
$second_resolver = $mock_builder
->getMock();
$second_resolver
->expects($this
->once())
->method('resolve')
->willReturn('RS');
$container
->set('commerce.second_resolver', $second_resolver);
$third_resolver = $mock_builder
->getMock();
$third_resolver
->expects($this
->never())
->method('resolve');
$container
->set('commerce.third_resolver', $third_resolver);
// Mimic how the container would add the services.
// @see \Drupal\Core\DependencyInjection\Compiler\TaggedHandlersPass::process
$resolvers = [
'commerce.first_resolver' => 900,
'commerce.second_resolver' => 400,
'commerce.third_resolver' => -100,
];
arsort($resolvers, SORT_NUMERIC);
foreach ($resolvers as $id => $priority) {
$this->chainCountryResolver
->addResolver($container
->get($id));
}
$result = $this->chainCountryResolver
->resolve();
$this
->assertEquals('RS', $result);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ChainCountryResolverTest:: |
protected | property | The chain country resolver. | |
ChainCountryResolverTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ChainCountryResolverTest:: |
public | function | Tests the resolver and priority. | |
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. |