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 Oct 21, 2024
1 parent 89213c9 commit f180723
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Dev/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public static function notice($atVersion, $string = '', $scope = Deprecation::SC
}

// Getting a backtrace is slow, so we only do it if we need it
$backtrace = null;
$backtrace = [];

// Get the calling scope
if ($scope == Deprecation::SCOPE_METHOD) {
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Dev/DeprecationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public function testNoticeNoReplacement()
'Will be removed without equivalent functionality to replace it.',
'Called from SilverStripe\Dev\Tests\DeprecationTest->testNoticeNoReplacement.'
]);
$this->expectDeprecation();
$this->expectDeprecationMessage($message);
$this->expectException(DeprecationTestException::class);
$this->expectExceptionMessage($message);
$this->enableDeprecationNotices(true);
$ret = $this->myDeprecatedMethodNoReplacement();
$this->assertSame('abc', $ret);
Expand Down
36 changes: 28 additions & 8 deletions tests/php/ORM/Search/SearchContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,36 @@ public function testUserDefinedFiltersAppearInSearchContext()
public function testUserDefinedFieldsAppearInSearchContext()
{
$company = SearchContextTest\Company::singleton();
$searchName = $company->getGeneralSearchFieldName();
$expected = new FieldList(
new HiddenField($searchName, 'General Search'),
(new TextField("Name", 'Name'))
->setMaxLength(255),
new TextareaField("Industry", 'Industry'),
new NumericField("AnnualProfit", 'The Almighty Annual Profit')
);
$context = $company->getDefaultSearchContext();
$actual = $context->getFields();
$this->assertSame($expected->count(), $actual->count());
$this->assertEquals(
$expected->fieldByName($searchName)->Title,
$actual->fieldByName($searchName)->Title
);
$this->assertEquals(
$expected->fieldByName('Name')->Title,
$actual->fieldByName('Name')->Title
);
$this->assertEquals(
$expected->fieldByName('Name')->getMaxLength(),
$actual->fieldByName('Name')->getMaxLength()
);
$this->assertEquals(
$expected->fieldByName('Industry')->Title,
$actual->fieldByName('Industry')->Title
);
$this->assertEquals(
new FieldList(
new HiddenField($company->getGeneralSearchFieldName(), 'General Search'),
(new TextField("Name", 'Name'))
->setMaxLength(255),
new TextareaField("Industry", 'Industry'),
new NumericField("AnnualProfit", 'The Almighty Annual Profit')
),
$context->getFields()
$expected->fieldByName('AnnualProfit')->Title,
$actual->fieldByName('AnnualProfit')->Title
);
}

Expand Down

0 comments on commit f180723

Please sign in to comment.