function OptimizedPhpArrayDumperTest::testGetServiceDefinitionForObjectServiceId

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php \Drupal\Tests\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumperTest::testGetServiceDefinitionForObjectServiceId()

Tests that the correct RuntimeException is thrown for dumping an object.

@covers ::dumpValue
@group legacy

File

core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php, line 617

Class

OptimizedPhpArrayDumperTest
@coversDefaultClass \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper[[api-linebreak]] @group DependencyInjection

Namespace

Drupal\Tests\Component\DependencyInjection\Dumper

Code

public function testGetServiceDefinitionForObjectServiceId() : void {
  $service = new \stdClass();
  $service->_serviceId = 'foo';
  $services['foo'] = new Definition('\\stdClass');
  $services['bar'] = new Definition('\\stdClass');
  $services['bar']->addArgument($service);
  foreach ($services as $s) {
    $s->setPublic(TRUE);
  }
  $this->containerBuilder
    ->getDefinitions()
    ->willReturn($services);
  $this->containerBuilder
    ->getDefinition('foo')
    ->willReturn($services['foo']);
  $this->containerBuilder
    ->getDefinition('bar')
    ->willReturn($services['bar']);
  $this->expectDeprecation('_serviceId is deprecated in drupal:9.5.0 and is removed from drupal:11.0.0. Use \\Drupal\\Core\\DrupalKernelInterface::getServiceIdMapping() instead. See https://www.drupal.org/node/3292540');
  $a = $this->dumper
    ->getArray();
  $this->assertEquals(static::serializeDefinition([
    'class' => '\\stdClass',
    // Legacy code takes care of converting _serviceId into this.
'arguments' => static::getCollection([
      static::getServiceCall('foo'),
    ]),
    'arguments_count' => 1,
  ]), $a['services']['bar']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.