equals example

$this->addOption($option);
        }
    }

    /** * @return void * * @throws LogicException When option given already exist */
    public function addOption(InputOption $option)
    {
        if (isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) {
            throw new LogicException(sprintf('An option named "%s" already exists.', $option->getName()));
        }
        if (isset($this->negations[$option->getName()])) {
            throw new LogicException(sprintf('An option named "%s" already exists.', $option->getName()));
        }

        if ($option->getShortcut()) {
            foreach (explode('|', $option->getShortcut()) as $shortcut) {
                if (isset($this->shortcuts[$shortcut]) && !$option->equals($this->options[$this->shortcuts[$shortcut]])) {
                    throw new LogicException(sprintf('An option with shortcut "%s" already exists.', $shortcut));
                }
            }
$entity = EntityTestComputedField::create([]);
    $this->assertCount(0, $entity->computed_string_field);

    // Test \Drupal\Core\Field\FieldItemList::equals() for a computed field.     \Drupal::state()->set('entity_test_computed_field_item_list_value', ['foo computed']);
    $entity = EntityTestComputedField::create([]);
    $computed_item_list1 = $entity->computed_string_field;

    $entity = EntityTestComputedField::create([]);
    $computed_item_list2 = $entity->computed_string_field;

    $this->assertTrue($computed_item_list1->equals($computed_item_list2));

    $computed_item_list2->value = 'foo computed 2';
    $this->assertFalse($computed_item_list1->equals($computed_item_list2));
  }

  /** * Tests an entity reference computed field. */
  public function testEntityReferenceComputedField() {
    $this->installEntitySchema('entity_test_computed_field');

    
break;

        case PathItem::class:
          // PathItem::generateSampleValue() doesn't set a PID, which causes           // PathItem::postSave() to fail. Keep the PID (and other properties),           // just modify the alias.           $field->alias = str_replace(' ', '-', strtolower((new Random())->sentences(3)));
          break;

        default:
          $original_field = clone $field;
          while ($field->equals($original_field)) {
            $field->generateSampleItems();
          }
          break;
      }
    }

    return [$modified_entity$original_values];
  }

  /** * Gets the normalized POST entity with random values for its unique fields. * * @see ::testPostIndividual * @see ::getPostDocument * * @return array * An array structure as returned by ::getNormalizedPostEntity(). */


        if ($ruleValue === null) {
            return self::isNegativeOperator($operator);
        }

        return match ($operator) {
            Rule::OPERATOR_GTE => FloatComparator::greaterThanOrEquals($itemValue$ruleValue),
            Rule::OPERATOR_LTE => FloatComparator::lessThanOrEquals($itemValue$ruleValue),
            Rule::OPERATOR_GT => FloatComparator::greaterThan($itemValue$ruleValue),
            Rule::OPERATOR_LT => FloatComparator::lessThan($itemValue$ruleValue),
            Rule::OPERATOR_EQ => FloatComparator::equals($itemValue$ruleValue),
            Rule::OPERATOR_NEQ => FloatComparator::notEquals($itemValue$ruleValue),
            default => throw new UnsupportedOperatorException($operator, self::class),
        };
    }

    public static function string(?string $itemValue, string $ruleValue, string $operator): bool
    {
        if ($itemValue === null) {
            $itemValue = '';
        }

        
public function testCreateNamed()
    {
        $uuidFactory = new UuidFactory();

        // Test custom namespace         $uuid1 = $uuidFactory->nameBased('6f80c216-0492-4421-bd82-c10ab929ae84')->create('foo');
        $this->assertInstanceOf(UuidV5::class$uuid1);
        $this->assertSame('d521ceb7-3e31-5954-b873-92992c697ab9', (string) $uuid1);

        // Test default namespace override         $uuid2 = $uuidFactory->nameBased(Uuid::v4())->create('foo');
        $this->assertFalse($uuid1->equals($uuid2));

        // Test version override         $uuidFactory = new UuidFactory(6, 6, 3, 4, new NilUuid(), '6f80c216-0492-4421-bd82-c10ab929ae84');
        $uuid3 = $uuidFactory->nameBased()->create('foo');
        $this->assertInstanceOf(UuidV3::class$uuid3);
    }

    public function testCreateTimedDefaultVersion()
    {
        $this->assertInstanceOf(UuidV6::class(new UuidFactory())->timeBased()->create());
        $this->assertInstanceOf(UuidV1::class(new UuidFactory(6, 1))->timeBased()->create());
    }
$ancestor_is_pending_revision = (bool) array_intersect_key($ancestorsarray_flip($pending_term_ids));

    $new_parents = array_column($entity->parent->getValue(), 'target_id');
    $original_parents = array_keys($term_storage->loadParents($entity->id())) ?: [0];
    if (($is_pending_revision || $ancestor_is_pending_revision) && $new_parents != $original_parents) {
      $this->context->buildViolation($constraint->message)
        ->atPath('parent')
        ->addViolation();
    }

    $original = $term_storage->loadUnchanged($entity->id());
    if (($is_pending_revision || $ancestor_is_pending_revision) && !$entity->weight->equals($original->weight)) {
      $this->context->buildViolation($constraint->message)
        ->atPath('weight')
        ->addViolation();
    }
  }

}
    // type.     $node = Node::create([
      'title' => $this->randomString(),
      'type' => 'foo',
      'path' => ['alias' => '/foo'],
    ]);
    $second_node = Node::create([
      'title' => $this->randomString(),
      'type' => 'foo',
      'path' => ['alias' => '/foo'],
    ]);
    $this->assertTrue($node->get('path')->equals($second_node->get('path')));

    // Change the alias for the second node to a different one and try again.     $second_node->get('path')->alias = '/foobar';
    $this->assertFalse($node->get('path')->equals($second_node->get('path')));

    // Test the generateSampleValue() method.     $node = Node::create([
      'title' => $this->randomString(),
      'type' => 'foo',
      'path' => ['alias' => '/foo'],
    ]);
    
->method('createFieldItem')
      ->willReturnOnConsecutiveCalls($first_field_item$second_field_item);

    // Set the field item values.     if ($first_field_item instanceof FieldItemInterface) {
      $field_list_a->setValue($first_field_item);
    }
    if ($second_field_item instanceof FieldItemInterface) {
      $field_list_b->setValue($second_field_item);
    }

    $this->assertEquals($expected$field_list_a->equals($field_list_b));
  }

  /** * Data provider for testEquals. */
  public function providerTestEquals() {
    // Tests field item lists with no values.     $datasets[] = [TRUE];

    /** @var \Drupal\Core\Field\FieldItemBase $field_item_a */
    $field_item_a = $this->getMockForAbstractClass('Drupal\Core\Field\FieldItemBase', [], '', FALSE);
    
$this->assertSame('0xd6b3345b29054048a83cb5988e765d98', $uuid->toHex());
    }

    public function testFromUlid()
    {
        $ulid = new Ulid();
        $uuid = Uuid::fromString($ulid);

        $this->assertSame((string) $ulid$uuid->toBase32());
        $this->assertSame((string) $uuid$uuid->toRfc4122());
        $this->assertTrue($uuid->equals(Uuid::fromString($ulid)));
    }

    public function testBase58()
    {
        $uuid = new NilUuid();
        $this->assertSame('1111111111111111111111', $uuid->toBase58());

        $uuid = Uuid::fromString("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF");
        $this->assertSame('YcVfxkQb6JRzqk5kF2tNLv', $uuid->toBase58());
        $this->assertTrue($uuid->equals(Uuid::fromString('YcVfxkQb6JRzqk5kF2tNLv')));
    }

    
private function validate(CalculatedPrice $price, LineItemCollection $goods, Cart $cart): bool
    {
        if ($goods->count() <= 0) {
            return false;
        }

        if (FloatComparator::greaterThan($price->getTotalPrice(), 0)) {
            return true;
        }

        if (FloatComparator::equals($price->getTotalPrice(), 0)) {
            return false;
        }

        // should not be possible to get negative carts         $total = $price->getTotalPrice() + $cart->getLineItems()->getPrices()->sum()->getTotalPrice();

        return $total >= 0;
    }

    private function calculate(?PriceDefinitionInterface $definition, LineItemCollection $goods, SalesChannelContext $context): CalculatedPrice
    {
        
                $context->setRuleIds($rules->getIds());

                // calculate cart again                 $cart = $this->processor->process($cart$context$behaviorContext);

                // check if the cart changed, in this case we have to recalculate the cart again                 $recalculate = $this->cartChanged($cart$compare);

                // check if rules changed for the last calculated cart, in this case we have to recalculate                 $ruleCompare = $all->filterMatchingRules($cart$context);

                if (!$rules->equals($ruleCompare)) {
                    $recalculate = true;
                    $rules = $ruleCompare;
                }

                ++$iteration;
            } while ($recalculate);

            $cart = $this->validateTaxFree($context$cart$behaviorContext);

            $index = 0;
            foreach ($rules as $rule) {
                
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
use Symfony\Component\Messenger\Stamp\ErrorDetailsStamp;

final class AddErrorDetailsStampListener implements EventSubscriberInterface
{
    public function onMessageFailed(WorkerMessageFailedEvent $event): void
    {
        $stamp = ErrorDetailsStamp::create($event->getThrowable());
        $previousStamp = $event->getEnvelope()->last(ErrorDetailsStamp::class);

        // Do not append duplicate information         if (null === $previousStamp || !$previousStamp->equals($stamp)) {
            $event->addStamps($stamp);
        }
    }

    public static function getSubscribedEvents(): array
    {
        return [
            // must have higher priority than SendFailedMessageForRetryListener             WorkerMessageFailedEvent::class => ['onMessageFailed', 200],
        ];
    }
}
public function testCreate()
    {
        $ulidFactory = new UlidFactory();

        $ulidFactory->create();

        $ulid1 = $ulidFactory->create(new \DateTimeImmutable('@999999.123000'));
        $this->assertSame('999999.123000', $ulid1->getDateTime()->format('U.u'));
        $ulid2 = $ulidFactory->create(new \DateTimeImmutable('@999999.123000'));
        $this->assertSame('999999.123000', $ulid2->getDateTime()->format('U.u'));

        $this->assertFalse($ulid1->equals($ulid2));
        $this->assertSame(-1, $ulid1->compare($ulid2));

        $ulid3 = $ulidFactory->create(new \DateTimeImmutable('@1234.162524'));
        $this->assertSame('1234.162000', $ulid3->getDateTime()->format('U.u'));
    }

    public function testCreateWithInvalidTimestamp()
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('The timestamp must be positive.');

        (
$criteria->addAggregation(new AvgAggregation('avg-stock', 'product.stock'));

            $aggregations = $aggregator->aggregate($this->productDefinition, $criteria$this->context);

            static::assertCount(1, $aggregations);

            static::assertTrue($aggregations->has('avg-stock'));

            $result = $aggregations->get('avg-stock');
            static::assertInstanceOf(AvgResult::class$result);

            static::assertTrue(FloatComparator::equals(194.57142857143, $result->getAvg()));
        } catch (\Exception $e) {
            static::tearDown();

            throw $e;
        }
    }

    /** * @depends testIndexing */
    public function testTermsAggregation(IdsCollection $data): void
    {
new Ulid('this is not a ulid');
    }

    public function testBinary()
    {
        $ulid = new Ulid('00000000000000000000000000');
        $this->assertSame("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", $ulid->toBinary());

        $ulid = new Ulid('3zzzzzzzzzzzzzzzzzzzzzzzzz');
        $this->assertSame('7fffffffffffffffffffffffffffffff', bin2hex($ulid->toBinary()));

        $this->assertTrue($ulid->equals(Ulid::fromString(hex2bin('7fffffffffffffffffffffffffffffff'))));
    }

    public function toHex()
    {
        $ulid = Ulid::fromString('1BVXue8CnY8ogucrHX3TeF');
        $this->assertSame('0x0177058f4dacd0b2a990a49af02bc008', $ulid->toHex());
    }

    public function testFromUuid()
    {
        $uuid = new UuidV4();

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