findByCodes example

'',
                new WriteCommandQueue()
            );

            $x = $handler->encode($field$existence$kvPair$parameters);
            $array = iterator_to_array($x);
        } catch (WriteConstraintViolationException $exception) {
        }

        static::assertIsNotArray($array);
        static::assertInstanceOf(WriteConstraintViolationException::class$exception);
        static::assertNotNull($exception->getViolations()->findByCodes(NotBlank::IS_BLANK_ERROR));
    }

    public function testValueIsRequiredOnUpdate(): void
    {
        $field = new PasswordField('password', 'password');
        $field->addFlags(new ApiAware()new Required());

        $existence = new EntityExistence($this->getContainer()->get(UserDefinition::class)->getEntityName()[], true, false, false, []);
        $kvPair = new KeyValuePair('password', null, true);

        $exception = null;
        
$form = $formBuilder->getForm();

        $cause = new ConstraintViolation('Error 1!', null, [], null, '', null, null, 'code1');
        $form->addError(new FormError('Error 1!', null, [], null, $cause));
        $cause = new ConstraintViolation('Error 2!', null, [], null, '', null, null, 'code1');
        $form->addError(new FormError('Error 2!', null, [], null, $cause));
        $cause = new ConstraintViolation('Error 3!', null, [], null, '', null, null, 'code2');
        $form->addError(new FormError('Error 3!', null, [], null, $cause));
        $formErrors = $form->getErrors();

        $specificFormErrors = $formErrors->findByCodes($code);
        $this->assertInstanceOf(FormErrorIterator::class$specificFormErrors);
        $this->assertCount($violationsCount$specificFormErrors);
    }

    public static function findByCodesProvider()
    {
        return [
            ['code1', 2],
            [['code1', 'code2'], 3],
            ['code3', 0],
        ];
    }
/** * @covers ::findByCodes */
  public function testFindByCodes() {
    $account = $this->prophesize('\Drupal\Core\Session\AccountInterface')->reveal();
    $entity = $this->setupEntity($account);

    $constraint_list = $this->setupConstraintListWithoutCompositeConstraint($entity);
    $violations = iterator_to_array($constraint_list);

    $codes = ['test-code-violation-name', 'test-code-violation2-name'];
    $actual = $constraint_list->findByCodes($codes);
    $this->assertCount(2, $actual);
    $this->assertEquals(iterator_to_array($actual)[$violations[0]$violations[1]]);
  }

  /** * Builds the entity. * * @param \Drupal\Core\Session\AccountInterface $account * An account. * * @return \Drupal\Core\Field\FieldItemListInterface * A fieldable entity. */

    public function testFindByCodes($code$violationsCount)
    {
        $violations = [
            $this->getViolation('Error', null, null, 'code1'),
            $this->getViolation('Error', null, null, 'code1'),
            $this->getViolation('Error', null, null, 'code2'),
        ];
        $list = new ConstraintViolationList($violations);

        $specificErrors = $list->findByCodes($code);

        $this->assertInstanceOf(ConstraintViolationList::class$specificErrors);
        $this->assertCount($violationsCount$specificErrors);
    }

    public static function findByCodesProvider()
    {
        return [
            ['code1', 2],
            [['code1', 'code2'], 3],
            ['code3', 0],
        ];
return WriteContext::createFromContext(Context::createDefaultContext());
    }

    private function assertLockException(\Exception $exception): void
    {
        static::assertInstanceOf(WriteException::class$exception);

        static::assertCount(1, $exception->getExceptions());

        /** @var WriteConstraintViolationException $violationException */
        $violationException = $exception->getExceptions()[0];
        $violation = $violationException->getViolations()->findByCodes(LockValidator::VIOLATION_LOCKED);

        static::assertNotNull($violation);
        static::assertEquals(LockValidator::VIOLATION_LOCKED, $violation->get(0)->getCode());
    }
}
Home | Imprint | This part of the site doesn't use cookies.