Skip to content

Commit

Permalink
MNT Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Dec 3, 2024
1 parent dd6662d commit 03efcea
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tests/php/Dev/BacktraceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static function matchesFilterableClassProvider(): array
#[DataProvider('matchesFilterableClassProvider')]
public function testMatchesFilterableClass(string $className, string $filterableClass, bool $expected, string $message): void
{
$reflectionMethod = new ReflectionMethod(Backtrace::class . '::matchesFilterableClass');
$reflectionMethod = new ReflectionMethod(Backtrace::class, 'matchesFilterableClass');
$reflectionMethod->setAccessible(true);
$this->assertSame($expected, $reflectionMethod->invoke(null, $className, $filterableClass), $message);
}
Expand Down
10 changes: 5 additions & 5 deletions tests/php/Dev/CsvBulkLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public function testLoad()
$filepath = $this->csvPath . 'PlayersWithHeader.csv';
$file = fopen($filepath ?? '', 'r');
$compareCount = $this->getLineCount($file);
fgetcsv($file); // pop header row
$compareRow = fgetcsv($file);
fgetcsv($file, escape: "\\"); // pop header row
$compareRow = fgetcsv($file, escape: "\\");
$results = $loader->load($filepath);

// Test that right amount of columns was imported
Expand Down Expand Up @@ -141,7 +141,7 @@ public function testLoadWithColumnMap()
$filepath = $this->csvPath . 'Players.csv';
$file = fopen($filepath ?? '', 'r');
$compareCount = $this->getLineCount($file);
$compareRow = fgetcsv($file);
$compareRow = fgetcsv($file, escape: "\\");
$loader->columnMap = [
'FirstName',
'Biography',
Expand Down Expand Up @@ -188,8 +188,8 @@ public function testLoadWithCustomHeaderAndRelation()
$filepath = $this->csvPath . 'PlayersWithCustomHeaderAndRelation.csv';
$file = fopen($filepath ?? '', 'r');
$compareCount = $this->getLineCount($file);
fgetcsv($file); // pop header row
$compareRow = fgetcsv($file);
fgetcsv($file, escape: "\\"); // pop header row
$compareRow = fgetcsv($file, escape: "\\");
$loader->columnMap = [
'first name' => 'FirstName',
'bio' => 'Biography',
Expand Down
6 changes: 1 addition & 5 deletions tests/php/Dev/SapphireTestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use SilverStripe\Security\Permission;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\DataProviderExternal;
use SilverStripe\Dev\Exceptions\ExpectedErrorException;
use SilverStripe\Dev\Exceptions\ExpectedNoticeException;
use SilverStripe\Dev\Exceptions\ExpectedWarningException;

Expand Down Expand Up @@ -271,11 +270,8 @@ public function testEnableErrorHandler(int $errno, ?string $expectedClass): void
public static function provideEnableErrorHandler(): array
{
// Only E_USER_* errors can be triggered, so that's all that's being tested
// As of PHP 8.4, E_USER_ERROR can no longer be triggered without a PHP deprecation notice
return [
'error' => [
'errno' => E_USER_ERROR,
'expectedClass' => ExpectedErrorException::class,
],
'notice' => [
'errno' => E_USER_NOTICE,
'expectedClass' => ExpectedNoticeException::class,
Expand Down
12 changes: 7 additions & 5 deletions tests/php/Forms/FormFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
use SilverStripe\Core\Validation\FieldValidation\OptionFieldValidator;
use SilverStripe\ORM\DataList;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\SegmentField;
use SilverStripe\Core\Validation\FieldValidation\TimeFieldValidator;
use SilverStripe\Core\Validation\FieldValidation\DatetimeFieldValidator;

Expand Down Expand Up @@ -932,9 +931,6 @@ public function testFieldValidatorConfig(): void
SelectionGroup_Item::class => [
CompositeFieldValidator::class,
],
SegmentField::class => [
StringFieldValidator::class,
],
SingleLookupField::class => [],
Tab::class => [
CompositeFieldValidator::class,
Expand Down Expand Up @@ -969,6 +965,12 @@ public function testFieldValidatorConfig(): void
];
$count = 0;
foreach ($this->getFormFieldClasses() as $class) {
// skip any class with a core namespace that resides in an optional module that
// is included in silverstripe/recipe-kitchen-sink, and not in silverstripe/installer
if ($class === 'SilverStripe\\Forms\\SegmentField') {
// class if from silverstripe/segment-field
continue;
}
if (!array_key_exists($class, $expectedFieldValidators)) {
throw new Exception("No field validator config found for $class");
}
Expand All @@ -983,7 +985,7 @@ public function testFieldValidatorConfig(): void
}
// Assert that we have tested all classes e.g. namespace wasn't changed, no new classes were added
// that haven't been tested
$this->assertSame(58, $count);
$this->assertSame(57, $count);
}

private function instantiateFormField(string $class): FormField
Expand Down

0 comments on commit 03efcea

Please sign in to comment.