expectDeprecation example


  public function testMigrationDependenciesInConstructor(array $dependencies) {

    $configuration = ['migration_dependencies' => $dependencies];
    $plugin_id = 'test_migration';
    $migration_plugin_manager = $this->createMock('\Drupal\migrate\Plugin\MigrationPluginManagerInterface');
    $source_plugin_manager = $this->createMock('\Drupal\migrate\Plugin\MigratePluginManagerInterface');
    $process_plugin_manager = $this->createMock('\Drupal\migrate\Plugin\MigratePluginManagerInterface');
    $destination_plugin_manager = $this->createMock('\Drupal\migrate\Plugin\MigrateDestinationPluginManager');
    $id_map_plugin_manager = $this->createMock('\Drupal\migrate\Plugin\MigratePluginManagerInterface');

    $this->expectDeprecation("Invalid migration dependencies for {$plugin_id} is deprecated in drupal:10.1.0 and will cause an error in drupal:11.0.0. See https://www.drupal.org/node/3266691");
    new Migration($configuration$plugin_id[]$migration_plugin_manager$source_plugin_manager$process_plugin_manager$destination_plugin_manager$id_map_plugin_manager);
  }

  /** * Tests checking requirements for source plugins. * * @covers ::checkRequirements */
  public function testRequirementsForSourcePlugin() {
    $migration = new TestMigration();

    
$this->assertFalse($container->hasDefinition('console.command.messenger_failed_messages_retry'));
        $this->assertFalse($container->hasDefinition('console.command.messenger_failed_messages_show'));
        $this->assertFalse($container->hasDefinition('console.command.messenger_failed_messages_remove'));
        $this->assertFalse($container->hasDefinition('cache.messenger.restart_workers_signal'));
    }

    /** * @group legacy */
    public function testMessengerWithExplictResetOnMessageLegacy()
    {
        $this->expectDeprecation('Since symfony/framework-bundle 6.1: Option "reset_on_message" at "framework.messenger" is deprecated. It does nothing and will be removed in version 7.0.');

        $container = $this->createContainerFromFile('messenger_with_explict_reset_on_message_legacy');

        $this->assertTrue($container->hasDefinition('console.command.messenger_consume_messages'));
        $this->assertTrue($container->hasAlias('messenger.default_bus'));
        $this->assertTrue($container->getAlias('messenger.default_bus')->isPublic());
        $this->assertTrue($container->hasDefinition('messenger.transport.amqp.factory'));
        $this->assertTrue($container->hasDefinition('messenger.transport.redis.factory'));
        $this->assertTrue($container->hasDefinition('messenger.transport_factory'));
        $this->assertSame(TransportFactory::class$container->getDefinition('messenger.transport_factory')->getClass());
        $this->assertTrue($container->hasDefinition('messenger.listener.reset_services'));
        
$url = new Url('test_route_1');
    $url->setUrlGenerator($this->urlGenerator);
    $expected_link_markup = '<a href="/test-route-1">Test</a>';

    // Test ::generate().     $this->assertSame($expected_link_markup(string) $this->linkGenerator->generate('Test', $url));
    $generated_link = $this->linkGenerator->generate('Test', $url);
    $this->assertSame($expected_link_markup(string) $generated_link->getGeneratedLink());
    $this->assertInstanceOf('\Drupal\Core\Render\BubbleableMetadata', $generated_link);

    // Test ::generateFromLink().     $this->expectDeprecation('\Drupal\Core\Utility\LinkGeneratorInterface::generateFromLink() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use \Drupal\Core\Utility\LinkGeneratorInterface::generate() instead. See https://www.drupal.org/node/3342992');
    $link = new Link('Test', $url);
    $this->assertSame($expected_link_markup(string) $this->linkGenerator->generateFromLink($link));
    $generated_link = $this->linkGenerator->generateFromLink($link);
    $this->assertSame($expected_link_markup(string) $generated_link->getGeneratedLink());
    $this->assertInstanceOf('\Drupal\Core\Render\BubbleableMetadata', $generated_link);
  }

  /** * Tests altering the URL object using hook_link_alter(). * * @covers ::generate */
/** * The test should be kept in the group as it always expects a deprecation. * * @group legacy */
    public function testDeprecate()
    {
        $bag = new ParameterBag(['foo' => 'bar']);

        $bag->deprecate('foo', 'symfony/test', '6.3');

        $this->expectDeprecation('Since symfony/test 6.3: The parameter "foo" is deprecated.');

        $bag->get('foo');
    }

    /** * The test should be kept in the group as it always expects a deprecation. * * @group legacy */
    public function testDeprecateWithMessage()
    {
        
$string = 'Can I please have a @replacement';
    $formattable_string = new FormattableMarkup($string['@replacement' => 'kitten']);
    $this->assertEquals(strlen($string)$formattable_string->count());
  }

  /** * @covers ::__toString * @dataProvider providerTestNullPlaceholder * @group legacy */
  public function testNullPlaceholder(string $expected, string $string, array $arguments, string $expected_deprecation): void {
    $this->expectDeprecation($expected_deprecation);
    $this->assertEquals($expected(string) new FormattableMarkup($string$arguments));
  }

  /** * Data provider for FormattableMarkupTest::testNullPlaceholder(). * * @return array */
  public function providerTestNullPlaceholder() {
    return [
      ['', '@empty', ['@empty' => NULL], 'Deprecated NULL placeholder value for key (@empty) in: "@empty". This will throw a PHP error in drupal:11.0.0. See https://www.drupal.org/node/3318826'],
      [

class PgsqlDriverLegacyTest extends DriverSpecificDatabaseTestBase {

  /** * @covers Drupal\Core\Database\Driver\pgsql\Install\Tasks */
  public function testDeprecationInstallTasks() {
    $this->expectDeprecation('\Drupal\Core\Database\Driver\pgsql\Install\Tasks is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. The PostgreSQL database driver has been moved to the pgsql module. See https://www.drupal.org/node/3129492');
    $tasks = new Tasks();
    $this->assertInstanceOf(Tasks::class$tasks);
  }

  /** * @covers Drupal\Core\Database\Driver\pgsql\Connection */
  public function testDeprecationConnection() {
    $this->expectDeprecation('\Drupal\Core\Database\Driver\pgsql\Connection is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. The PostgreSQL database driver has been moved to the pgsql module. See https://www.drupal.org/node/3129492');
    $connection = new Connection($this->createMock(StubPDO::class)[]);
    $this->assertInstanceOf(Connection::class$connection);
  }
/** * @group legacy */
    public function testGetSetTokenLegacy()
    {
        $tokenStorage = new TokenStorage();
        $token = new UsernamePasswordToken(new InMemoryUser('username', 'password'), 'provider');
        $tokenStorage->setToken($token);
        $this->assertSame($token$tokenStorage->getToken());

        $this->expectDeprecation('Since symfony/security-core 6.2: Calling "Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage::setToken()" without any arguments is deprecated, pass null explicitly instead.');

        $tokenStorage->setToken();
        $this->assertNull($tokenStorage->getToken());
    }

    public function testGetSetToken()
    {
        $tokenStorage = new TokenStorage();
        $this->assertNull($tokenStorage->getToken());
        $token = new UsernamePasswordToken(new InMemoryUser('username', 'password'), 'provider');
        $tokenStorage->setToken($token);
        
$this->validator->validate('example@example', $constraint);

        $this->assertNoViolation();
    }

    /** * @group legacy */
    public function testModeLoose()
    {
        $this->expectDeprecation('Since symfony/validator 6.2: The "loose" mode is deprecated. It will be removed in 7.0 and the default mode will be changed to "html5".');

        $constraint = new Email(['mode' => Email::VALIDATION_MODE_LOOSE]);

        $this->validator->validate('example@example..com', $constraint);

        $this->assertNoViolation();
    }

    public function testUnknownModesOnValidateTriggerException()
    {
        $this->expectException(\InvalidArgumentException::class);
        
public function testSupportsDenormalizationForNonUid()
    {
        $this->assertFalse($this->normalizer->supportsDenormalization('foo', \stdClass::class));
    }

    /** * @group legacy */
    public function testSupportOurAbstractUid()
    {
        $this->expectDeprecation('Since symfony/serializer 6.1: Supporting denormalization for the "Symfony\Component\Uid\AbstractUid" type in "Symfony\Component\Serializer\Normalizer\UidNormalizer" is deprecated, use one of "Symfony\Component\Uid\AbstractUid" child class instead.');

        $this->assertTrue($this->normalizer->supportsDenormalization('1ea6ecef-eb9a-66fe-b62b-957b45f17e43', AbstractUid::class));
    }

    public function testSupportCustomAbstractUid()
    {
        $this->assertTrue($this->normalizer->supportsDenormalization('ccc', TestAbstractCustomUid::class));
    }

    /** * @dataProvider dataProvider */
$this->assertEquals([$typedRef]$container->getDefinition('def1')->getArguments());
        $this->assertEquals([new Reference('foo')]$container->getDefinition('def2')->getArguments());
        $this->assertEquals([new Reference('bar')]$container->getDefinition('def3')->getArguments());
    }

    /** * @group legacy */
    public function testScalarSetterAnnotation()
    {
        $this->expectDeprecation('Since symfony/dependency-injection 6.3: Relying on the "@required" annotation on method "Symfony\Component\DependencyInjection\Tests\Compiler\ScalarSetterAnnotation::setDefaultLocale()" is deprecated, use the "Symfony\Contracts\Service\Attribute\Required" attribute instead.');

        $container = new ContainerBuilder();

        $definition = $container->autowire('foo', ScalarSetterAnnotation::class);
        $definition->setBindings(['$defaultLocale' => 'fr']);

        (new AutowireRequiredMethodsPass())->process($container);
        (new ResolveBindingsPass())->process($container);

        $this->assertEquals([['setDefaultLocale', ['fr']]]$definition->getMethodCalls());
    }

    

class RequestStackLegacyTest extends UnitTestCase {

  /** * Tests deprecation message in our subclassed RequestStack. * * @covers ::getMainRequest */
  public function testGetMainRequestDeprecation() {
    $stack = new RequestStack();

    $this->expectDeprecation('The Drupal\Core\Http\RequestStack is deprecated in drupal:10.0.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3265357');
    $this->assertNull($stack->getMainRequest());
  }

}
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;

/** * @group legacy */
class AnnotationLoaderWithDoctrineAnnotationsTest extends AnnotationLoaderTestCase
{
    use ExpectDeprecationTrait;

    protected function setUp(): void
    {
        $this->expectDeprecation('Since symfony/validator 6.4: Passing a "Doctrine\Common\Annotations\AnnotationReader" instance as argument 1 to "Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader::__construct()" is deprecated, pass null or omit the parameter instead.');

        parent::setUp();
    }

    public function testLoadClassMetadataReturnsTrueIfSuccessful()
    {
        $this->expectDeprecation('Since symfony/serializer 6.4: Property "Symfony\Component\Serializer\Tests\Fixtures\Annotations\GroupDummy::$foo" uses Doctrine Annotations to configure serialization, which is deprecated. Use PHP attributes instead.');
        $this->expectDeprecation('Since symfony/serializer 6.4: Property "Symfony\Component\Serializer\Tests\Fixtures\Annotations\GroupDummy::$bar" uses Doctrine Annotations to configure serialization, which is deprecated. Use PHP attributes instead.');
        $this->expectDeprecation('Since symfony/serializer 6.4: Property "Symfony\Component\Serializer\Tests\Fixtures\Annotations\GroupDummy::$quux" uses Doctrine Annotations to configure serialization, which is deprecated. Use PHP attributes instead.');
        $this->expectDeprecation('Since symfony/serializer 6.4: Method "Symfony\Component\Serializer\Tests\Fixtures\Annotations\GroupDummy::setBar()" uses Doctrine Annotations to configure serialization, which is deprecated. Use PHP attributes instead.');
        $this->expectDeprecation('Since symfony/serializer 6.4: Method "Symfony\Component\Serializer\Tests\Fixtures\Annotations\GroupDummy::getBar()" uses Doctrine Annotations to configure serialization, which is deprecated. Use PHP attributes instead.');
        

  protected $defaultTheme = 'stark';

  /** * Tests the deprecation message from the old block-type page. * * @group legacy */
  public function testBlockContentTypeRedirect() {
    $this->drupalLogin($this->adminUser);
    $this->expectDeprecation('The path /admin/structure/block/block-content/types is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use /admin/structure/block-content. See https://www.drupal.org/node/3320855.');
    $this->drupalGet('/admin/structure/block/block-content/types');
    $this->assertSession()
      ->pageTextContains("You have been redirected from admin/structure/block/block-content/types. Update links, shortcuts, and bookmarks to use admin/structure/block-content.");
  }

  /** * Tests the deprecation message from the old block library page. * * @group legacy */
  public function testBlockLibraryRedirect() {
    
$container = new ContainerBuilder();
        $loader = new PhpFileLoader($containernew FileLocator(), 'dev', new ConfigBuilderGenerator(sys_get_temp_dir()));

        $loader->load($fixtures.'/config/when_env.php');
    }

    /** * @group legacy */
    public function testServiceWithServiceLocatorArgument()
    {
        $this->expectDeprecation('Since symfony/dependency-injection 6.3: Using integers as keys in a "service_locator()" argument is deprecated. The keys will default to the IDs of the original services in 7.0.');

        $fixtures = realpath(__DIR__.'/../Fixtures');
        $loader = new PhpFileLoader($container = new ContainerBuilder()new FileLocator());
        $loader->load($fixtures.'/config/services_with_service_locator_argument.php');

        $values = ['foo' => new Reference('foo_service'), 'bar' => new Reference('bar_service')];
        $this->assertEquals([new ServiceLocatorArgument($values)]$container->getDefinition('locator_dependent_service_indexed')->getArguments());

        $values = [new Reference('foo_service')new Reference('bar_service')];
        $this->assertEquals([new ServiceLocatorArgument($values)]$container->getDefinition('locator_dependent_service_not_indexed')->getArguments());

        
public function testAddMethodMappings()
    {
        $this->assertSame($this->builder, $this->builder->addMethodMappings([]));
    }

    /** * @group legacy */
    public function testEnableAnnotationMappingWithDefaultDoctrineAnnotationReader()
    {
        $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::enableAnnotationMapping()" is deprecated, use "enableAttributeMapping()" instead.');
        $this->assertSame($this->builder, $this->builder->enableAnnotationMapping());

        $this->expectDeprecation('Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::addDefaultDoctrineAnnotationReader()" is deprecated without replacement.');
        $this->assertSame($this->builder, $this->builder->addDefaultDoctrineAnnotationReader());

        $loaders = $this->builder->getLoaders();
        $this->assertCount(1, $loaders);
        $this->assertInstanceOf(AnnotationLoader::class$loaders[0]);

        $r = new \ReflectionProperty(AnnotationLoader::class, 'reader');

        
Home | Imprint | This part of the site doesn't use cookies.