diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..22d0d82 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor diff --git a/composer.json b/composer.json index 36b0fef..955f40a 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,9 @@ } ], "require": { - "php": "^8" + "php": "^8", + "drupal/core-utility": "^10 || ^11", + "symfony/validator": "^5 || ^6 || ^7" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/src/Traits/AssertViolationsTrait.php b/src/Traits/AssertViolationsTrait.php new file mode 100644 index 0000000..ab94d73 --- /dev/null +++ b/src/Traits/AssertViolationsTrait.php @@ -0,0 +1,49 @@ +getPropertyPath()] = \strip_tags((string) $violation->getMessage()); + } + self::assertEquals($expected, $list); + } + + /** + * Asserts that an expected violation exists. + * + * @param string $expected_violation + * Expected violation message. + * @param \Symfony\Component\Validator\ConstraintViolationListInterface $violations + * A list of violations. + */ + protected static function assertViolationExists(string $expected_violation, ConstraintViolationListInterface $violations): void { + $list = []; + foreach ($violations as $violation) { + \assert($violation instanceof ConstraintViolation); + $list[$violation->getPropertyPath()] = \strip_tags((string) $violation->getMessage()); + } + self::assertContains($expected_violation, $list); + } + +} diff --git a/src/Traits/RandomValuesTrait.php b/src/Traits/RandomValuesTrait.php new file mode 100644 index 0000000..17be639 --- /dev/null +++ b/src/Traits/RandomValuesTrait.php @@ -0,0 +1,66 @@ +name(), $random->name()); + } + + /** + * Generates a random email. + * + * @return string + * Random email. + */ + protected function randomEmail(): string { + $random = new Random(); + return \sprintf('%s@%s.com', $random->name(), $random->name()); + } + + /** + * Generates a random lat lon pair. + */ + protected function randomLatLonPair(): string { + $lon = $this->randomPoint(-180, 180); + $lat = $this->randomPoint(-84, 84); + return \sprintf('POINT(%s %s)', $lon, $lat); + } + + /** + * Generates a random lat/lon point. + */ + private function randomPoint(int $min, int $max): float { + $number = \mt_rand($min, $max); + $decimals = \mt_rand(1, \pow(10, 5)) / \pow(10, 5); + return \round($number + $decimals, 5); + } + + /** + * Generates a random address. + * + * @return string + * Address. + */ + public function randomAddress(): string { + $random = new Random(); + return \sprintf('%d %s St, %s, %d', \rand(1, 200), $random->name(), $random->name(), \rand(2000, 2999)); + } + +} diff --git a/src/Traits/SpinTrait.php b/src/Traits/SpinTrait.php new file mode 100644 index 0000000..1af8699 --- /dev/null +++ b/src/Traits/SpinTrait.php @@ -0,0 +1,52 @@ +