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
46 changes: 23 additions & 23 deletions tests/system/CommonSingleServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,6 @@ public function testSingleServiceWithAtLeastOneParamSupplied(string $service): v
}
}

public function testSingleServiceWithAllParamsSupplied(): void
{
$cache1 = single_service('cache', null, true);
$cache2 = single_service('cache', null, true);

assert($cache1 !== null);
assert($cache2 !== null);

// Assert that even passing true as last param this will
// not create a shared instance.
$this->assertInstanceOf($cache1::class, $cache2);
$this->assertNotSame($cache1, $cache2);
}

public function testSingleServiceWithGibberishGiven(): void
{
$this->assertNull(single_service('foo')); // @phpstan-ignore codeigniter.unknownServiceMethod
$this->assertNull(single_service('bar')); // @phpstan-ignore codeigniter.unknownServiceMethod
$this->assertNull(single_service('baz')); // @phpstan-ignore codeigniter.unknownServiceMethod
$this->assertNull(single_service('caches')); // @phpstan-ignore codeigniter.unknownServiceMethod
$this->assertNull(single_service('timers')); // @phpstan-ignore codeigniter.unknownServiceMethod
}

/**
* @return iterable<string, array{string}>
*/
Expand Down Expand Up @@ -137,4 +114,27 @@ public static function provideServiceNames(): iterable

yield from $services;
}

public function testSingleServiceWithAllParamsSupplied(): void
{
$cache1 = single_service('cache', null, true);
$cache2 = single_service('cache', null, true);

assert($cache1 !== null);
assert($cache2 !== null);

// Assert that even passing true as last param this will
// not create a shared instance.
$this->assertInstanceOf($cache1::class, $cache2);
$this->assertNotSame($cache1, $cache2);
}

public function testSingleServiceWithGibberishGiven(): void
{
$this->assertNull(single_service('foo')); // @phpstan-ignore codeigniter.unknownServiceMethod
$this->assertNull(single_service('bar')); // @phpstan-ignore codeigniter.unknownServiceMethod
$this->assertNull(single_service('baz')); // @phpstan-ignore codeigniter.unknownServiceMethod
$this->assertNull(single_service('caches')); // @phpstan-ignore codeigniter.unknownServiceMethod
$this->assertNull(single_service('timers')); // @phpstan-ignore codeigniter.unknownServiceMethod
}
}
18 changes: 9 additions & 9 deletions tests/system/Config/MimesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
#[Group('Others')]
final class MimesTest extends CIUnitTestCase
{
#[DataProvider('provideGuessExtensionFromType')]
public function testGuessExtensionFromType(?string $expected, string $mime): void
{
$this->assertSame($expected, Mimes::guessExtensionFromType($mime));
}

public static function provideGuessExtensionFromType(): iterable
{
return [
Expand All @@ -50,10 +56,10 @@ public static function provideGuessExtensionFromType(): iterable
];
}

#[DataProvider('provideGuessExtensionFromType')]
public function testGuessExtensionFromType(?string $expected, string $mime): void
#[DataProvider('provideGuessTypeFromExtension')]
public function testGuessTypeFromExtension(?string $expected, string $ext): void
{
$this->assertSame($expected, Mimes::guessExtensionFromType($mime));
$this->assertSame($expected, Mimes::guessTypeFromExtension($ext));
}

public static function provideGuessTypeFromExtension(): iterable
Expand Down Expand Up @@ -81,10 +87,4 @@ public static function provideGuessTypeFromExtension(): iterable
],
];
}

#[DataProvider('provideGuessTypeFromExtension')]
public function testGuessTypeFromExtension(?string $expected, string $ext): void
{
$this->assertSame($expected, Mimes::guessTypeFromExtension($ext));
}
}
26 changes: 13 additions & 13 deletions tests/system/Config/ServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function testNewSessionWithNullConfig(): void
$this->assertInstanceOf(Session::class, $actual);
}

#[DataProvider('provideNewSessionInvalid')]
#[DataProvider('provideNewSessionWithInvalidHandler')]
#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
public function testNewSessionWithInvalidHandler(string $driver): void
Expand All @@ -277,6 +277,18 @@ public function testNewSessionWithInvalidHandler(string $driver): void
Services::session($config, false);
}

/**
* @return iterable<string, array{0: string}>
*/
public static function provideNewSessionWithInvalidHandler(): iterable
{
yield 'just a string' => ['file'];

yield 'inexistent class' => ['Foo'];

yield 'other class' => [self::class];
}

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
public function testNewSessionWithInvalidDatabaseHandler(): void
Expand All @@ -296,18 +308,6 @@ public function testNewSessionWithInvalidDatabaseHandler(): void
Services::session($config, false);
}

/**
* @return iterable<string, array{0: string}>
*/
public static function provideNewSessionInvalid(): iterable
{
yield 'just a string' => ['file'];

yield 'inexistent class' => ['Foo'];

yield 'other class' => [self::class];
}

#[PreserveGlobalState(false)]
#[RunInSeparateProcess]
public function testCallStatic(): void
Expand Down
20 changes: 10 additions & 10 deletions tests/system/DataConverter/DataConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ public function testConvertDataFromDB(array $types, array $dbData, array $expect
$this->assertSame($expected, $data);
}

#[DataProvider('provideConvertDataToDB')]
public function testConvertDataToDB(array $types, array $phpData, array $expected): void
{
$converter = $this->createDataConverter($types);

$data = $converter->toDataSource($phpData);

$this->assertSame($expected, $data);
}

public static function provideConvertDataFromDB(): iterable
{
yield from [
Expand Down Expand Up @@ -206,6 +196,16 @@ public static function provideConvertDataFromDB(): iterable
];
}

#[DataProvider('provideConvertDataToDB')]
public function testConvertDataToDB(array $types, array $phpData, array $expected): void
{
$converter = $this->createDataConverter($types);

$data = $converter->toDataSource($phpData);

$this->assertSame($expected, $data);
}

public static function provideConvertDataToDB(): iterable
{
yield from [
Expand Down
52 changes: 26 additions & 26 deletions tests/system/Database/BaseQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ public function testSwapPrefix(): void
$this->assertSame($newSQL, $query->getQuery());
}

/**
* @param mixed $expected
* @param mixed $sql
*/
#[DataProvider('provideIsWriteType')]
public function testIsWriteType($expected, $sql): void
{
$query = new Query($this->db);

$query->setQuery($sql);
$this->assertSame($expected, $query->isWriteType());
}

public static function provideIsWriteType(): iterable
{
return [
Expand Down Expand Up @@ -185,19 +198,6 @@ public static function provideIsWriteType(): iterable
];
}

/**
* @param mixed $expected
* @param mixed $sql
*/
#[DataProvider('provideIsWriteType')]
public function testIsWriteType($expected, $sql): void
{
$query = new Query($this->db);

$query->setQuery($sql);
$this->assertSame($expected, $query->isWriteType());
}

public function testSingleBindingOutsideOfArray(): void
{
$query = new Query($this->db);
Expand Down Expand Up @@ -579,6 +579,19 @@ public function testSwapPrefixAfterGetQuery(): void
$this->assertSame($expected, $query->getQuery());
}

/**
* @param mixed $expected
* @param mixed $sql
*/
#[DataProvider('provideHighlightQueryKeywords')]
public function testHighlightQueryKeywords($expected, $sql): void
{
$query = new Query($this->db);
$query->setQuery($sql);

$this->assertSame($expected, $query->debugToolbarDisplay());
}

public static function provideHighlightQueryKeywords(): iterable
{
return [
Expand All @@ -596,17 +609,4 @@ public static function provideHighlightQueryKeywords(): iterable
],
];
}

/**
* @param mixed $expected
* @param mixed $sql
*/
#[DataProvider('provideHighlightQueryKeywords')]
public function testHighlightQueryKeywords($expected, $sql): void
{
$query = new Query($this->db);
$query->setQuery($sql);

$this->assertSame($expected, $query->debugToolbarDisplay());
}
}
2 changes: 1 addition & 1 deletion tests/system/Database/Builder/WhenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function testWhenNotRunsDefaultCallbackBasedOnCondition(mixed $condition,
/**
* @return array<string, array{0: mixed, 1: bool}>
*/
public static function provideConditionValues(): array
public static function provideConditionValues(): iterable
{
return [
'false' => [false, true], // [condition, expectedDefaultCallbackRuns]
Expand Down
24 changes: 12 additions & 12 deletions tests/system/Database/Builder/WhereTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,6 @@ public function testWhereInSubQuery(): void
$this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect()));
}

public static function provideWhereInvalidKeyThrowInvalidArgumentException(): iterable
{
return [
'null' => [null],
'empty string' => [''],
];
}

/**
* @param mixed $key
*/
Expand All @@ -415,12 +407,11 @@ public function testWhereInvalidKeyThrowInvalidArgumentException($key): void
$builder->whereIn($key, ['Politician', 'Accountant']);
}

public static function provideWhereInEmptyValuesThrowInvalidArgumentException(): iterable
public static function provideWhereInvalidKeyThrowInvalidArgumentException(): iterable
{
return [
'null' => [null],
'not array' => ['not array'],
'not instanceof \Closure' => [new stdClass()],
'null' => [null],
'empty string' => [''],
];
}

Expand All @@ -436,6 +427,15 @@ public function testWhereInEmptyValuesThrowInvalidArgumentException($values): vo
$builder->whereIn('name', $values);
}

public static function provideWhereInEmptyValuesThrowInvalidArgumentException(): iterable
{
return [
'null' => [null],
'not array' => ['not array'],
'not instanceof \Closure' => [new stdClass()],
];
}

public function testWhereNotIn(): void
{
$builder = $this->db->table('jobs');
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Database/Live/LikeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testLikeCaseInsensitive(): void
$this->assertSame('Developer', $job->name);
}

#[DataProvider('provideMultibyteCharacters')]
#[DataProvider('provideLikeCaseInsensitiveWithMultibyteCharacter')]
public function testLikeCaseInsensitiveWithMultibyteCharacter(string $match, string $result): void
{
$wai = $this->db->table('without_auto_increment')->like('value', $match, 'both', null, true)->get();
Expand All @@ -88,7 +88,7 @@ public function testLikeCaseInsensitiveWithMultibyteCharacter(string $match, str
/**
* @return iterable<string, array{0: string, 1: string}>
*/
public static function provideMultibyteCharacters(): iterable
public static function provideLikeCaseInsensitiveWithMultibyteCharacter(): iterable
{
yield from [
'polish' => ['ŁĄ', 'multibyte characters pl'],
Expand Down
16 changes: 8 additions & 8 deletions tests/system/Email/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ public function testEmailValidation(): void
$this->assertStringContainsString('Invalid email address: "invalid"', $email->printDebugger());
}

public static function provideEmailSendWithClearance(): iterable
{
return [
'autoclear' => [true],
'not autoclear' => [false],
];
}

/**
* @param bool $autoClear
*/
Expand All @@ -64,6 +56,14 @@ public function testEmailSendWithClearance($autoClear): void
}
}

public static function provideEmailSendWithClearance(): iterable
{
return [
'autoclear' => [true],
'not autoclear' => [false],
];
}

public function testEmailSendStoresArchive(): void
{
$email = $this->createMockEmail();
Expand Down
Loading
Loading