getContent example

public static function fromNotification(Notification $notification, EmailRecipientInterface $recipient): self
    {
        if ('' === $recipient->getEmail()) {
            throw new InvalidArgumentException(sprintf('"%s" needs an email, it cannot be empty.', __CLASS__));
        }

        if (!class_exists(NotificationEmail::class)) {
            $email = (new Email())
                ->to($recipient->getEmail())
                ->subject($notification->getSubject())
                ->text($notification->getContent() ?: $notification->getSubject())
            ;
        } else {
            $email = (new NotificationEmail())
                ->to($recipient->getEmail())
                ->subject($notification->getSubject())
                ->content($notification->getContent() ?: $notification->getSubject())
                ->importance($notification->getImportance())
            ;

            if ($exception = $notification->getException()) {
                $email->exception($exception);
            }
public function testLoadNormal(): void
    {
        $this->browser
            ->request(
                'POST',
                '/store-api/navigation/' . $this->ids->get('category') . '/' . $this->ids->get('category'),
                [
                ]
            );

        $response = json_decode($this->browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertCount(2, $response);
        static::assertSame('Toys', $response[0]['name']);
        static::assertSame($this->ids->get('category2')$response[0]['id']);
        static::assertCount(1, $response[0]['children']);
        static::assertSame($this->ids->get('category3')$response[0]['children'][0]['id']);
        static::assertSame('Kids', $response[0]['children'][0]['name']);
    }

    public function testLoadFlat(): void
    {
        
return new JsonResponse([
                'error' => 'Session expired, please go back to database configuration.',
            ], Response::HTTP_INTERNAL_SERVER_ERROR);
        }

        $_SERVER[BlueGreenDeploymentService::ENV_NAME] = $_ENV[BlueGreenDeploymentService::ENV_NAME] = $session->get(BlueGreenDeploymentService::ENV_NAME);
        $_SERVER[MigrationStep::INSTALL_ENVIRONMENT_VARIABLE] = $_ENV[MigrationStep::INSTALL_ENVIRONMENT_VARIABLE] = true;

        try {
            $connection = $this->connectionFactory->getConnection($connectionInfo);

            $offset = json_decode((string) $request->getContent(), true, 512, \JSON_THROW_ON_ERROR)['offset'] ?? 0;
            $result = $this->migrator->migrate($offset$connection);

            return new JsonResponse($result);
        } catch (\Exception $e) {
            return new JsonResponse([
                'error' => $e->getMessage(),
            ], Response::HTTP_INTERNAL_SERVER_ERROR);
        }
    }
}
$request = new Request();

        $this->administrationController->checkCustomerEmailValid($request$this->context);
    }

    public function testCheckCustomerEmailValidWithoutException(): void
    {
        $this->createInstance();
        $request = new Request([]['email' => 'random@email.com']);

        $response = $this->administrationController->checkCustomerEmailValid($request$this->context);
        static::assertIsString($response->getContent());
        static::assertEquals(
            ['isValid' => true],
            json_decode($response->getContent(), true, 512, \JSON_THROW_ON_ERROR)
        );
    }

    public function testCheckCustomerEmailValidWithConstraintException(): void
    {
        static::expectException(ConstraintViolationException::class);

        $customer = $this->mockCustomer();

        

  protected function deserialize(RouteMatchInterface $route_match, Request $request, ResourceInterface $resource) {
    // Deserialize incoming data if available.     $received = $request->getContent();
    $unserialized = NULL;
    if (!empty($received)) {
      $method = static::getNormalizedRequestMethod($route_match);
      $format = $request->getContentTypeFormat();

      $definition = $resource->getPluginDefinition();

      // First decode the request data. We can then determine if the       // serialized data was malformed.       try {
        $unserialized = $this->serializer->decode($received$format['request_method' => $method]);
      }
$this->controller = $this->getContainer()->get(ExtensionStoreDataController::class);
    }

    public function testInstalled(): void
    {
        $this->installApp(__DIR__ . '/../_fixtures/TestApp');

        $this->getRequestHandler()->reset();
        $this->getRequestHandler()->append(new Response(200, [], '[]'));

        $response = $this->controller->getInstalledExtensions($this->createAdminStoreContext());
        $data = json_decode($response->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertNotEmpty($data);
        static::assertContains('TestApp', array_column($data, 'name'));
    }
}
$suffix = $i % 2 ? 'odd' : 'even';
      $tag = 'autocomplete_tag_test_' . $suffix . $this->randomMachineName();
      $tags[] = $tag;
      View::create(['tag' => $tag, 'id' => $this->randomMachineName()])->save();
    }

    // Make sure just ten results are returned.     $controller = ViewsUIController::create($this->container);
    $request = $this->container->get('request_stack')->getCurrentRequest();
    $request->query->set('q', 'autocomplete_tag_test');
    $result = $controller->autocompleteTag($request);
    $matches = (array) json_decode($result->getContent(), TRUE);
    $this->assertCount(10, $matches, 'Make sure the maximum amount of tag results is 10.');

    // Make sure the returned array has the proper format.     $suggestions = array_map(function D$tag) {
      return ['value' => $tag, 'label' => Html::escape($tag)];
    }$tags);
    foreach ($matches as $match) {
      $this->assertContains($match$suggestions, 'Make sure the returned array has the proper format.');
    }

    // Make sure that matching by a certain prefix works.
$client = $this->getHttpClient(__FUNCTION__, function DChunkInterface $chunk, AsyncContext $context) {
            $this->assertTrue($chunk->isFirst());
            $this->assertSame(404, $context->getStatusCode());
            $context->getResponse()->cancel();
            $context->replaceRequest('GET', 'http://localhost:8057/404');
            $context->passthru();
        });

        $response = $client->request('GET', 'http://localhost:8057/404');

        $this->expectException(ClientExceptionInterface::class);
        $response->getContent(true);
    }

    public function testRetryTransportError()
    {
        $client = $this->getHttpClient(__FUNCTION__, function DChunkInterface $chunk, AsyncContext $context) {
            try {
                if ($chunk->isFirst()) {
                    $this->assertSame(200, $context->getStatusCode());
                }
            } catch (TransportExceptionInterface $e) {
                $context->getResponse()->cancel();
                

        $this->options = $options;
    }

    /** * @return $this */
    public static function fromNotification(Notification $notification)static
    {
        $options = new self();
        $options->headings(['en' => $notification->getSubject()]);
        $options->contents(['en' => $notification->getContent()]);

        return $options;
    }

    /** * @return $this */
    public function headings(array $headings)static
    {
        $this->options['headings'] = $headings;

        
$kernel = $this->createMock(HttpKernelInterface::class);
        $kernel->expects($this->once())->method('handle')->willReturnCallback(fn (Request $request) => new Response($request->getRequestFormat()));

        $request = Request::create('/');
        $request->setRequestFormat('xml');

        $event = new ExceptionEvent($kernel$request, HttpKernelInterface::MAIN_REQUEST, new \Exception('foo'));
        $listener->onKernelException($event);

        $response = $event->getResponse();
        $this->assertEquals('xml', $response->getContent());
    }

    public function testCSPHeaderIsRemoved()
    {
        $dispatcher = new EventDispatcher();
        $kernel = $this->createMock(HttpKernelInterface::class);
        $kernel->expects($this->once())->method('handle')->willReturnCallback(fn (Request $request) => new Response($request->getRequestFormat()));

        $listener = new ErrorListener('foo', $this->createMock(LoggerInterface::class), true);

        $dispatcher->addSubscriber($listener);

        

                            'id' => $this->ids->get('p1'),
                            'type' => 'product',
                            'referencedId' => $this->ids->get('p1'),
                        ],
                    ],
                ])
            );

        static::assertSame(200, $this->browser->getResponse()->getStatusCode());

        $response = json_decode((string) $this->browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertSame('cart', $response['apiAlias']);
        static::assertSame(10, $response['price']['totalPrice']);
        static::assertCount(1, $response['lineItems']);
        static::assertSame(1, $response['lineItems'][0]['quantity']);

        $this->browser
            ->request(
                'PATCH',
                '/store-api/checkout/cart/line-item',
                [],
                [],

            $require .= sprintf('require_once __DIR__.\DIRECTORY_SEPARATOR.\'%s\';', implode('\'.\DIRECTORY_SEPARATOR.\'', $path))."\n";
        }
        $use = $require ? "\n" : '';
        foreach (array_keys($this->use) as $statement) {
            $use .= sprintf('use %s;', $statement)."\n";
        }

        $implements = [] === $this->implements ? '' : 'implements '.implode(', ', $this->implements);
        $body = '';
        foreach ($this->properties as $property) {
            $body .= ' '.$property->getContent()."\n";
        }
        foreach ($this->methods as $method) {
            $lines = explode("\n", $method->getContent());
            foreach ($lines as $line) {
                $body .= ($line ? ' '.$line : '')."\n";
            }
        }

        $content = strtr('<?php namespace NAMESPACE; REQUIREUSE /** * This class is automatically generated to help in creating a config. */ class CLASS IMPLEMENTS { BODY } ',

                        'id' => $id2,
                        'name' => 'Test stream - 2',
                    ],
                ],
            ],
        ];

        $this->getBrowser()->request('POST', '/api/_action/sync', [][][]json_encode($data, \JSON_THROW_ON_ERROR));
        $response = $this->getBrowser()->getResponse();

        $content = $response->getContent();
        static::assertIsString($content);
        static::assertSame(200, $response->getStatusCode()$content);

        $result = $this->connection
            ->executeQuery(
                'SELECT * FROM product_stream INNER JOIN product_stream_translation ON product_stream.id = product_stream_translation.product_stream_id WHERE product_stream.id = :id1 OR product_stream.id = :id2 ORDER BY `name`',
                [
                    
$correct_number = $limit;
    $num_pages = floor($count / $limit);

    // If there is no remainder from rounding, subtract 1 since we index from 0.     if (!($num_pages * $limit < $count)) {
      $num_pages--;
    }

    for ($page = 0; $page <= $num_pages; ++$page) {
      $this->drupalGet('database_test/pager_query_even/' . $limit['query' => ['page' => $page]]);
      $data = json_decode($this->getSession()->getPage()->getContent());

      if ($page == $num_pages) {
        $correct_number = $count - ($limit * $page);
      }

      $this->assertCount($correct_number$data->names, new FormattableMarkup('Correct number of records returned by pager: @number', ['@number' => $correct_number]));
    }
  }

  /** * Confirms that a pager query returns the correct results. * * Note that we have to make an HTTP request to a test page handler * because the pager depends on GET parameters. */

        $productId = $this->createProduct();

        $response = $this->request(
            'GET',
            '/detail/' . $productId . '/switch',
            $this->tokenize('frontend.detail.switch', [
                'productId' => $productId,
            ])
        );

        $responseContent = (string) $response->getContent();
        $content = (array) json_decode($responseContent);

        static::assertSame(Response::HTTP_OK, $response->getStatusCode());
        static::assertInstanceOf(JsonResponse::class$response);
        static::assertEquals($productId$content['productId']);
        static::assertStringContainsString($productId$content['url']);
    }

    public function testSwitchDoesNotCrashOnMalformedOptions(): void
    {
        $productId = $this->createProduct();

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