getMethod example

public function testInvalidate(): void
    {
        $gateway = new VarnishReverseProxyGateway(['http://localhost'], 0, $this->client);

        $this->mockHandler->append(new GuzzleResponse(200, [], ''));

        $gateway->invalidate(['tag-1', 'tag-2']);

        $request = $this->mockHandler->getLastRequest();
        static::assertNotNull($request);

        static::assertEquals('PURGE', $request->getMethod());
        static::assertEquals('http://localhost', $request->getUri()->__toString());
        static::assertEquals('tag-1 tag-2', $request->getHeader('xkey')[0]);
    }

    /** * @dataProvider providerExceptions */
    public function testInvalidateFails(\Throwable $e, string $message): void
    {
        $gateway = new VarnishReverseProxyGateway(['http://localhost'], 0, $this->client);

        
private function createUploadedFile(string $content, int $error, string $clientFileName, string $clientMediaType): UploadedFile
    {
        $filePath = tempnam($this->tmpDir, uniqid());
        file_put_contents($filePath$content);

        return new UploadedFile($filePathfilesize($filePath)$error$clientFileName$clientMediaType);
    }

    private function callCreateUploadedFile(UploadedFileInterface $uploadedFile): HttpFoundationUploadedFile
    {
        $reflection = new \ReflectionClass($this->factory);
        $createUploadedFile = $reflection->getMethod('createUploadedFile');

        return $createUploadedFile->invokeArgs($this->factory, [$uploadedFile]);
    }

    public function testCreateResponse()
    {
        $response = new Response(
            '1.0',
            [
                'X-Symfony' => ['2.8'],
                'Set-Cookie' => [
                    
$typed_data = $this->createMock('\Drupal\Core\TypedData\TypedDataManagerInterface');
    $this->fieldConfigEditForm = new FieldConfigEditForm($entity_type_bundle_info$typed_data);
  }

  /** * @covers ::hasAnyRequired * * @dataProvider providerRequired */
  public function testHasAnyRequired(array $element, bool $result) {
    $reflection = new \ReflectionClass('\Drupal\field_ui\Form\FieldConfigEditForm');
    $method = $reflection->getMethod('hasAnyRequired');
    $this->assertEquals($result$method->invoke($this->fieldConfigEditForm, $element));
  }

  /** * Provides test cases with required and optional elements. */
  public function providerRequired(): \Generator {
    yield 'required' => [
      [['#required' => TRUE]],
      TRUE,
    ];
    

  public function buildForm($form_arg, FormStateInterface &$form_state) {
    // Ensure the form ID is prepared.     $form_id = $this->getFormId($form_arg$form_state);

    $request = $this->requestStack->getCurrentRequest();

    // Inform $form_state about the request method that's building it, so that     // it can prevent persisting state changes during HTTP methods for which     // that is disallowed by HTTP: GET and HEAD.     $form_state->setRequestMethod($request->getMethod());

    // Initialize the form's user input. The user input should include only the     // input meant to be treated as part of what is submitted to the form, so     // we base it on the form's method rather than the request's method. For     // example, when someone does a GET request for     // /node/add/article?destination=foo, which is a form that expects its     // submission method to be POST, the user input during the GET request     // should be initialized to empty rather than to ['destination' => 'foo'].     $input = $form_state->getUserInput();
    if (!isset($input)) {
      $input = $form_state->isMethodType('get') ? $request->query->all() : $request->request->all();
      
namespace Symfony\Bridge\PhpUnit;

use PHPUnit\Framework\Constraint\Constraint;

$r = new \ReflectionClass(Constraint::class);
if ($r->getProperty('exporter')->isProtected()) {
    trait ConstraintTrait
    {
        use Legacy\ConstraintTraitForV7;
    }
} elseif (!$r->getMethod('evaluate')->hasReturnType()) {
    trait ConstraintTrait
    {
        use Legacy\ConstraintTraitForV8;
    }
} else {
    trait ConstraintTrait
    {
        use Legacy\ConstraintTraitForV9;
    }
}

        return $this->isOriginAllowed($request);
    }

    public function isCorsRequest(Request $request): bool
    {
        return $request->headers->has('Origin');
    }

    public function isPreflightRequest(Request $request): bool
    {
        return $request->getMethod() === 'OPTIONS' && $request->headers->has('Access-Control-Request-Method');
    }

    public function handlePreflightRequest(Request $request): Response
    {
        $response = new Response();

        $response->setStatusCode(204);

        return $this->addPreflightRequestHeaders($response$request);
    }

    
public function matchAttribute(string $key, string $regexp)
    {
        $this->attributes[$key] = $regexp;
    }

    public function matches(Request $request): bool
    {
        if ($this->schemes && !\in_array($request->getScheme()$this->schemes, true)) {
            return false;
        }

        if ($this->methods && !\in_array($request->getMethod()$this->methods, true)) {
            return false;
        }

        foreach ($this->attributes as $key => $pattern) {
            $requestAttribute = $request->attributes->get($key);
            if (!\is_string($requestAttribute)) {
                return false;
            }
            if (!preg_match('{'.$pattern.'}', $requestAttribute)) {
                return false;
            }
        }
public function __construct(string $methodName = 'loadValidatorMetadata')
    {
        $this->methodName = $methodName;
    }

    public function loadClassMetadata(ClassMetadata $metadata): bool
    {
        /** @var \ReflectionClass $reflClass */
        $reflClass = $metadata->getReflectionClass();

        if (!$reflClass->isInterface() && $reflClass->hasMethod($this->methodName)) {
            $reflMethod = $reflClass->getMethod($this->methodName);

            if ($reflMethod->isAbstract()) {
                return false;
            }

            if (!$reflMethod->isStatic()) {
                throw new MappingException(sprintf('The method "%s::%s()" should be static.', $reflClass->name, $this->methodName));
            }

            if ($reflMethod->getDeclaringClass()->name != $reflClass->name) {
                return false;
            }
public function getContext(): ?array
    {
        if (null === $request = $this->requestStack->getCurrentRequest()) {
            return null;
        }

        $controller = $request->attributes->get('_controller');

        return [
            'uri' => $request->getUri(),
            'method' => $request->getMethod(),
            'controller' => $controller ? $this->cloner->cloneVar($controller) : $controller,
            'identifier' => spl_object_hash($request),
        ];
    }
}
/** * Exercise setPrefix() and tablePrefix(). * * @dataProvider providerPrefixRoundTrip */
  public function testPrefixRoundTrip($expected$prefix_info) {
    $mock_pdo = $this->createMock('Drupal\Tests\Core\Database\Stub\StubPDO');
    $connection = new StubConnection($mock_pdo[]);

    // setPrefix() is protected, so we make it accessible with reflection.     $reflection = new \ReflectionClass('Drupal\Tests\Core\Database\Stub\StubConnection');
    $set_prefix = $reflection->getMethod('setPrefix');

    // Set the prefix data.     $set_prefix->invokeArgs($connection[$prefix_info]);
    // Check the round-trip.     foreach ($expected as $table => $prefix) {
      $this->assertEquals($prefix$connection->getPrefix());
    }
  }

  /** * Data provider for testPrefixTables(). * * @return array * Array of arrays with the following elements: * - Expected result. * - Table prefix. * - Query to be prefixed. * - Quote identifier. */
$this->translator = $translator;
        $this->translationDomain = $translationDomain;
        $this->serverParams = $serverParams ?? new ServerParams();
    }

    /** * @return void */
    public function preSubmit(FormEvent $event)
    {
        $form = $event->getForm();
        $postRequestSizeExceeded = 'POST' === $form->getConfig()->getMethod() && $this->serverParams->hasPostMaxSizeBeenExceeded();

        if ($form->isRoot() && $form->getConfig()->getOption('compound') && !$postRequestSizeExceeded) {
            $data = $event->getData();

            $csrfValue = \is_string($data[$this->fieldName] ?? null) ? $data[$this->fieldName] : null;
            $csrfToken = new CsrfToken($this->tokenId, $csrfValue);

            if (null === $csrfValue || !$this->tokenManager->isTokenValid($csrfToken)) {
                $errorMessage = $this->errorMessage;

                if (null !== $this->translator) {
                    

class DeprecatedAnnotationsTest extends TestCase
{
    /** * @DisabledFeatures("v6.6.0.0") */
    public function testDeprecatedAnnotationsCanBeConstructed(): void
    {
        $method = (new \ReflectionClass($this))->getMethod('testMethod');

        $annotations = (new AnnotationReader())->getMethodAnnotations($method);

        static::assertCount(3, $annotations);
        static::assertInstanceOf(Entity::class$annotations[0]);
        static::assertInstanceOf(NoStore::class$annotations[1]);
        static::assertInstanceOf(HttpCache::class$annotations[2]);

        // make PHPStan happy that the private method is used         $this->testMethod();
    }

    
$projectDir = $this->getProjectDir();

        $getClassesCommand = new GetClassesPerAreaCommand($projectDir);
        $definition = $getClassesCommand->getDefinition();
        $input = new ArrayInput(
            $parameters,
            $definition
        );
        $input->getOptions();
        $output = new BufferedOutput();

        $refMethod = ReflectionHelper::getMethod(GetClassesPerAreaCommand::class, 'execute');
        $refMethod->invoke($getClassesCommand$input$output);

        return $output->fetch();
    }

    private function getProjectDir(): string
    {
        $vendorDir = key(ClassLoader::getRegisteredLoaders());
        static::assertIsString($vendorDir);

        return \dirname($vendorDir);
    }
public function __construct(RequestContextAwareInterface $router)
    {
        $this->router = $router;
    }

    public function handle(Envelope $envelope, StackInterface $stack): Envelope
    {
        if (!$envelope->last(ConsumedByWorkerStamp::class) || !$contextStamp = $envelope->last(RouterContextStamp::class)) {
            $context = $this->router->getContext();
            $envelope = $envelope->with(new RouterContextStamp(
                $context->getBaseUrl(),
                $context->getMethod(),
                $context->getHost(),
                $context->getScheme(),
                $context->getHttpPort(),
                $context->getHttpsPort(),
                $context->getPathInfo(),
                $context->getQueryString()
            ));

            return $stack->next()->handle($envelope$stack);
        }

        

        }

        return $values;
    }

    /** * Gets the file field values. */
    public function getFiles(): array
    {
        if (!\in_array($this->getMethod()['POST', 'PUT', 'DELETE', 'PATCH'])) {
            return [];
        }

        $files = [];

        foreach ($this->fields->all() as $name => $field) {
            if ($field->isDisabled()) {
                continue;
            }

            if ($field instanceof Field\FileFormField) {
                
Home | Imprint | This part of the site doesn't use cookies.