Skip to content

Commit 41eda0c

Browse files
committed
Resolve PHPUnit deprecations
* Remove calls to getMockForAbstractClass(), see [1] * Remove calls to PHPUnit method returnValueMap, see [2] * Work around issue with deprecated test_suffix CSV, see [3] * Do not explicitly add `-colors=always` since it is already added [4] [1]: sebastianbergmann/phpunit#5241 [2]: sebastianbergmann/phpunit#5423 [3]: php-actions/phpunit#64 [4]: https://github.com/php-actions/phpunit/blob/c27e49b5fd8cd59d032b7b4441d2e15f23cf6519/phpunit-action.bash#L154
1 parent d24a3d4 commit 41eda0c

File tree

5 files changed

+87
-40
lines changed

5 files changed

+87
-40
lines changed

Diff for: .github/workflows/test.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
- name: Run PHPUnit Tests
2323
uses: php-actions/phpunit@v3
2424
with:
25-
args: --colors=always --testdox tests
25+
args: --testdox tests
2626
bootstrap: vendor/autoload.php
27+
test_suffix: "Test.php" #workaround for https://github.com/php-actions/phpunit/pull/64
2728
php_version: "8.3"

Diff for: tests/AbstractMeetupTest.php

+13-23
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,51 @@
66

77
use DateTimeImmutable;
88
use MergePHP\Website\AbstractMeetup;
9-
use PHPUnit\Framework\MockObject\MockObject;
109
use PHPUnit\Framework\TestCase;
10+
use Tests\fixtures\TestMeetup;
1111

1212
class AbstractMeetupTest extends TestCase
1313
{
14-
private function generateMock(string $title): AbstractMeetup|MockObject
15-
{
16-
$mock = $this->getMockForAbstractClass(AbstractMeetup::class);
17-
$mock->method('getTitle')->willReturn($title);
18-
return $mock;
19-
}
20-
2114
public function testItGeneratesASlugIgnoringEmojis(): void
2215
{
23-
$mock = $this->generateMock('50 Ways To Leave Your ♥er');
16+
$meetup = new TestMeetup('50 Ways To Leave Your ♥er');
2417

25-
$this->assertEquals('50-ways-to-leave-your-er', $mock->getSlug());
18+
$this->assertEquals('50-ways-to-leave-your-er', $meetup->getSlug());
2619
}
2720

2821
public function testItGeneratesASlugWithoutConsecutiveDashes(): void
2922
{
30-
$mock = $this->generateMock('First Part - Second Part');
23+
$meetup = new TestMeetup('First Part - Second Part');
3124

32-
$this->assertEquals('first-part-second-part', $mock->getSlug());
25+
$this->assertEquals('first-part-second-part', $meetup->getSlug());
3326
}
3427

3528
public function testItGeneratesASlugThatDoesNotStartOrEndWithADash(): void
3629
{
37-
$mock = $this->generateMock('@ slug !');
30+
$meetup = new TestMeetup('@ slug !');
3831

39-
$this->assertEquals('slug', $mock->getSlug());
32+
$this->assertEquals('slug', $meetup->getSlug());
4033
}
4134

4235
public function testItGeneratesASlugThatDoesNotReallyDoWellWithAccentedCharacters(): void
4336
{
44-
$mock = $this->generateMock('slúg');
37+
$meetup = new TestMeetup('slúg');
4538

46-
$this->assertEquals('sl-g', $mock->getSlug());
39+
$this->assertEquals('sl-g', $meetup->getSlug());
4740
}
4841

4942
public function testItReturnsADefaultImageUrlOnlyWhenTheImageIsNotDefined(): void
5043
{
51-
$mock = $this->getMockForAbstractClass(AbstractMeetup::class);
44+
$meetup = new TestMeetup('');
5245

53-
$this->assertEquals(
54-
'/images/placeholder.webp',
55-
$mock->getImage(),
56-
);
46+
$this->assertEquals('/images/placeholder.webp', $meetup->getImage());
5747
}
5848

5949
public function testItAllowsANullYouTubeLink(): void
6050
{
61-
$mock = $this->getMockForAbstractClass(AbstractMeetup::class);
51+
$meetup = new TestMeetup('');
6252

63-
$this->assertNull($mock->getYouTubeLink());
53+
$this->assertNull($meetup->getYouTubeLink());
6454
}
6555

6656
public function testItAllowsTheImageAndYouTubeLinkToBeOverridden(): void

Diff for: tests/Builder/Processor/RssFeedProcessorTest.php

+28-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class RssFeedProcessorTest extends TestCase
1919
{
20-
private const string MEETUP_DATE_STRING = '2000-01-01T00:00:00+00:00';
20+
public const string MEETUP_DATE_STRING = '2000-01-01T00:00:00+00:00';
2121
private const string MODIFIED_DATE_STRING = '2000-01-02T00:00:00+00:00';
2222
private const string EXPECTED_FILENAME = 'vfs://root/atom.xml';
2323
private const string FIXTURES_DIR = __DIR__ . '/../../fixtures/';
@@ -76,12 +76,32 @@ public function testItIgnoresTheMeetupImageURL(): void
7676

7777
private function generateMeetup(string $description = 'Example description'): AbstractMeetup
7878
{
79-
$mock = $this->getMockForAbstractClass(AbstractMeetup::class);
80-
$mock->method('getTitle')->willReturn('Example Meetup');
81-
$mock->method('getDescription')->willReturn($description);
82-
$mock->method('getDateTime')->willReturn(new DateTimeImmutable(RssFeedProcessorTest::MEETUP_DATE_STRING));
83-
$mock->method('getSpeakerName')->willReturn('Speaker Name');
84-
$mock->method('getSpeakerBio')->willReturn('Speaker Bio');
85-
return $mock;
79+
return new class ($description) extends AbstractMeetup
80+
{
81+
public function __construct(private readonly string $description)
82+
{
83+
}
84+
85+
public function getTitle(): string
86+
{
87+
return 'Example Meetup';
88+
}
89+
public function getDescription(): string
90+
{
91+
return $this->description;
92+
}
93+
public function getDateTime(): DateTimeImmutable
94+
{
95+
return new DateTimeImmutable(RssFeedProcessorTest::MEETUP_DATE_STRING);
96+
}
97+
public function getSpeakerName(): string
98+
{
99+
return 'Speaker Name';
100+
}
101+
public function getSpeakerBio(): string
102+
{
103+
return 'Speaker Bio';
104+
}
105+
};
86106
}
87107
}

Diff for: tests/Generator/MeetupGeneratorCommandTest.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@ public function setUp(): void
4646
$response = new MeetupGeneratorResponse('foo', 123);
4747
$service = $this->createMock(MeetupGeneratorService::class);
4848
$service->method('getSuggestedDate')->willReturn('2023-01-01');
49-
$service->method('generate')->will(
50-
$this->returnValueMap(
51-
[
52-
// arg1, arg2, arg3, arg4, arg5, arg6, return
53-
[...self::COMMAND_1_2_ARGS, $response],
54-
[...self::COMMAND_3_ARGS, $response],
55-
]
56-
)
49+
$service->method('generate')->willReturnMap(
50+
[
51+
// arg1, arg2, arg3, arg4, arg5, arg6, return
52+
[...self::COMMAND_1_2_ARGS, $response],
53+
[...self::COMMAND_3_ARGS, $response],
54+
]
5755
);
5856

5957
$application = new Application();

Diff for: tests/fixtures/TestMeetup.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Tests\fixtures;
4+
5+
use DateTimeImmutable;
6+
use MergePHP\Website\AbstractMeetup;
7+
8+
class TestMeetup extends AbstractMeetup
9+
{
10+
public function __construct(private readonly string $title)
11+
{
12+
}
13+
14+
public function getTitle(): string
15+
{
16+
return $this->title;
17+
}
18+
19+
public function getDescription(): string
20+
{
21+
return 'Description';
22+
}
23+
24+
public function getDateTime(): DateTimeImmutable
25+
{
26+
return new DateTimeImmutable();
27+
}
28+
29+
public function getSpeakerName(): string
30+
{
31+
return 'Speaker name';
32+
}
33+
34+
public function getSpeakerBio(): string
35+
{
36+
return 'Speaker bio';
37+
}
38+
}

0 commit comments

Comments
 (0)