ChainStoreResolverTest.php in Commerce Core 8.2
File
modules/store/tests/src/Unit/Resolver/ChainStoreResolverTest.php
View source
<?php
namespace Drupal\Tests\commerce_store\Unit\Resolver;
use Drupal\commerce_store\Resolver\ChainStoreResolver;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
class ChainStoreResolverTest extends UnitTestCase {
protected $resolver;
protected function setUp() : void {
parent::setUp();
$this->resolver = new ChainStoreResolver();
}
public function testResolver() {
$container = new ContainerBuilder();
$mock_builder = $this
->getMockBuilder('Drupal\\commerce_store\\Resolver\\StoreResolverInterface')
->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('testStore');
$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);
$resolvers = [
'commerce.first_resolver' => 900,
'commerce.second_resolver' => 400,
'commerce.third_resolver' => -100,
];
arsort($resolvers, SORT_NUMERIC);
foreach ($resolvers as $id => $priority) {
$this->resolver
->addResolver($container
->get($id));
}
$result = $this->resolver
->resolve();
$this
->assertEquals('testStore', $result);
}
}