You are here

public function StockServiceManagerTest::testServices in Commerce Stock 8

Test the stock service manager.

::covers addService ::covers listServices ::covers listServiceIds.

File

tests/src/Kernel/StockServiceManagerTest.php, line 38

Class

StockServiceManagerTest
@coversDefaultClass \Drupal\commerce_stock\StockServiceManager @group commerce_stock

Namespace

Drupal\Tests\commerce_stock\Kernel

Code

public function testServices() {
  $mock_builder = $this
    ->getMockBuilder('Drupal\\commerce_stock\\StockServiceInterface')
    ->disableOriginalConstructor();
  $first_service = $mock_builder
    ->getMock();
  $first_service
    ->expects($this
    ->any())
    ->method('getName')
    ->willReturn('Stock service 1');
  $first_service
    ->expects($this
    ->any())
    ->method('getId')
    ->willReturn('stock_service_1');
  $second_service = $mock_builder
    ->getMock();
  $second_service
    ->expects($this
    ->any())
    ->method('getName')
    ->willReturn('Stock service 2');
  $second_service
    ->expects($this
    ->any())
    ->method('getId')
    ->willReturn('stock_service_2');
  $this->stockServiceManager
    ->addService($first_service);
  $this->stockServiceManager
    ->addService($second_service);
  $expectedServices = [
    'stock_service_1' => $first_service,
    'stock_service_2' => $second_service,
  ];
  $services = $this->stockServiceManager
    ->listServices();
  $this
    ->assertEquals($expectedServices, $services, 'The manager has the expected services');
  $expectedServiceIds = [
    'stock_service_1' => 'Stock service 1',
    'stock_service_2' => 'Stock service 2',
  ];
  $this
    ->assertEquals($expectedServiceIds, $this->stockServiceManager
    ->listServiceIds());
}