setPrefix example


        $loader = $this->createMock(LoaderInterface::class);
        $twig = new Environment($loader[
            'strict_variables' => true,
            'debug' => true,
            'cache' => false,
            'autoescape' => false,
        ]);
        $twig->addExtension(new TranslationExtension($this->createMock(TranslatorInterface::class)));

        $extractor = new TwigExtractor($twig);
        $extractor->setPrefix('prefix');
        $catalogue = new MessageCatalogue('en');

        $m = new \ReflectionMethod($extractor, 'extractTemplate');
        $m->invoke($extractor$template$catalogue);

        if (0 === \count($messages)) {
            $this->assertSame($catalogue->all()$messages);
        }

        foreach ($messages as $key => $domain) {
            $this->assertTrue($catalogue->has($key$domain));
            

class YamlDiscoveryTest extends TestCase {

  /** * {@inheritdoc} */
  protected function setUp(): void {
    // Ensure that FileCacheFactory has a prefix.     FileCacheFactory::setPrefix('prefix');
  }

  /** * Tests if filename is output for a broken YAML file. */
  public function testFilenameForBrokenYml() {
    vfsStreamWrapper::register();
    $root = new vfsStreamDirectory('modules');
    vfsStreamWrapper::setRoot($root);
    $url = vfsStream::url('modules');

    
    $configuration = Settings::get('file_cache');

    // Provide a default configuration, if not set.     if (!isset($configuration['default'])) {
      // @todo Use extension_loaded('apcu') for non-testbot       // https://www.drupal.org/node/2447753.       if (function_exists('apcu_fetch')) {
        $configuration['default']['cache_backend_class'] = '\Drupal\Component\FileCache\ApcuFileCacheBackend';
      }
    }
    FileCacheFactory::setConfiguration($configuration);
    FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root));

    $this->bootstrapContainer = new $this->bootstrapContainerClass(Settings::get('bootstrap_container_definition', $this->defaultBootstrapContainerDefinition));

    // Initialize the container.     $this->initializeContainer();

    // Add the APCu prefix to use to cache found/not-found classes.     if (Settings::get('class_loader_auto_detect', TRUE) && method_exists($this->classLoader, 'setApcuPrefix')) {
      // Vary the APCu key by which modules are installed to allow       // class_exists() checks to determine functionality.       $id = 'class_loader:' . crc32(implode(':', array_keys($this->container->getParameter('container.modules'))));
      

  public function testAutoloadBadAnnotations($annotation) {
    // Set up a class file in vfsStream.     vfsStreamWrapper::register();
    $root = new vfsStreamDirectory('root');
    vfsStreamWrapper::setRoot($root);

    FileCacheFactory::setPrefix(__CLASS__);

    // Make a directory for discovery.     $url = vfsStream::url('root');
    mkdir($url . '/DrupalTest');

    // Create a class docblock with our annotation.     $php_file = "<?php\nnamespace DrupalTest;\n/**\n";
    $php_file .= " * @$annotation\n";
    $php_file .= " */\nclass TestClass {}";
    file_put_contents($url . '/DrupalTest/TestClass.php', $php_file);

    
if (array_key_exists('metadata', $params)) {
            $this->showFieldMetaData($tableName);

            return;
        }

        $this->showDataOfTable($tableName$limitRows$limitFieldValue);
    }

    private function removeDBPrefix(): void
    {
        $this->db->setPrefix('');
    }

    private function restoreDBPrefix(): void
    {
        $this->db->setPrefix($this->DBPrefix);
    }

    private function showDataOfTable(string $tableName, int $limitRows, int $limitFieldValue)
    {
        CLI::write("Data of Table \"{$tableName}\":", 'black', 'yellow');
        CLI::newLine();

        

class AnnotatedClassDiscoveryTest extends TestCase {

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    // Ensure the file cache is disabled.     FileCacheFactory::setConfiguration([FileCacheFactory::DISABLE_CACHE => TRUE]);
    // Ensure that FileCacheFactory has a prefix.     FileCacheFactory::setPrefix('prefix');
  }

  /** * @covers ::__construct * @covers ::getPluginNamespaces */
  public function testGetPluginNamespaces() {
    $discovery = new AnnotatedClassDiscovery(['com/example' => [__DIR__]]);

    $reflection = new \ReflectionMethod($discovery, 'getPluginNamespaces');
    $result = $reflection->invoke($discovery);
    
$configuration = Settings::get('file_cache');

    // Provide a default configuration, if not set.     if (!isset($configuration['default'])) {
      // @todo Use extension_loaded('apcu') for non-testbot       // https://www.drupal.org/node/2447753.       if (function_exists('apcu_fetch')) {
        $configuration['default']['cache_backend_class'] = ApcuFileCacheBackend::class;
      }
    }
    FileCacheFactory::setConfiguration($configuration);
    FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root));
  }

  /** * Returns Extension objects for $modules to enable. * * @param string[] $modules * The list of modules to enable. * * @return \Drupal\Core\Extension\Extension[] * Extension objects for $modules, keyed by module name. * * @throws \PHPUnit\Framework\Exception * If a module is not available. * * @see \Drupal\Tests\KernelTestBase::enableModules() * @see \Drupal\Core\Extension\ModuleHandler::add() */
public function addExtractor(string $format, ExtractorInterface $extractor)
    {
        $this->extractors[$format] = $extractor;
    }

    /** * @return void */
    public function setPrefix(string $prefix)
    {
        foreach ($this->extractors as $extractor) {
            $extractor->setPrefix($prefix);
        }
    }

    /** * @return void */
    public function extract(string|iterable $directory, MessageCatalogue $catalogue)
    {
        foreach ($this->extractors as $extractor) {
            $extractor->extract($directory$catalogue);
        }
    }
class AnnotatedClassDiscoveryCachedTest extends TestCase {

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    // Ensure FileCacheFactory::DISABLE_CACHE is *not* set, since we're testing     // integration with the file cache.     FileCacheFactory::setConfiguration([]);
    // Ensure that FileCacheFactory has a prefix.     FileCacheFactory::setPrefix('prefix');
  }

  /** * Tests that getDefinitions() retrieves the file cache correctly. * * @covers ::getDefinitions */
  public function testGetDefinitions() {
    // Path to the classes which we'll discover and parse annotation.     $discovery_path = __DIR__ . '/Fixtures';
    // File path that should be discovered within that directory.

class YamlFileLoaderTest extends UnitTestCase {

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    FileCacheFactory::setPrefix('example');
  }

  public function testParseDefinitionsWithProvider() {
    $yml = <<<YAML services: example_service_1: class: \Drupal\Core\ExampleClass example_service_2: '@example_service_1' example_private_service: class: \Drupal\Core\ExampleClass public: false Drupal\Core\ExampleClass: ~
// Empty prefix means query the main database -- no need to attach anything.     $prefix = $this->connectionOptions['prefix'] ?? '';
    if ($prefix !== '') {
      $this->attachDatabase($prefix);
      // Add a ., so queries become prefix.table, which is proper syntax for       // querying an attached database.       $prefix .= '.';
    }

    // Regenerate the prefix.     $this->setPrefix($prefix);
  }

  /** * {@inheritdoc} */
  public static function open(array &$connection_options = []) {
    // Allow PDO options to be overridden.     $connection_options += [
      'pdo' => [],
    ];
    $connection_options['pdo'] += [
      

  public function __construct(object $connection, array $connection_options) {
    assert(count($this->identifierQuotes) === 2 && Inspector::assertAllStrings($this->identifierQuotes), '\Drupal\Core\Database\Connection::$identifierQuotes must contain 2 string values');

    // Manage the table prefix.     $connection_options['prefix'] = $connection_options['prefix'] ?? '';
    $this->setPrefix($connection_options['prefix']);

    // Work out the database driver namespace if none is provided. This normally     // written to setting.php by installer or set by     // \Drupal\Core\Database\Database::parseConnectionInfo().     if (empty($connection_options['namespace'])) {
      $connection_options['namespace'] = (new \ReflectionObject($this))->getNamespaceName();
    }

    $this->connection = $connection;
    $this->connectionOptions = $connection_options;
  }

  

class YamlDirectoryDiscoveryTest extends TestCase {

  /** * {@inheritdoc} */
  protected function setUp(): void {
    // Ensure that FileCacheFactory has a prefix.     FileCacheFactory::setPrefix('prefix');
  }

  /** * Tests YAML directory discovery. * * @covers ::findAll */
  public function testDiscovery() {
    vfsStream::setup('modules', NULL, [
      'test_1' => [
        'subdir1' => [
          
class PhpExtractorTest extends TestCase
{
    /** * @dataProvider resourcesProvider * * @param array|string $resource */
    public function testExtraction($resource)
    {
        // Arrange         $extractor = new PhpExtractor();
        $extractor->setPrefix('prefix');
        $catalogue = new MessageCatalogue('en');

        // Act         $extractor->extract($resource$catalogue);

        $expectedHeredoc = <<<EOF heredoc key with whitespace and escaped \$\n sequences EOF;
        $expectedNowdoc = <<<'EOF' nowdoc key with whitespace and nonescaped \$\n sequences EOF;
        


    /** * @param array<string, mixed> $data */
    private function hydrateProducer(array $data): ProducerStruct
    {
        $producer = new ProducerStruct();

        $producer->setId($data['id']);
        $producer->setName($data['name']);
        $producer->setPrefix($data['prefix']);
        $producer->setWebsite($data['website']);
        $producer->setIconPath($data['iconPath']);

        if (!empty($data['description'])) {
            $producer->setDescription($data['description']);
        }

        return $producer;
    }

    /** * @return PictureStruct[] */
Home | Imprint | This part of the site doesn't use cookies.