Skip to content

Upgrade PHP Code Sniffer, resolve PHPUnit deprecations #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 13, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- name: Run PHPUnit Tests
uses: php-actions/phpunit@v3
with:
args: --colors=always --testdox tests
args: --testdox tests
bootstrap: vendor/autoload.php
test_suffix: "Test.php" #workaround for https://github.com/php-actions/phpunit/pull/64
php_version: "8.3"
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"league/commonmark": "^2.3",
"nette/php-generator": "^4.0.0",
"psr/log": "^3.0.0",
"squizlabs/php_codesniffer": "3.*",
"squizlabs/php_codesniffer": "^3.9.1",
"symfony/console": "^6.1",
"twig/markdown-extra": "^3.4",
"twig/twig": "^3.0.0"
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Builder/MeetupCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function count(): int
return count($this->array);
}

public function append(MeetupEntry $meetup)
public function append(MeetupEntry $meetup): void
{
$this->array[] = $meetup;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/Processor/HTMLProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

abstract class HTMLProcessor extends AbstractProcessor
{
protected function writeHtml(string $html, string $filename, DateTimeImmutable $modifiedTime = null)
protected function writeHtml(string $html, string $filename, DateTimeImmutable $modifiedTime = null): void
{
$destination = "$this->outputDirectory/$filename";
$path = substr($destination, 0, strlen(basename($destination)) * -1);
Expand Down
1 change: 0 additions & 1 deletion src/Builder/Processor/HomepageProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use DateTimeImmutable;
use MergePHP\Website\Builder\MeetupCollection;
use MergePHP\Website\Meetups;
use Psr\Log\LoggerInterface;
use Twig\Environment;

Expand Down
1 change: 0 additions & 1 deletion src/Builder/Processor/MissingLinkProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function __construct(
public function run(): void
{
$this->logger->info('Checking for missing YouTube links');
$buckets = [];

foreach ($this->meetups->withOnlyPast() as $meetup) {
if ($meetup->instance->getYouTubeLink() === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/SiteBuilderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class SiteBuilderService
{
protected const APP_ROOT = __DIR__ . '/../..';
protected const string APP_ROOT = __DIR__ . '/../..';
private Environment $twig;

public function __construct(protected string $outputDirectory, protected LoggerInterface $logger)
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/MeetupGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(public string $directory)
}
}

protected const SUGGESTED_DATE_FORMAT = 'Y-m-d';
protected const string SUGGESTED_DATE_FORMAT = 'Y-m-d';

public function getSuggestedDate(string $baseDate = 'now'): string
{
Expand Down
36 changes: 13 additions & 23 deletions tests/AbstractMeetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,51 @@

use DateTimeImmutable;
use MergePHP\Website\AbstractMeetup;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Tests\fixtures\TestMeetup;

class AbstractMeetupTest extends TestCase
{
private function generateMock(string $title): AbstractMeetup|MockObject
{
$mock = $this->getMockForAbstractClass(AbstractMeetup::class);
$mock->method('getTitle')->willReturn($title);
return $mock;
}

public function testItGeneratesASlugIgnoringEmojis(): void
{
$mock = $this->generateMock('50 Ways To Leave Your ♥er');
$meetup = new TestMeetup('50 Ways To Leave Your ♥er');

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

public function testItGeneratesASlugWithoutConsecutiveDashes(): void
{
$mock = $this->generateMock('First Part - Second Part');
$meetup = new TestMeetup('First Part - Second Part');

$this->assertEquals('first-part-second-part', $mock->getSlug());
$this->assertEquals('first-part-second-part', $meetup->getSlug());
}

public function testItGeneratesASlugThatDoesNotStartOrEndWithADash(): void
{
$mock = $this->generateMock('@ slug !');
$meetup = new TestMeetup('@ slug !');

$this->assertEquals('slug', $mock->getSlug());
$this->assertEquals('slug', $meetup->getSlug());
}

public function testItGeneratesASlugThatDoesNotReallyDoWellWithAccentedCharacters(): void
{
$mock = $this->generateMock('slúg');
$meetup = new TestMeetup('slúg');

$this->assertEquals('sl-g', $mock->getSlug());
$this->assertEquals('sl-g', $meetup->getSlug());
}

public function testItReturnsADefaultImageUrlOnlyWhenTheImageIsNotDefined(): void
{
$mock = $this->getMockForAbstractClass(AbstractMeetup::class);
$meetup = new TestMeetup('');

$this->assertEquals(
'/images/placeholder.webp',
$mock->getImage(),
);
$this->assertEquals('/images/placeholder.webp', $meetup->getImage());
}

public function testItAllowsANullYouTubeLink(): void
{
$mock = $this->getMockForAbstractClass(AbstractMeetup::class);
$meetup = new TestMeetup('');

$this->assertNull($mock->getYouTubeLink());
$this->assertNull($meetup->getYouTubeLink());
}

public function testItAllowsTheImageAndYouTubeLinkToBeOverridden(): void
Expand Down
42 changes: 31 additions & 11 deletions tests/Builder/Processor/RssFeedProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

class RssFeedProcessorTest extends TestCase
{
private const MEETUP_DATE_STRING = '2000-01-01T00:00:00+00:00';
private const MODIFIED_DATE_STRING = '2000-01-02T00:00:00+00:00';
private const EXPECTED_FILENAME = 'vfs://root/atom.xml';
private const FIXTURES_DIR = __DIR__ . '/../../fixtures/';
public const string MEETUP_DATE_STRING = '2000-01-01T00:00:00+00:00';
private const string MODIFIED_DATE_STRING = '2000-01-02T00:00:00+00:00';
private const string EXPECTED_FILENAME = 'vfs://root/atom.xml';
private const string FIXTURES_DIR = __DIR__ . '/../../fixtures/';

public function setUp(): void
{
Expand Down Expand Up @@ -76,12 +76,32 @@ public function testItIgnoresTheMeetupImageURL(): void

private function generateMeetup(string $description = 'Example description'): AbstractMeetup
{
$mock = $this->getMockForAbstractClass(AbstractMeetup::class);
$mock->method('getTitle')->willReturn('Example Meetup');
$mock->method('getDescription')->willReturn($description);
$mock->method('getDateTime')->willReturn(new DateTimeImmutable(RssFeedProcessorTest::MEETUP_DATE_STRING));
$mock->method('getSpeakerName')->willReturn('Speaker Name');
$mock->method('getSpeakerBio')->willReturn('Speaker Bio');
return $mock;
return new class ($description) extends AbstractMeetup
{
public function __construct(private readonly string $description)
{
}

public function getTitle(): string
{
return 'Example Meetup';
}
public function getDescription(): string
{
return $this->description;
}
public function getDateTime(): DateTimeImmutable
{
return new DateTimeImmutable(RssFeedProcessorTest::MEETUP_DATE_STRING);
}
public function getSpeakerName(): string
{
return 'Speaker Name';
}
public function getSpeakerBio(): string
{
return 'Speaker Bio';
}
};
}
}
38 changes: 25 additions & 13 deletions tests/Generator/MeetupGeneratorCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,26 @@
class MeetupGeneratorCommandTest extends TestCase
{
// generate args simulate what the user types in to the command line
private const GENERATE_1_ARGS = ['Title', 'Description', null , 'Name', 'Bio', null];
private const GENERATE_2_ARGS = ['Title', 'Description', '2023-01-01', 'Name', 'Bio', null];
private const GENERATE_3_ARGS = ['Title', 'Description', '2023-01-01', 'Name', 'Bio', 'https://example.com/f.jpg'];
private const array GENERATE_1_ARGS = ['Title', 'Description', null , 'Name', 'Bio', null];
private const array GENERATE_2_ARGS = ['Title', 'Description', '2023-01-01', 'Name', 'Bio', null];
private const array GENERATE_3_ARGS = [
'Title',
'Description',
'2023-01-01',
'Name',
'Bio',
'https://example.com/f.jpg'
];
// command args are what the generator command expects to be called with given a certain set of generate args
private const COMMAND_1_2_ARGS = ['Title', 'Description', '2023-01-01', 'Name', 'Bio', null];
private const COMMAND_3_ARGS = ['Title', 'Description', '2023-01-01', 'Name', 'Bio', 'https://example.com/f.jpg'];
private const array COMMAND_1_2_ARGS = ['Title', 'Description', '2023-01-01', 'Name', 'Bio', null];
private const array COMMAND_3_ARGS = [
'Title',
'Description',
'2023-01-01',
'Name',
'Bio',
'https://example.com/f.jpg'
];

private CommandTester $commandTester;

Expand All @@ -32,14 +46,12 @@ public function setUp(): void
$response = new MeetupGeneratorResponse('foo', 123);
$service = $this->createMock(MeetupGeneratorService::class);
$service->method('getSuggestedDate')->willReturn('2023-01-01');
$service->method('generate')->will(
$this->returnValueMap(
[
// arg1, arg2, arg3, arg4, arg5, arg6, return
[...self::COMMAND_1_2_ARGS, $response],
[...self::COMMAND_3_ARGS, $response],
]
)
$service->method('generate')->willReturnMap(
[
// arg1, arg2, arg3, arg4, arg5, arg6, return
[...self::COMMAND_1_2_ARGS, $response],
[...self::COMMAND_3_ARGS, $response],
]
);

$application = new Application();
Expand Down
2 changes: 1 addition & 1 deletion tests/Generator/MeetupGeneratorServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class MeetupGeneratorServiceTest extends TestCase
{
private MeetupGeneratorService $generator;
private const FIXTURES_DIR = __DIR__ . '/../fixtures/';
private const string FIXTURES_DIR = __DIR__ . '/../fixtures/';

public function setUp(): void
{
Expand Down
38 changes: 38 additions & 0 deletions tests/fixtures/TestMeetup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Tests\fixtures;

use DateTimeImmutable;
use MergePHP\Website\AbstractMeetup;

class TestMeetup extends AbstractMeetup
{
public function __construct(private readonly string $title)
{
}

public function getTitle(): string
{
return $this->title;
}

public function getDescription(): string
{
return 'Description';
}

public function getDateTime(): DateTimeImmutable
{
return new DateTimeImmutable();
}

public function getSpeakerName(): string
{
return 'Speaker name';
}

public function getSpeakerBio(): string
{
return 'Speaker bio';
}
}