dev/tests/makeRoutes.php

36 lines
1.6 KiB
PHP
Raw Normal View History

2024-09-07 13:02:52 -05:00
<?php
$routes = [];
$methods = ['GET', 'POST', 'PUT', 'DELETE'];
$apis = ['blog', 'github', 'dragonknight', 'ecchi', 'hentai', 'harem', 'isekai', 'mecha', 'romance', 'shoujo', 'shounen', 'slice-of-life', 'supernatural', 'yuri'];
$params = ['id', 'slug', 'page', 'extra', 'foo', 'string', 'number', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply', 'waldo', 'fred', 'plugh', 'xyzzy', 'thud'];
$endpoint = ['edit', 'create', 'delete', 'view', 'change', 'modify', 'generate', 'lift', 'lower', 'raise', 'drop', 'pick', 'choose', 'select', 'deselect', 'unselect', 'reselect', 'pick', 'unpick', 'repick', 'reselect', 'reunpick', 'rechoose', 'reselect'];
$midpoint = ['do', 'cause', 'effect', 'affect', 'impact', 'influence', 'change', 'modify', 'transform', 'alter', 'shift', 'adjust', 'adapt', 'convert', 'translate'];
2024-12-25 09:09:30 -06:00
file_put_contents('routes/big.txt', implode("\n", array_map(fn() => makeRoute(), range(1, 1000))));
enum RoutePart: string {
case PARAMS = 'params';
case ENDPOINT = 'endpoint';
case MIDPOINT = 'midpoint';
public function matches(array $params, array $endpoint, array $midpoint): string {
return '/' . match ($this) {
self::PARAMS => ':' . $params[array_rand($params)],
self::ENDPOINT => $endpoint[array_rand($endpoint)],
self::MIDPOINT => $midpoint[array_rand($midpoint)],
};
}
2024-09-07 13:02:52 -05:00
}
function makeRoute(): string
{
global $methods, $apis, $params, $endpoint, $midpoint;
2024-12-25 09:09:30 -06:00
return $methods[array_rand($methods)] .
' /' .
$apis[array_rand($apis)] .
implode('', array_map(fn($option) => $option->matches($params, $endpoint, $midpoint), array_rand(array_flip(RoutePart::cases()), rand(1, 8))));
2024-09-07 13:02:52 -05:00
}