Skip to content

Commit

Permalink
🐛 Source should be unique for each feedProvider
Browse files Browse the repository at this point in the history
The tagged locator uses the source as an index to retrieve the
corresponding feedprovider. If there is a source that points to multiple
services the locator fetches the first one it encounters. This results
in the second feed not being fetched.

AFAIK Symfony does not provide a locator that can fetch multiple
services by index.

There are multiple solutions to this problem:

- We could have the php.watch feed provider fetch both feeds.
- We could keep both the providers and give them a unique source.

In this commit we decided on the latter. We introduce two new sources,
php.watch-changes and php.watch-news.
  • Loading branch information
LVoogd committed Jan 7, 2024
1 parent 31c4ad8 commit 5bc4643
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
37 changes: 37 additions & 0 deletions migrations/Version20231231123959.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231231123959 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// Delete 'php.watch' source
$this->addSql("DELETE FROM sources WHERE id='9930338f-d07c-4030-ade6-5ac19821e554'");

$this->addSql("INSERT INTO sources (id, name) VALUES ('a9ba164c-5a86-43d2-b024-f38e6a227a41', 'php.watch-news')");
$this->addSql("INSERT INTO sources (id, name) VALUES ('18929b96-79a4-44bf-8d97-f442851b7b44', 'php.watch-changes')");

}

public function down(Schema $schema): void
{
$this->addSql("INSERT INTO sources (id, name) VALUES ('9930338f-d07c-4030-ade6-5ac19821e554','php.watch')");

$this->addSql("DELETE FROM sources WHERE id='a9ba164c-5a86-43d2-b024-f38e6a227a41'");
$this->addSql("DELETE FROM sources WHERE id='18929b96-79a4-44bf-8d97-f442851b7b44'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(

public static function getSource(): string
{
return 'php.watch';
return 'php.watch-changes';
}

public function fetchFeedItems(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(

public static function getSource(): string
{
return 'php.watch';
return 'php.watch-news';
}

public function fetchFeedItems(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ public function it_should_fetch_the_external_feed(): void
self::assertSame("Change type: Change Target version: 8.4 ", $feedItems[0]->summary);
self::assertSame("https://php.watch/versions/8.4/password_hash-bcrypt-cost-increase", $feedItems[0]->url);
self::assertEquals(\DateTime::createFromFormat('Y-m-d H:i', '2023-10-17 10:44'), $feedItems[0]->updated);
self::assertSame('php.watch', $feedItems[0]->source);
self::assertSame('php.watch-changes', $feedItems[0]->source);

self::assertSame("phpinfo: Show PHP Integer Size information", $feedItems[1]->title);
self::assertSame("Change type: New Feature Target version: 8.4 ", $feedItems[1]->summary);
self::assertSame("https://php.watch/versions/8.4/phpinfo-int-size", $feedItems[1]->url);
self::assertEquals(\DateTime::createFromFormat('Y-m-d H:i', '2023-09-23 10:44'), $feedItems[1]->updated);
self::assertSame('php.watch', $feedItems[1]->source);
self::assertSame('php.watch-changes', $feedItems[1]->source);

self::assertSame("Class constant type declarations in some PHP extension classes", $feedItems[2]->title);
self::assertSame("Change type: Change Target version: 8.3 ", $feedItems[2]->summary);
self::assertSame("https://php.watch/versions/8.3/ext-class-constant-type-declarations", $feedItems[2]->url);
self::assertEquals(\DateTime::createFromFormat('Y-m-d H:i', '2023-08-22 10:44'), $feedItems[2]->updated);
self::assertSame('php.watch', $feedItems[2]->source);
self::assertSame('php.watch-changes', $feedItems[2]->source);
}

/**
Expand All @@ -124,7 +124,7 @@ public function it_should_fetch_the_external_feed(): void
public function it_should_get_the_source_name(): void
{
// Assert
self::assertSame('php.watch', PhpWatchChangesFeedProvider::getSource());
self::assertSame('php.watch-changes', PhpWatchChangesFeedProvider::getSource());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ public function it_should_fetch_the_external_feed(): void
self::assertSame("The first release candidate (RC1) for PHP 8.3 is now released, along with Windows QA builds and Docker images.", $feedItems[0]->summary);
self::assertSame("https://php.watch/news/2023/08/php83-rc1-released", $feedItems[0]->url);
self::assertEquals(\DateTime::createFromFormat('Y-m-d H:i', '2023-08-31 10:44'), $feedItems[0]->updated);
self::assertSame('php.watch', $feedItems[0]->source);
self::assertSame('php.watch-news', $feedItems[0]->source);

self::assertSame("PHP 8.3 Beta Released", $feedItems[1]->title);
self::assertSame("The first beta release of the upcoming PHP 8.3 is released.", $feedItems[1]->summary);
self::assertSame("https://php.watch/news/2023/07/php83-beta-released", $feedItems[1]->url);
self::assertEquals(\DateTime::createFromFormat('Y-m-d H:i', '2023-07-24 10:44'), $feedItems[1]->updated);
self::assertSame('php.watch', $feedItems[1]->source);
self::assertSame('php.watch-news', $feedItems[1]->source);
}

/**
Expand All @@ -98,7 +98,7 @@ public function it_should_fetch_the_external_feed(): void
public function it_should_get_the_source_name(): void
{
// Assert
self::assertSame('php.watch', PhpWatchChangesFeedProvider::getSource());
self::assertSame('php.watch-news', PhpWatchNewsFeedProvider::getSource());
}

/**
Expand Down

0 comments on commit 5bc4643

Please sign in to comment.