context example

public function testRenderedOnceUnserializableContext()
    {
        $twig = new Environment(new ArrayLoader([
            'text' => 'Text',
        ]));
        $renderer = new BodyRenderer($twig);
        $email = (new TemplatedEmail())
            ->to('fabien@symfony.com')
            ->from('helene@symfony.com')
        ;
        $email->textTemplate('text');
        $email->context([
            'foo' => static fn () => 'bar',
        ]);

        $renderer->render($email);
        $this->assertEquals('Text', $email->getTextBody());
    }

    private function prepareEmail(?string $text, ?string $html, array $context = [], HtmlToTextConverterInterface $converter = null): TemplatedEmail
    {
        $twig = new Environment(new ArrayLoader([
            'text' => $text,
            
#[Groups(['base'])] abstract class AbstractBenchCase
{
    protected IdsCollection $ids;

    protected SalesChannelContext $context;

    public function setup(): void
    {
        $this->ids = clone Fixtures::getIds();

        $this->context = clone Fixtures::context();

        $this->getContainer()->get(Connection::class)->setNestTransactionsWithSavepoints(true);
        $this->getContainer()->get(Connection::class)->beginTransaction();
    }

    public function tearDown(): void
    {
        $this->getContainer()->get(Connection::class)->rollBack();
    }

    public static function getContainer(): ContainerInterface
    {
/** * @internal */
class ProductDetailRouteBench extends AbstractBenchCase
{
    private const SUBJECT_CUSTOMER = 'customer-0';
    private const PRODUCT_KEY = 'product-10';

    public function setupWithLogin(): void
    {
        $this->ids = clone Fixtures::getIds();
        $this->context = Fixtures::context([
            SalesChannelContextService::CUSTOMER_ID => $this->ids->get(self::SUBJECT_CUSTOMER),
        ]);
        if (!$this->context->getCustomerId()) {
            throw new \Exception('Customer not logged in for bench tests which require it!');
        }

        $this->getContainer()->get(Connection::class)->beginTransaction();
    }

    #[Bench\BeforeMethods(['setup'])]     #[Bench\Groups(['custom-pricing'])]
if ($key !== null) {
            if (count($key) > 64) {
                throw new SodiumException('Invalid key size');
            }
            $klen = count($key);
        }

        if ($outlen > 64) {
            throw new SodiumException('Invalid output size');
        }

        $ctx = self::context();

        $p = new SplFixedArray(64);
        // Zero our param buffer...         for ($i = 64; --$i;) {
            $p[$i] = 0;
        }

        $p[0] = $outlen; // digest_length         $p[1] = $klen;   // key_length         $p[2] = 1;       // fanout         $p[3] = 1;       // depth
if ($key !== null) {
            if (count($key) > 64) {
                throw new SodiumException('Invalid key size');
            }
            $klen = count($key);
        }

        if ($outlen > 64) {
            throw new SodiumException('Invalid output size');
        }

        $ctx = self::context();

        $p = new SplFixedArray(64);
        // Zero our param buffer...         for ($i = 64; --$i;) {
            $p[$i] = 0;
        }

        $p[0] = $outlen; // digest_length         $p[1] = $klen;   // key_length         $p[2] = 1;       // fanout         $p[3] = 1;       // depth
class ProductListingRouteBench extends AbstractBenchCase
{
    use BasicTestDataBehaviour;
    use SalesChannelApiTestBehaviour;

    private const SUBJECT_CUSTOMER = 'customer-0';
    private const CATEGORY_KEY = 'level-2.1';

    public function setupWithLogin(): void
    {
        $this->ids = clone Fixtures::getIds();
        $this->context = Fixtures::context([
            SalesChannelContextService::CUSTOMER_ID => $this->ids->get(self::SUBJECT_CUSTOMER),
        ]);
        if (!$this->context->getCustomer() instanceof CustomerEntity) {
            throw new \Exception('Customer not logged in for bench tests which require it!');
        }

        $this->getContainer()->get(Connection::class)->beginTransaction();
    }

    #[Bench\Groups(['custom-pricing'])]     #[Bench\Assert('mean(variant.time.avg) < 35ms')]

class CartOrderRouteBench extends AbstractBenchCase
{
    private const SUBJECT_CUSTOMER = 'customer-0';
    private const CART_ITEMS_COUNT = 10;

    private Cart $cart;

    public function setupWithLogin(): void
    {
        $this->ids = clone Fixtures::getIds();
        $this->context = Fixtures::context([
            SalesChannelContextService::CUSTOMER_ID => $this->ids->get(self::SUBJECT_CUSTOMER),
        ]);
        if (!$this->context->getCustomerId()) {
            throw new \Exception('Customer not logged in for bench tests which require it!');
        }

        $this->getContainer()->get(Connection::class)->beginTransaction();

        $baseProduct = [
            'name' => 'Test product',
            'stock' => 10,
            
use Symfony\Bridge\Twig\Mime\NotificationEmail;

class NotificationEmailTest extends TestCase
{
    public function test()
    {
        $email = (new NotificationEmail())
            ->markdown('Foo')
            ->exception(new \Exception())
            ->importance(NotificationEmail::IMPORTANCE_HIGH)
            ->action('Bar', 'http://example.com/')
            ->context(['a' => 'b'])
        ;

        $this->assertEquals([
            'importance' => NotificationEmail::IMPORTANCE_HIGH,
            'content' => 'Foo',
            'exception' => true,
            'action_text' => 'Bar',
            'action_url' => 'http://example.com/',
            'markdown' => true,
            'raw' => false,
            'a' => 'b',
            
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
use Symfony\Component\Serializer\Normalizer\MimeMessageNormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
use Symfony\Component\Serializer\Serializer;

class TemplatedEmailTest extends TestCase
{
    public function test()
    {
        $email = new TemplatedEmail();
        $email->context($context = ['product' => 'Symfony']);
        $this->assertEquals($context$email->getContext());

        $email->textTemplate($template = 'text');
        $this->assertEquals($template$email->getTextTemplate());

        $email->htmlTemplate($template = 'html');
        $this->assertEquals($template$email->getHtmlTemplate());
    }

    public function testSerialize()
    {
        
Home | Imprint | This part of the site doesn't use cookies.