getCollection example

'shared' => FALSE,
      ] + $base_service_definition;

      $service_definitions[] = [
        'lazy' => TRUE,
      ] + $base_service_definition;

      // Test a basic public Reference.       $service_definitions[] = [
        'arguments' => ['foo', new Reference('bar')],
        'arguments_count' => 2,
        'arguments_expected' => static::getCollection(['foo', static::getServiceCall('bar')]),
      ] + $base_service_definition;

      // Test a public reference that should not throw an Exception.       $reference = new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE);
      $service_definitions[] = [
        'arguments' => [$reference],
        'arguments_count' => 1,
        'arguments_expected' => static::getCollection([static::getServiceCall('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE)]),
      ] + $base_service_definition;

      // Test a private shared service, denoted by having a Reference.
$context = $this->getContext($orderId$event->getContext());
        $order = $this->getOrder($orderId$context);

        $this->dispatchEvent($event->getStateEventName()$order$context);
    }

    public function onAddStateEvents(BusinessEventCollectorEvent $event): void
    {
        $context = $event->getContext();

        $collection = $event->getCollection();

        $criteria = new Criteria();
        $criteria->addAssociation('stateMachine');

        $states = $this->stateRepository->search($criteria$context);

        $sides = [
            StateMachineStateChangeEvent::STATE_MACHINE_TRANSITION_SIDE_ENTER,
            StateMachineStateChangeEvent::STATE_MACHINE_TRANSITION_SIDE_LEAVE,
        ];

        
 $options);
        $this->ttl = $this->options['ttl'] ?? null;
    }

    public function close(): bool
    {
        return true;
    }

    protected function doDestroy(#[\SensitiveParameter] string $sessionId): bool     {
        $this->getCollection()->deleteOne([
            $this->options['id_field'] => $sessionId,
        ]);

        return true;
    }

    public function gc(int $maxlifetime): int|false
    {
        return $this->getCollection()->deleteMany([
            $this->options['expiry_field'] => ['$lt' => new UTCDateTime()],
        ])->getDeletedCount();
    }
if (!$definition) {
                continue;
            }
            $result->set($definition->getName()$definition);
        }

        // allows to mutate different events by plugins         $event = new BusinessEventCollectorEvent($result$context);
        $this->eventDispatcher->dispatch($event, BusinessEventCollectorEvent::NAME);

        $result = $event->getCollection();

        $result->sort(fn (BusinessEventDefinition $a, BusinessEventDefinition $b) => $a->getName() <=> $b->getName());

        return $result;
    }

    /** * @param class-string $class */
    public function define(string $class, ?string $name = null): ?BusinessEventDefinition
    {
        
'shared' => FALSE,
    ];

    $services['other.service_class_from_parameter'] = [
      'class' => $this->getParameterCall('some_parameter_class'),
    ];
    $services['late.service'] = [
      'class' => get_class($fake_service),
    ];
    $services['service.provider'] = [
      'class' => '\Drupal\Tests\Component\DependencyInjection\MockService',
      'arguments' => $this->getCollection([
        $this->getServiceCall('other.service'),
        $this->getParameterCall('some_config'),
      ]),
      'properties' => $this->getCollection(['someProperty' => 'foo']),
      'calls' => [
        [
          'setContainer',
          $this->getCollection([
            $this->getServiceCall('service_container'),
          ]),
        ],
        [

        $this->sortedRoute = new SortedShippingMethodRoute($this->decorated, $this->executor);
    }

    public function testTriggersScriptHookExecution(): void
    {
        $this->decorated
            ->expects(static::once())
            ->method('load')
            ->willReturn($this->response);

        $this->executor->method('execute')->with(static::callback(fn (ShippingMethodRouteHook $hook) => $hook->getCollection() === $this->response->getShippingMethods()
            && $hook->getSalesChannelContext() === $this->context
            && $hook->isOnlyAvailable()));

        $response = $this->sortedRoute->load(new Request(['onlyAvailable' => true])$this->context, new Criteria());
        static::assertCount(1, $response->getShippingMethods());
    }
}

    public function createTtlIndex(int $expireAfterSeconds = 0)
    {
        $this->getCollection()->createIndex(
            [ // key                 'expires_at' => 1,
            ],
            [ // options                 'expireAfterSeconds' => $expireAfterSeconds,
            ]
        );
    }

    /** * @return void * * @throws LockExpiredException when save is called on an expired lock */

        $this->sortedRoute = new SortedPaymentMethodRoute($this->decorated, $this->executor);
    }

    public function testTriggersScriptHookExecution(): void
    {
        $this->decorated
            ->expects(static::once())
            ->method('load')
            ->willReturn($this->response);

        $this->executor->method('execute')->with(static::callback(fn (PaymentMethodRouteHook $hook) => $hook->getCollection() === $this->response->getPaymentMethods()
            && $hook->getSalesChannelContext() === $this->context
            && $hook->isOnlyAvailable()));

        $response = $this->sortedRoute->load(new Request(['onlyAvailable' => true])$this->context, new Criteria());
        static::assertCount(1, $response->getPaymentMethods());
    }
}
use Shopware\Tests\Unit\Core\System\Snippet\Mock\MockSnippetFile;

/** * @internal * * @covers \Shopware\Core\System\Snippet\Files\SnippetFileCollection */
class SnippetFileCollectionTest extends TestCase
{
    public function testGet(): void
    {
        $collection = $this->getCollection();

        $result_en_GB = $collection->get('storefront.en-GB');
        $result_de_DE = $collection->get('storefront.de-DE');
        $result_NA = $collection->get('not.available');

        static::assertNotNull($result_en_GB);
        static::assertNotNull($result_de_DE);
        static::assertSame('en-GB', $result_en_GB->getIso());
        static::assertSame('de-DE', $result_de_DE->getIso());
        static::assertNull($result_NA);
    }

    
'sort' => 'nid',
      'page' => [
        'offset' => 1,
        'limit' => 1,
      ],
    ]);

    $entity_resource = $this->createEntityResource();

    // Get the response.     $resource_type = $this->container->get('jsonapi.resource_type.repository')->get('node', 'article');
    $response = $entity_resource->getCollection($resource_type$request);

    // Assertions.     $this->assertInstanceOf(CacheableResourceResponse::class$response);
    $this->assertInstanceOf(JsonApiDocumentTopLevel::class$response->getResponseData());
    $this->assertInstanceOf(Data::class$response->getResponseData()->getData());
    $data = $response->getResponseData()->getData();
    $this->assertCount(1, $data);
    $this->assertEquals($this->node2->uuid()$data->toArray()[0]->getId());
    $this->assertEqualsCanonicalizing(['node:2', 'node_list']$response->getCacheableMetadata()->getCacheTags());
  }

  
 $options);
        $this->ttl = $this->options['ttl'] ?? null;
    }

    public function close(): bool
    {
        return true;
    }

    protected function doDestroy(#[\SensitiveParameter] string $sessionId): bool     {
        $this->getCollection()->deleteOne([
            $this->options['id_field'] => $sessionId,
        ]);

        return true;
    }

    public function gc(int $maxlifetime): int|false
    {
        return $this->getCollection()->deleteMany([
            $this->options['expiry_field'] => ['$lt' => new UTCDateTime()],
        ])->getDeletedCount();
    }
Home | Imprint | This part of the site doesn't use cookies.