Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion system/Test/Constraints/SeeInDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ class SeeInDatabase extends Constraint
/**
* Data used to compare results against.
*
* @var array
* @var array<string, mixed>
*/
protected $data;

/**
* SeeInDatabase constructor.
*
* @param array<string, mixed> $data
*/
public function __construct(ConnectionInterface $db, array $data)
{
Expand Down
4 changes: 2 additions & 2 deletions system/Test/ControllerTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ trait ControllerTestTrait
/**
* URI of this request.
*
* @var string
* @var string|URI
*/
protected $uri = 'http://example.com';

Expand Down Expand Up @@ -144,7 +144,7 @@ public function controller(string $name)
/**
* Runs the specified method on the controller and returns the results.
*
* @param array $params
* @param mixed ...$params
*
* @return TestResponse
*
Expand Down
2 changes: 2 additions & 0 deletions system/Test/DOMParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ public function dontSeeXPath(string $path): bool
/**
* Search the DOM using an XPath expression.
*
* @param list<string> $paths
*
* @return DOMNodeList|false
*/
protected function doXPath(?string $search, string $element, array $paths = [])
Expand Down
34 changes: 19 additions & 15 deletions system/Test/Fabricator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Fabricator
/**
* Array of counts for fabricated items
*
* @var array
* @var array<string, int>
*/
protected static $tableCounts = [];

Expand Down Expand Up @@ -65,28 +65,28 @@ class Fabricator
/**
* Map of properties and their formatter to use
*
* @var array|null
* @var array<string, string>|null
*/
protected $formatters;

/**
* Date fields present in the model
*
* @var array
* @var list<string>
*/
protected $dateFields = [];

/**
* Array of data to add or override faked versions
*
* @var array
* @var array<string, mixed>
*/
protected $overrides = [];

/**
* Array of single-use data to override faked versions
*
* @var array|null
* @var array<string, mixed>|null
*/
protected $tempOverrides;

Expand All @@ -111,9 +111,9 @@ class Fabricator
/**
* Store the model instance and initialize Faker to the locale.
*
* @param object|string $model Instance or classname of the model to use
* @param array|null $formatters Array of property => formatter
* @param string|null $locale Locale for Faker provider
* @param object|string $model Instance or classname of the model to use
* @param array<string, string>|null $formatters Array of property => formatter
* @param string|null $locale Locale for Faker provider
*
* @throws InvalidArgumentException
*/
Expand Down Expand Up @@ -238,6 +238,8 @@ public function getFaker(): Generator

/**
* Return and reset tempOverrides
*
* @return array<string, mixed>
*/
public function getOverrides(): array
{
Expand All @@ -251,8 +253,8 @@ public function getOverrides(): array
/**
* Set the overrides, once or persistent
*
* @param array $overrides Array of [field => value]
* @param bool $persist Whether these overrides should persist through the next operation
* @param array<string, mixed> $overrides Array of [field => value]
* @param bool $persist Whether these overrides should persist through the next operation
*/
public function setOverrides(array $overrides = [], $persist = true): self
{
Expand Down Expand Up @@ -307,6 +309,8 @@ public function setValid(string $field, ?Closure $validator = null, int $maxRetr

/**
* Returns the current formatters
*
* @return array<string, string>|null
*/
public function getFormatters(): ?array
{
Expand All @@ -316,7 +320,7 @@ public function getFormatters(): ?array
/**
* Set the formatters to use. Will attempt to autodetect if none are available.
*
* @param array|null $formatters Array of [field => formatter], or null to detect
* @param array<string, string>|null $formatters Array of [field => formatter], or null to detect
*/
public function setFormatters(?array $formatters = null): self
{
Expand Down Expand Up @@ -399,7 +403,7 @@ protected function guessFormatter($field): string
*
* @param int|null $count Optional number to create a collection
*
* @return array|object An array or object (based on returnType), or an array of returnTypes
* @return array<string, mixed>|list<array<string, mixed>|object>|object An array or object (based on returnType), or an array of returnTypes
*/
public function make(?int $count = null)
{
Expand All @@ -424,7 +428,7 @@ public function make(?int $count = null)
/**
* Generate an array of faked data
*
* @return array An array of faked data
* @return array<string, mixed> An array of faked data
*
* @throws RuntimeException
*/
Expand Down Expand Up @@ -534,7 +538,7 @@ public function makeObject(?string $className = null): object
* @param int|null $count Optional number to create a collection
* @param bool $mock Whether to execute or mock the insertion
*
* @return array|object An array or object (based on returnType), or an array of returnTypes
* @return array<string, mixed>|list<array<string, mixed>|object>|object|null An array or object (based on returnType), or an array of returnTypes
*
* @throws FrameworkException
*/
Expand Down Expand Up @@ -572,7 +576,7 @@ public function create(?int $count = null, bool $mock = false)
*
* @param int|null $count Optional number to create a collection
*
* @return array|object An array or object (based on returnType), or an array of returnTypes
* @return array<string, mixed>|list<array<string, mixed>|object>|object An array or object (based on returnType), or an array of returnTypes
*/
protected function createMock(?int $count = null)
{
Expand Down
28 changes: 22 additions & 6 deletions system/Test/FeatureTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public function skipEvents()
* Calls a single URI, executes it, and returns a TestResponse
* instance that can be used to run many assertions against.
*
* @param string $method HTTP verb
* @param string $method HTTP verb
* @param array<array-key, mixed>|null $params
*
* @return TestResponse
*/
Expand Down Expand Up @@ -242,7 +243,8 @@ public function call(string $method, string $path, ?array $params = null)
/**
* Performs a GET request.
*
* @param string $path URI path relative to baseURL. May include query.
* @param string $path URI path relative to baseURL. May include query.
* @param array<array-key, mixed>|null $params
*
* @return TestResponse
*
Expand All @@ -257,6 +259,8 @@ public function get(string $path, ?array $params = null)
/**
* Performs a POST request.
*
* @param array<array-key, mixed>|null $params
*
* @return TestResponse
*
* @throws RedirectException
Expand All @@ -270,6 +274,8 @@ public function post(string $path, ?array $params = null)
/**
* Performs a PUT request
*
* @param array<array-key, mixed>|null $params
*
* @return TestResponse
*
* @throws RedirectException
Expand All @@ -283,6 +289,8 @@ public function put(string $path, ?array $params = null)
/**
* Performss a PATCH request
*
* @param array<array-key, mixed>|null $params
*
* @return TestResponse
*
* @throws RedirectException
Expand All @@ -296,6 +304,8 @@ public function patch(string $path, ?array $params = null)
/**
* Performs a DELETE request.
*
* @param array<array-key, mixed>|null $params
*
* @return TestResponse
*
* @throws RedirectException
Expand All @@ -309,6 +319,8 @@ public function delete(string $path, ?array $params = null)
/**
* Performs an OPTIONS request.
*
* @param array<array-key, mixed>|null $params
*
* @return TestResponse
*
* @throws RedirectException
Expand Down Expand Up @@ -379,10 +391,11 @@ protected function setupHeaders(IncomingRequest $request)
*
* Always populate the GET vars based on the URI.
*
* @param string $name Superglobal name (lowercase)
* @param non-empty-array|null $params
* @param string $name Superglobal name (lowercase)
* @param IncomingRequest $request
* @param non-empty-array<array-key, mixed>|null $params
*
* @return Request
* @return IncomingRequest
*
* @throws ReflectionException
*/
Expand Down Expand Up @@ -418,7 +431,10 @@ protected function populateGlobals(string $name, Request $request, ?array $param
* This allows the body to be formatted in a way that the controller is going to
* expect as in the case of testing a JSON or XML API.
*
* @param array|null $params The parameters to be formatted and put in the body.
* @param IncomingRequest $request
* @param array<array-key, mixed>|null $params The parameters to be formatted and put in the body.
*
* @return IncomingRequest
*/
protected function setRequestBody(Request $request, ?array $params = null): Request
{
Expand Down
6 changes: 6 additions & 0 deletions system/Test/IniTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@

trait IniTestTrait
{
/**
* @var array<string, false|string>
*/
private array $iniSettings = [];

/**
* @param list<string> $keys
*/
private function backupIniValues(array $keys): void
{
foreach ($keys as $key) {
Expand Down
4 changes: 3 additions & 1 deletion system/Test/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ public function getJSON()

/**
* Test that the response contains a matching JSON fragment.
*
* @param array<array-key, mixed> $fragment
*/
public function assertJSONFragment(array $fragment, bool $strict = false): void
{
Expand All @@ -378,7 +380,7 @@ public function assertJSONFragment(array $fragment, bool $strict = false): void
* Asserts that the JSON exactly matches the passed in data.
* If the value being passed in is a string, it must be a json_encoded string.
*
* @param array|object|string $test
* @param array<array-key, mixed>|object|string $test
*/
public function assertJSONExact($test): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Test/ControllerTestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function testFailsForward(): void
->execute('index');

// won't fail, but doesn't do anything
$this->assertNull($result->ohno('Hi'));
$this->assertNull($result->ohno('Hi')); // @phpstan-ignore method.notFound (Testing TestResponse::__call() fallback)
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/system/Test/DOMParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ public function testSeeElement($text): void
$this->assertTrue($dom->see($text, 'h1'));
}

/**
* @return iterable<string, array{string}>
*/
public static function provideText(): iterable
{
return [
Expand Down
2 changes: 2 additions & 0 deletions tests/system/Test/FabricatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ final class FabricatorTest extends CIUnitTestCase
{
/**
* Default formatters to use for UserModel. Should match detected version.
*
* @var array<string, string>
*/
private array $formatters = [
'name' => 'name',
Expand Down
3 changes: 3 additions & 0 deletions tests/system/Test/FeatureTestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ public function testOpenCliRoutesFromHttpGot404(string $from, string $to, string
$this->get($httpGet);
}

/**
* @return iterable<string, array{string, string, string}>
*/
public static function provideOpenCliRoutesFromHttpGot404(): iterable
{
return [
Expand Down
3 changes: 3 additions & 0 deletions tests/system/Test/TestLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public function testDidLogMethod(bool $expected, string $level, string $message,
);
}

/**
* @return iterable<string, array{bool, string, string, bool}>
*/
public static function provideDidLogMethod(): iterable
{
yield 'exact' => [
Expand Down
10 changes: 8 additions & 2 deletions tests/system/Test/TestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public function testIsOK(int $code, bool $isOk): void

/**
* Provides status codes and their expected "OK"
*
* @return iterable<array{int, bool}>
*/
public static function provideHttpStatusCodes(): iterable
{
Expand Down Expand Up @@ -312,7 +314,7 @@ public function testGetJSONEmptyJSON(): void
public function testGetJSONFalseJSON(): void
{
$this->getTestResponse('<h1>Hello World</h1>');
$this->response->setJSON(false, true);
$this->response->setJSON(false, true); // @phpstan-ignore argument.type (Needed for testing)

// this should be FALSE - json_encode(false)
$this->assertSame('false', $this->testResponse->getJSON());
Expand All @@ -321,7 +323,7 @@ public function testGetJSONFalseJSON(): void
public function testGetJSONTrueJSON(): void
{
$this->getTestResponse('<h1>Hello World</h1>');
$this->response->setJSON(true, true);
$this->response->setJSON(true, true); // @phpstan-ignore argument.type (Needed for testing)

// this should be TRUE - json_encode(true)
$this->assertSame('true', $this->testResponse->getJSON());
Expand Down Expand Up @@ -427,6 +429,10 @@ public function testAssertJsonExactString(): void
$this->testResponse->assertJSONExact($formatter->format($data));
}

/**
* @param array<string, mixed> $responseOptions
* @param array<string, mixed> $headers
*/
protected function getTestResponse(?string $body = null, array $responseOptions = [], array $headers = []): void
{
$this->response = new Response(new App());
Expand Down
Loading
Loading