diff --git a/types/Macros/Arr.php b/types/Macros/Arr.php new file mode 100644 index 000000000..129f29590 --- /dev/null +++ b/types/Macros/Arr.php @@ -0,0 +1,58 @@ + 'value'])); +assertType('bool', Arr::arrayable('string')); + +// Arr::array() tests +assertType('array', Arr::array(['nested' => ['key' => 'value']], 'nested')); +assertType('array', Arr::array(['data' => [1, 2, 3]], 'data', [])); + +// Arr::boolean() tests +assertType('bool', Arr::boolean(['is_active' => true], 'is_active')); +assertType('bool', Arr::boolean(['flag' => false], 'flag', false)); + +// Arr::every() tests +assertType('bool', Arr::every([1, 2, 3], fn ($value) => $value > 0)); +assertType('bool', Arr::every(['a', 'b', 'c'], fn ($value) => is_string($value))); + +// Arr::float() tests +assertType('float', Arr::float(['price' => 10.5], 'price')); +assertType('float', Arr::float(['amount' => 99.99], 'amount', 0.0)); + +// Arr::from() tests +assertType('array', Arr::from([])); +assertType('array', Arr::from(['key' => 'value'])); + +// Arr::hasAll() tests +assertType('bool', Arr::hasAll(['a' => 1, 'b' => 2], ['a', 'b'])); +assertType('bool', Arr::hasAll(['x' => 1], 'x')); + +// Arr::integer() tests +assertType('int', Arr::integer(['count' => 10], 'count')); +assertType('int', Arr::integer(['total' => 100], 'total', 0)); + +// Arr::string() tests +assertType('string', Arr::string(['name' => 'test'], 'name')); +assertType('string', Arr::string(['title' => 'value'], 'title', 'default')); + +// Arr::some() tests +assertType('bool', Arr::some([1, 2, 3], fn ($value) => $value > 2)); +assertType('bool', Arr::some(['a', 'b', 'c'], fn ($value) => $value === 'b')); + +// Arr::sortByMany() tests +assertType('array', Arr::sortByMany([['name' => 'John', 'age' => 30]], [['name', true]])); +assertType('array', Arr::sortByMany([['x' => 1], ['x' => 2]], [])); diff --git a/types/Macros/Collection.php b/types/Macros/Collection.php new file mode 100644 index 000000000..0b21474b5 --- /dev/null +++ b/types/Macros/Collection.php @@ -0,0 +1,22 @@ +isSingle()); +assertType('bool', (new Collection([1, 2]))->isSingle()); +assertType('bool', (new Collection([]))->isSingle()); + +// Collection::collapseWithKeys() tests +assertType('Hyperf\Collection\Collection', (new Collection([['a' => 1], ['b' => 2]]))->collapseWithKeys()); +assertType('Hyperf\Collection\Collection', (new Collection([]))->collapseWithKeys()); diff --git a/types/Macros/LazyCollection.php b/types/Macros/LazyCollection.php new file mode 100644 index 000000000..f96fd30b4 --- /dev/null +++ b/types/Macros/LazyCollection.php @@ -0,0 +1,22 @@ +isSingle()); +assertType('bool', LazyCollection::make([1, 2])->isSingle()); +assertType('bool', LazyCollection::make([])->isSingle()); + +// LazyCollection::collapseWithKeys() tests +assertType('Hyperf\Collection\LazyCollection', LazyCollection::make([['a' => 1], ['b' => 2]])->collapseWithKeys()); +assertType('Hyperf\Collection\LazyCollection', LazyCollection::make([])->collapseWithKeys()); diff --git a/types/Macros/Request.php b/types/Macros/Request.php new file mode 100644 index 000000000..ae6071523 --- /dev/null +++ b/types/Macros/Request.php @@ -0,0 +1,109 @@ +boolean('is_active')); +assertType('bool', $request->boolean('flag', false)); + +// Request::collect() tests +assertType('mixed', $request->collect()); +assertType('Hyperf\Collection\Collection', $request->collect('key')); +assertType('Hyperf\Collection\Collection', $request->collect(['key1', 'key2'])); + +// Request::date() tests +assertType('Carbon\Carbon|null', $request->date('created_at')); +assertType('Carbon\Carbon|null', $request->date('updated_at', 'Y-m-d')); +assertType('Carbon\Carbon|null', $request->date('deleted_at', 'Y-m-d H:i:s', 'UTC')); + +// Request::enum() tests +assertType('mixed', $request->enum('status', \BackedEnum::class)); + +// Request::exists() tests +assertType('bool', $request->exists('key')); + +// Request::filled() tests +assertType('bool', $request->filled('name')); +assertType('bool', $request->filled(['name', 'email'])); + +// Request::float() tests +assertType('float', $request->float('price')); +assertType('float', $request->float('amount', 0.0)); + +// Request::fluent() tests +assertType('Hyperf\Support\Fluent', $request->fluent()); +assertType('Hyperf\Support\Fluent', $request->fluent('key')); +assertType('Hyperf\Support\Fluent', $request->fluent(['key1', 'key2'])); + +// Request::hasAny() tests +assertType('bool', $request->hasAny(['key1', 'key2'])); +assertType('bool', $request->hasAny('key')); + +// Request::host() tests +assertType('string', $request->host()); + +// Request::httpHost() tests +assertType('string', $request->httpHost()); + +// Request::integer() tests +assertType('int', $request->integer('count')); +assertType('int', $request->integer('total', 0)); + +// Request::isEmptyString() tests +assertType('bool', $request->isEmptyString('field')); + +// Request::isJson() tests +assertType('bool', $request->isJson()); + +// Request::isNotFilled() tests +assertType('bool', $request->isNotFilled('field')); +assertType('bool', $request->isNotFilled(['field1', 'field2'])); + +// Request::keys() tests +assertType('array', $request->keys()); + +// Request::missing() tests +assertType('bool', $request->missing('key')); +assertType('bool', $request->missing(['key1', 'key2'])); + +// Request::str() tests +assertType('Hyperf\Stringable\Stringable', $request->str('name')); +assertType('Hyperf\Stringable\Stringable', $request->str('title', 'default')); + +// Request::string() tests +assertType('Hyperf\Stringable\Stringable', $request->string('name')); +assertType('Hyperf\Stringable\Stringable', $request->string('title', 'default')); + +// Request::wantsJson() tests +assertType('bool', $request->wantsJson()); + +// Request::isSecure() tests +assertType('bool', $request->isSecure()); + +// Request::getScheme() tests +assertType('string', $request->getScheme()); + +// Request::getPort() tests +assertType('int', $request->getPort()); + +// Request::schemeAndHttpHost() tests +assertType('string', $request->schemeAndHttpHost()); + +// Request::anyFilled() tests +assertType('bool', $request->anyFilled(['key1', 'key2'])); +assertType('bool', $request->anyFilled('key')); diff --git a/types/Macros/Str.php b/types/Macros/Str.php new file mode 100644 index 000000000..52a2ed905 --- /dev/null +++ b/types/Macros/Str.php @@ -0,0 +1,44 @@ + 'custom-uuid')); + +// Str::deduplicate() tests +assertType('string', Str::deduplicate('hello world')); +assertType('string', Str::deduplicate('a--b--c', '-')); + +// Str::inlineMarkdown() tests +assertType('string', Str::inlineMarkdown('**bold**')); +assertType('string', Str::inlineMarkdown('*italic*', [])); + +// Str::markdown() tests +assertType('string', Str::markdown('# Heading')); +assertType('string', Str::markdown('## Title', [], [])); + +// Str::transliterate() tests +assertType('string', Str::transliterate('こんにちは')); +assertType('string', Str::transliterate('café', '?', false)); + +// Str::doesntEndWith() tests +assertType('bool', Str::doesntEndWith('hello world', 'world')); +assertType('bool', Str::doesntEndWith('test', ['ing', 'ed'])); + +// Str::doesntStartWith() tests +assertType('bool', Str::doesntStartWith('hello world', 'hello')); +assertType('bool', Str::doesntStartWith('test', ['pre', 'post'])); diff --git a/types/Macros/Stringable.php b/types/Macros/Stringable.php new file mode 100644 index 000000000..aed8528bd --- /dev/null +++ b/types/Macros/Stringable.php @@ -0,0 +1,44 @@ +deduplicate()); +assertType('Hyperf\Stringable\Stringable', Str::of('a--b')->deduplicate('-')); + +// Stringable::hash() tests +assertType('Hyperf\Stringable\Stringable', Str::of('password')->hash('sha256')); +assertType('Hyperf\Stringable\Stringable', Str::of('text')->hash('md5')); + +// Stringable::inlineMarkdown() tests +assertType('Hyperf\Stringable\Stringable', Str::of('**bold**')->inlineMarkdown()); +assertType('Hyperf\Stringable\Stringable', Str::of('*italic*')->inlineMarkdown([])); + +// Stringable::markdown() tests +assertType('Hyperf\Stringable\Stringable', Str::of('# Heading')->markdown()); +assertType('Hyperf\Stringable\Stringable', Str::of('## Title')->markdown([], [])); + +// Stringable::toHtmlString() tests +assertType('FriendsOfHyperf\Support\HtmlString', Str::of('
test
')->toHtmlString()); + +// Stringable::whenIsAscii() tests +assertType('Hyperf\Stringable\Stringable', Str::of('hello')->whenIsAscii(fn ($s) => $s->upper())); +assertType('Hyperf\Stringable\Stringable', Str::of('test')->whenIsAscii(fn ($s) => $s->upper(), fn ($s) => $s->lower())); + +// Stringable::doesntEndWith() tests +assertType('bool', Str::of('hello world')->doesntEndWith('world')); +assertType('bool', Str::of('test')->doesntEndWith(['ing', 'ed'])); + +// Stringable::doesntStartWith() tests +assertType('bool', Str::of('hello world')->doesntStartWith('hello')); +assertType('bool', Str::of('test')->doesntStartWith(['pre', 'post']));