You are here

protected function FractionConstraintTest::generateFraction in Fraction 8

Same name and namespace in other branches
  1. 2.x tests/src/Kernel/Plugin/Constraints/FractionConstraintTest.php \Drupal\Tests\fraction\Kernel\Plugin\Constraints\FractionConstraintTest::generateFraction()

Helper method that generates fraction from decimal to set it on field.

Parameters

string $decimal: Decimal to convert to fraction.

Return value

array Array to be set on field.

1 call to FractionConstraintTest::generateFraction()
FractionConstraintTest::testConstraints in tests/src/Kernel/Plugin/Constraints/FractionConstraintTest.php
Tests constraints.

File

tests/src/Kernel/Plugin/Constraints/FractionConstraintTest.php, line 155

Class

FractionConstraintTest
Tests Constraint for Fraction.

Namespace

Drupal\Tests\fraction\Kernel\Plugin\Constraints

Code

protected function generateFraction(string $decimal) {
  $fraction = Fraction::createFromDecimal($decimal);
  $numerator = $fraction
    ->getNumerator();
  $denominator = $fraction
    ->getDenominator();

  // Set the numerator and denominator values for the field and store
  // them in array which will be saved on the field.
  return [
    'decimal' => $decimal,
    'numerator' => $numerator,
    'denominator' => $denominator,
  ];
}