Skip to content

Commit

Permalink
minor #5607 Don't use some deprecated methods in tests (javiereguiluz)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.x branch.

Discussion
----------

Don't use some deprecated methods in tests

The `setMethods()` method was deprecated in previous PhpUnit versions and removed in PhpUnit 10 ... so let's not use it to ease compatibility with next PhpUnit versions.

Commits
-------

28cf4dc Don't use some deprecated methods in tests
  • Loading branch information
javiereguiluz committed Feb 5, 2023
2 parents 934d5e6 + 28cf4dc commit cd46dbd
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions tests/Field/AbstractFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function setUp(): void

$crudMock = $this->getMockBuilder(CrudDto::class)
->disableOriginalConstructor()
->setMethods(['getCurrentPage', 'getDatePattern', 'getDateTimePattern', 'getTimePattern'])
->onlyMethods(['getCurrentPage', 'getDatePattern', 'getDateTimePattern', 'getTimePattern'])
->getMock();
$crudMock->method('getCurrentPage')->willReturn(Crud::PAGE_INDEX);
$crudMock->method('getDatePattern')->willReturn(DateTimeField::FORMAT_MEDIUM);
Expand All @@ -40,14 +40,14 @@ protected function setUp(): void

$i18nMock = $this->getMockBuilder(I18nDto::class)
->disableOriginalConstructor()
->setMethods(['getTranslationParameters', 'getTranslationDomain'])
->onlyMethods(['getTranslationParameters', 'getTranslationDomain'])
->getMock();
$i18nMock->method('getTranslationParameters')->willReturn([]);
$i18nMock->method('getTranslationDomain')->willReturn('messages');

$adminContextMock = $this->getMockBuilder(AdminContext::class)
->disableOriginalConstructor()
->setMethods(['getCrud', 'getI18n', 'getTemplatePath'])
->onlyMethods(['getCrud', 'getI18n', 'getTemplatePath'])
->getMock();
$adminContextMock
->expects($this->any())
Expand Down
2 changes: 1 addition & 1 deletion tests/Field/DateFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected function setUp(): void

$intlFormatterMock = $this->getMockBuilder(IntlFormatter::class)
->disableOriginalConstructor()
->setMethods(['formatDate'])
->onlyMethods(['formatDate'])
->getMock();
$intlFormatterMock->method('formatDate')->willReturnCallback(
static function ($value, ?string $dateFormat = 'medium', string $pattern = '', $timezone = null, string $calendar = 'gregorian', string $locale = null) { return sprintf('value: %s | dateFormat: %s | pattern: %s | timezone: %s | calendar: %s | locale: %s', $value instanceof \DateTimeInterface ? $value->format('Y-m-d H:i:s') : $value, $dateFormat, $pattern, $timezone, $calendar, $locale); }
Expand Down
2 changes: 1 addition & 1 deletion tests/Field/DateTimeFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected function setUp(): void

$intlFormatterMock = $this->getMockBuilder(IntlFormatter::class)
->disableOriginalConstructor()
->setMethods(['formatDateTime'])
->onlyMethods(['formatDateTime'])
->getMock();
$intlFormatterMock->method('formatDateTime')->willReturnCallback(
static function ($value, ?string $dateFormat = 'medium', ?string $timeFormat = 'medium', string $pattern = '', $timezone = null, string $calendar = 'gregorian', string $locale = null) { return sprintf('value: %s | dateFormat: %s | timeFormat: %s | pattern: %s | timezone: %s | calendar: %s | locale: %s', $value->format('Y-m-d'), $dateFormat, $timeFormat, $pattern, $timezone, $calendar, $locale); }
Expand Down
4 changes: 2 additions & 2 deletions tests/Field/MoneyFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ protected function setUp(): void

$intlFormatterMock = $this->getMockBuilder(IntlFormatter::class)
->disableOriginalConstructor()
->setMethods(['formatCurrency'])
->onlyMethods(['formatCurrency'])
->getMock();
$intlFormatterMock->method('formatCurrency')->willReturnCallback(
function ($value) { return $value.'€'; }
);

$propertyAccessorMock = $this->getMockBuilder(PropertyAccessor::class)
->disableOriginalConstructor()
->setMethods(['isReadable', 'getValue'])
->onlyMethods(['isReadable', 'getValue'])
->getMock();
$propertyAccessorMock->method('isReadable')->willReturn(true);
$propertyAccessorMock->method('getValue')->willReturn('USD');
Expand Down
2 changes: 1 addition & 1 deletion tests/Field/TimeFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected function setUp(): void

$intlFormatterMock = $this->getMockBuilder(IntlFormatter::class)
->disableOriginalConstructor()
->setMethods(['formatDate', 'formatTime'])
->onlyMethods(['formatDate', 'formatTime'])
->getMock();
$intlFormatterMock->method('formatDate')->willReturnCallback(
static function ($value, ?string $dateFormat = 'medium', string $pattern = '', $timezone = null, string $calendar = 'gregorian', string $locale = null) { return sprintf('value: %s | dateFormat: %s | pattern: %s | timezone: %s | calendar: %s | locale: %s', $value instanceof \DateTimeInterface ? $value->format('Y-m-d H:i:s') : $value, $dateFormat, $pattern, $timezone, $calendar, $locale); }
Expand Down

0 comments on commit cd46dbd

Please sign in to comment.