array_rand example

            [!$isCustomerScoped$hasGlobalAccount, !$hasBoundAccount, !$requestOnSameSalesChannel$expectedEmailExistedStatus],
            // @phpstan-ignore-next-line             [!$isCustomerScoped, !$hasGlobalAccount, !$hasBoundAccount$requestOnSameSalesChannel$expectedSuccessStatus],
        ];
    }

    public function testRegistrationWithAllowedAccountType(): void
    {
        /** @var string[] $accountTypes */
        $accountTypes = $this->getContainer()->getParameter('customer.account_types');
        static::assertIsArray($accountTypes);
        $accountType = $accountTypes[array_rand($accountTypes)];

        $additionalData = [
            'accountType' => $accountType,
            'billingAddress' => [
                'company' => 'Test Company',
                'department' => 'Test Department',
            ],
            'vatIds' => [
                'DE123456789',
            ],
        ];
        


  /** * {@inheritdoc} */
  public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
    $allowed_options = options_allowed_values($field_definition->getFieldStorageDefinition());
    if (empty($allowed_options)) {
      $values['value'] = NULL;
      return $values;
    }
    $values['value'] = array_rand($allowed_options);
    return $values;
  }

  /** * {@inheritdoc} */
  public function isEmpty() {
    return empty($this->value) && (string) $this->value !== '0';
  }

  /** * {@inheritdoc} */
$console->progressAdvance($count);
        }
        $console->progressFinish();
    }

    /** * @return array<string, mixed> */
    private function getRandomSet(): array
    {
        return $this->attributeSets[array_rand($this->attributeSets)];
    }

    /** * @return array<string, mixed> */
    private function randomCustomField(string $prefix, DemodataContext $context): array
    {
        $types = [
            CustomFieldTypes::INT,
            CustomFieldTypes::FLOAT,
            CustomFieldTypes::DATETIME,
            

    private function buildVariants(array $combinations, array $prices, TaxCollection $taxes): array
    {
        $configurator = [];

        $variants = [];
        foreach ($combinations as $options) {
            $price = $this->faker->randomFloat(2, 1, 1000);
            $tax = $taxes->get(array_rand($taxes->getIds()));
            if (!$tax instanceof TaxEntity) {
                continue;
            }
            $taxRate = 1 + ($tax->getTaxRate() / 100);

            $id = Uuid::randomHex();
            $variants[] = [
                'id' => $id,
                'productNumber' => $id,
                'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => $price, 'net' => $price / $taxRate, 'linked' => true]],
                'active' => true,
                
 else {
                if ( current_theme_supports( 'custom-header', 'random-default' ) ) {
                    $headers = $_wp_default_headers;
                }
            }
        }

        if ( empty( $headers ) ) {
            return new stdClass();
        }

        $_wp_random_header = (object) $headers[ array_rand( $headers ) ];

        $_wp_random_header->url = sprintf(
            $_wp_random_header->url,
            get_template_directory_uri(),
            get_stylesheet_directory_uri()
        );

        $_wp_random_header->thumbnail_url = sprintf(
            $_wp_random_header->thumbnail_url,
            get_template_directory_uri(),
            get_stylesheet_directory_uri()
        );
$customer = [
            'id' => $id,
            'customerNumber' => '1337',
            'salutationId' => $salutationId,
            'firstName' => 'Max',
            'lastName' => 'Mustermann',
            'email' => 'test@example.com',
            'password' => 'shopware',
            'defaultPaymentMethodId' => $this->getDefaultPaymentMethod(),
            'groupId' => TestDefaults::FALLBACK_CUSTOMER_GROUP,
            'salesChannelId' => $salesChannelIds[array_rand($salesChannelIds)],
            'defaultBillingAddressId' => $billingAddressId,
            'defaultShippingAddressId' => $shippingAddressId,
            'addresses' => [
                [
                    'id' => $shippingAddressId,
                    'customerId' => $id,
                    'countryId' => Uuid::fromBytesToHex($countries[array_rand($countries)]),
                    'salutationId' => $salutationId,
                    'firstName' => 'Max',
                    'lastName' => 'Mustermann',
                    'street' => 'Ebbinghoff 10',
                    
'doubleOptInEmailSentDate' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            'doubleOptInConfirmDate' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
        ];

        $this->writer->insert($this->customerDefinition, [$customer], WriteContext::createFromContext(Context::createDefaultContext()));
    }

    private function getSalutationId(): string
    {
        $salutationIds = $this->connection->fetchFirstColumn('SELECT id FROM salutation');

        return Uuid::fromBytesToHex($salutationIds[array_rand($salutationIds)]);
    }

    private function getDefaultPaymentMethodId(): ?string
    {
        $id = $this->connection->executeQuery(
            'SELECT `id` FROM `payment_method` WHERE `active` = 1 ORDER BY `position` ASC'
        )->fetchOne();

        if (!$id) {
            return null;
        }

        
"virtus", "voco", "volutpat", "vulpes", "vulputate", "wisi", "ymo",
      "zelus",
    ];
    // cSpell:enable     $dictionary_flipped = array_flip($dictionary);
    $greeking = '';

    if (!$capitalize) {
      $words_remaining = $min_word_count;
      while ($words_remaining > 0) {
        $sentence_length = mt_rand(3, 10);
        $words = array_rand($dictionary_flipped$sentence_length);
        $sentence = implode(' ', $words);
        $greeking .= ucfirst($sentence) . '. ';
        $words_remaining -= $sentence_length;
      }
    }
    else {
      // Use slightly different method for titles.       $words = array_rand($dictionary_flipped$min_word_count);
      $words = is_array($words) ? implode(' ', $words) : $words;
      $greeking = ucwords($words);
    }
    
 $result->getProducts());

        $diff = array_diff($ids$this->cachePromotions);
        if (empty($diff)) {
            $diff = $ids;
        }

        if ($mode === 'new') {
            $value = current($diff);
        } else {
            shuffle($diff);
            $value = $diff[array_rand($diff)];
        }

        $this->cachePromotions[] = (int) $value;

        return $value;
    }

    /** * Helper function to get access to the media repository. */
    private function getMediaRepository(): MediaRepository
    {
// When the source is populated, they are not the same any more.     $this->generateRandomData($source$source_collections);
    $this->assertNotEquals(self::toArray($source), self::toArray($target));

    // When the target is filled with random data they are also not the same.     $this->generateRandomData($target$target_collections);
    $this->assertNotEquals(self::toArray($source), self::toArray($target));

    // Set the active collection to a random one on both source and target.     if ($source_collections) {
      $collections = $source->getAllCollectionNames();
      $source = $source->createCollection($collections[array_rand($collections)]);
    }
    if ($target_collections) {
      $collections = $target->getAllCollectionNames();
      $target = $target->createCollection($collections[array_rand($collections)]);
    }

    $source_data = self::toArray($source);
    $source_name = $source->getCollectionName();

    // After copying they are the same, this asserts that items not present     // in the source get removed from the target.

  public function testDifferentCollections() {
    $source = new MemoryStorage();
    $target = new MemoryStorage();

    $this->generateRandomData($source, 's');
    $this->generateRandomData($target, 't');

    // Use random collections for source and target.     $collections = $source->getAllCollectionNames();
    $source = $source->createCollection($collections[array_rand($collections)]);
    $collections = $target->getAllCollectionNames();
    $target = $target->createCollection($collections[array_rand($collections)]);

    $comparer = new StorageComparer($source$target);
    $comparer->createChangelist();

    foreach (array_merge([StorageInterface::DEFAULT_COLLECTION]$source->getAllCollectionNames()$target->getAllCollectionNames()) as $collection) {
      $expected = [
        'create' => $source->createCollection($collection)->listAll(),
        'update' => [],
        'delete' => $target->createCollection($collection)->listAll(),
        
$entity_type = \Drupal::entityTypeManager()->getDefinition($options['target_type']);
    $options['sort'] = [
      'field' => $entity_type->getKey('id'),
      'direction' => 'DESC',
    ];
    $selection_handler = $manager->getInstance($options);

    // Select a random number of references between the last 50 referenceable     // entities created.     if ($referenceable = $selection_handler->getReferenceableEntities(NULL, 'CONTAINS', 50)) {
      $group = array_rand($referenceable);
      $values['target_id'] = array_rand($referenceable[$group]);
      return $values;
    }

    // Attempt to create a sample entity, avoiding recursion.     $entity_storage = \Drupal::entityTypeManager()->getStorage($options['target_type']);
    if ($entity_storage instanceof ContentEntityStorageInterface) {
      $bundle = static::getRandomBundle($entity_type$options);

      // Track the generated entity by reference type, target type, and bundle.       $key = $field_definition->getTargetEntityTypeId() . ':' . $options['target_type'] . ':' . $bundle;

      
if ($this->_from !== null) {
            $user = $this->_from;
        } elseif (isset($_SERVER['REMOTE_ADDR'])) {
            $user = $_SERVER['REMOTE_ADDR'];
        } else {
            $user = getmypid();
        }

        $rand = Random::getInteger(0, PHP_INT_MAX);

        if ($this->_recipients !== array()) {
            $recipient = array_rand($this->_recipients);
        } else {
            $recipient = 'unknown';
        }

        $hostName = $this->messageIdHostName;
        if (!$hostName) {
            $hostName = (string) ($_SERVER['SERVER_NAME'] ?? '');
        }
        if (!$hostName) {
            $hostName = php_uname('n');
        }

        
$context->getConsole()->progressAdvance(\count($payload));
        }

        $context->getConsole()->progressFinish();
    }

    private function getRandomTitle(): string
    {
        $titles = ['', 'Dr.', 'Dr. med.', 'Prof.', 'Prof. Dr.'];

        return $titles[array_rand($titles)];
    }

    private function getLocaleId(Context $context): string
    {
        /** @var LanguageEntity $first */
        $first = $this->languageRepository->search(new Criteria([Defaults::LANGUAGE_SYSTEM])$context)->first();

        return $first->getLocaleId();
    }
}
if ( is_wp_error( $feed ) || ! $feed->get_item_quantity() )
            continue;

        $items = $feed->get_items(0, 5);

        // Pick a random, non-installed plugin.         while ( true ) {
            // Abort this foreach loop iteration if there's no plugins left of this type.             if ( 0 === count($items) )
                continue 2;

            $item_key = array_rand($items);
            $item = $items[$item_key];

            list($link$frag) = explode( '#', $item->get_link() );

            $link = esc_url($link);
            if ( preg_match( '|/([^/]+?)/?$|', $link$matches ) )
                $slug = $matches[1];
            else {
                unset( $items[$item_key] );
                continue;
            }

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