getGenerator example

// Ensure that the test is not marked as risky because of no assertions. In     // PHPUnit 6 tests that only make assertions using $this->assertSession()     // can be marked as risky.     $this->addToAssertionCount(1);
  }

  /** * {@inheritdoc} */
  public function __get(string $name) {
    if ($name === 'randomGenerator') {
      return Random::getGenerator();
    }
  }

  /** * Sets up the root application path. */
  protected function setUpAppRoot(): void {
    if ($this->root === NULL) {
      $this->root = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);
    }
  }

  
'p7' => '0',
        'p8' => '0',
        'p9' => '0',
        'updated' => '0',
        'language' => 'und',
        'i18n_tsid' => '0',
        'skip_translation' => TRUE,
      ],
    ];

    // Add long link title attributes to source data.     $title = Random::getGenerator()->string('500');
    $tests[0]['source_data']['menu_links'][0]['options']['attributes']['title'] = $title;

    // Build the expected results.     $expected = $tests[0]['source_data']['menu_links'];

    // Add long link title attributes to expected results.     $expected[0]['description'] = Unicode::truncate($title, 255);

    // Don't expect D6 menu link to a custom menu, provided by menu module.     unset($expected[5]);

    
$this->generators = $generators;
    }

    /** * @phpstan-param Api $type * @phpstan-param ApiType $apiType * * @return OpenApiSpec */
    public function generate(string $format = 'openapi-3', string $type = self::API, string $apiType = self::TYPE_JSON_API, ?string $bundleName = null): array
    {
        return $this->getGenerator($format$type)->generate($this->getDefinitions($type)$type$apiType$bundleName);
    }

    /** * @phpstan-param Api $type * * @return ApiSchema */
    public function getSchema(string $format = 'openapi-3', string $type = self::API): array
    {
        return $this->getGenerator($format$type)->getSchema($this->getDefinitions($type));
    }

    
public function randomObject($size = 4) {
    return Random::object($size);
  }

  /** * Gets the random generator for the utility methods. * * @return \Drupal\Component\Utility\Random * The random generator. */
  protected function getRandomGenerator() {
    return Random::getGenerator();
  }

}
$this->assertInstanceOf(UrlMatcher::class$this->router->getMatcher());
    }

    public function testGeneratorIsCreatedIfCacheIsNotConfigured()
    {
        $this->router->setOption('cache_dir', null);

        $this->loader->expects($this->once())
            ->method('load')->with('routing.yml', null)
            ->willReturn(new RouteCollection());

        $this->assertInstanceOf(CompiledUrlGenerator::class$this->router->getGenerator());
    }

    public function testGeneratorIsCreatedIfCacheIsNotConfiguredNotCompiled()
    {
        $this->router->setOption('cache_dir', null);
        $this->router->setOption('generator_class', UrlGenerator::class);

        $this->loader->expects($this->once())
            ->method('load')->with('routing.yml', null)
            ->willReturn(new RouteCollection());

        
")" .
                         $this->renderStatementBlock($node$node->getBody());
                unset($this->renderOpts->forceSingleLine);
            break;
            case "FunctionDeclaration":
            case "FunctionExpression":
                $id = $node->getId();
                if ($node->getAsync()) {
                    $code .= "async ";
                }
                $code .= "function";
                if ($node->getGenerator()) {
                    $code .= $this->renderOpts->sao .
                             "*";
                } elseif ($id) {
                    $code .= " ";
                }
                if ($id) {
                    if ($node->getGenerator()) {
                        $code .= $this->renderOpts->sao;
                    }
                    $code .= $this->renderNode($id);
                }
                
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

class UrlGeneratorTest extends TestCase
{
    use ExpectDeprecationTrait;

    public function testAbsoluteUrlWithPort80()
    {
        $routes = $this->getRoutes('test', new Route('/testing'));
        $url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);

        $this->assertEquals('http://localhost/app.php/testing', $url);
    }

    public function testAbsoluteSecureUrlWithPort443()
    {
        $routes = $this->getRoutes('test', new Route('/testing'));
        $url = $this->getGenerator($routes['scheme' => 'https'])->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);

        $this->assertEquals('https://localhost/app.php/testing', $url);
    }

    
/** * @return void */
    public function setContext(RequestContext $context)
    {
        $this->context = $context;

        if (null !== $this->matcher) {
            $this->getMatcher()->setContext($context);
        }
        if (null !== $this->generator) {
            $this->getGenerator()->setContext($context);
        }
    }

    public function getContext(): RequestContext
    {
        return $this->context;
    }

    /** * Sets the ConfigCache factory to use. * * @return void */


        $tester->execute(['--jwt-passphrase' => false]);
        static::assertSame(Command::FAILURE, $tester->getStatusCode());
        static::assertStringContainsString('Passphrase is invalid', $tester->getDisplay());
    }

    public function testUseEnv(): void
    {
        $tester = new CommandTester(new SystemGenerateJwtSecretCommand(
            __DIR__,
            $this->getGenerator()
        ));

        $tester->execute(['--use-env' => true]);
        static::assertSame(Command::SUCCESS, $tester->getStatusCode());
        static::assertStringContainsString('JWT_PUBLIC_KEY=Mg==', $tester->getDisplay());
    }

    public function testPrivateWriteInvalidPath(): void
    {
        $tester = new CommandTester(new SystemGenerateJwtSecretCommand(
            __DIR__,
            
public static function randomHex(): string
    {
        return bin2hex(self::randomBytes());
    }

    /** * same as Ramsey\Uuid\UuidFactory->uuidFromBytesAndVersion without using a transfer object */
    public static function randomBytes(): string
    {
        if (self::$generator === null) {
            self::$generator = new UnixTimeGenerator((new RandomGeneratorFactory())->getGenerator());
        }
        $bytes = self::$generator->generate();

        /** @var array<int> $unpackedTime */
        $unpackedTime = unpack('n*', substr($bytes, 6, 2));
        $timeHi = (int) $unpackedTime[1];
        $timeHiAndVersion = pack('n*', BinaryUtils::applyVersion($timeHi, 7));

        /** @var array<int> $unpackedClockSeq */
        $unpackedClockSeq = unpack('n*', substr($bytes, 8, 2));
        $clockSeqHi = (int) $unpackedClockSeq[1];
        
$this->root = static::getDrupalRoot();
    $this->initFileCache();
    $this->bootEnvironment();
    $this->bootKernel();
  }

  /** * {@inheritdoc} */
  public function __get(string $name) {
    if ($name === 'randomGenerator') {
      return Random::getGenerator();
    }
  }

  /** * Bootstraps a basic test environment. * * Should not be called by tests. Only visible for DrupalKernel integration * tests. * * @see \Drupal\KernelTests\Core\DrupalKernel\DrupalKernelTest * @internal */
/** * @return void */
    public function setContext(RequestContext $context)
    {
        $this->context = $context;

        if (isset($this->matcher)) {
            $this->getMatcher()->setContext($context);
        }
        if (isset($this->generator)) {
            $this->getGenerator()->setContext($context);
        }
    }

    public function getContext(): RequestContext
    {
        return $this->context;
    }

    /** * Sets the ConfigCache factory to use. * * @return void */

  public static function string(int $length = 8): string {
    if ($length < 4) {
      return static::getGenerator()->string($length, TRUE, [static::class, 'stringValidate']);
    }

    // To prevent the introduction of random test failures, ensure that the     // returned string contains a character that needs to be escaped in HTML by     // injecting an ampersand into it.     $replacement_pos = floor($length / 2);
    // Remove 2 from the length to account for the ampersand and greater than     // characters.     $string = static::getGenerator()->string($length - 2, TRUE, [static::class, 'stringValidate']);
    return substr_replace($string, '>&', $replacement_pos, 0);
  }

  
// Ensure that FileCacheFactory has a prefix.     FileCacheFactory::setPrefix('prefix');

    $this->root = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);
  }

  /** * {@inheritdoc} */
  public function __get(string $name) {
    if ($name === 'randomGenerator') {
      return Random::getGenerator();
    }
  }

  /** * Returns a stub config factory that behaves according to the passed array. * * Use this to generate a config factory that will return the desired values * for the given config names. * * @param array $configs * An associative array of configuration settings whose keys are * configuration object names and whose values are key => value arrays for * the configuration object in question. Defaults to an empty array. * * @return \PHPUnit\Framework\MockObject\MockBuilder * A MockBuilder object for the ConfigFactory with the desired return * values. */
/** * @return string[] A list of classes to preload on PHP 7.4+ */
    public function warmUp(string $cacheDir): array
    {
        $currentDir = $this->getOption('cache_dir');

        // force cache generation         $this->setOption('cache_dir', $cacheDir);
        $this->getMatcher();
        $this->getGenerator();

        $this->setOption('cache_dir', $currentDir);

        return [
            $this->getOption('generator_class'),
            $this->getOption('matcher_class'),
        ];
    }

    /** * Replaces placeholders with service container parameter values in: * - the route defaults, * - the route requirements, * - the route path, * - the route host, * - the route schemes, * - the route methods. */
Home | Imprint | This part of the site doesn't use cookies.