diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 260b50e..e3e3e1d 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -8,9 +8,12 @@ on: jobs: phpunit: - name: "PHPUnit tests" - runs-on: "ubuntu-latest" + strategy: + matrix: + php-versions: ['7.3', '7.4'] + + name: PHPUnit tests on PHP ${{ matrix.php-versions }} steps: - name: "Checkout" @@ -20,7 +23,8 @@ jobs: uses: "shivammathur/setup-php@v2" with: coverage: "pcov" - php-version: "7.3" + php-version: ${{ matrix.php-versions }} + extensions: intl-60.3 ini-values: memory_limit=-1 - name: "Cache dependencies" diff --git a/CHANGELOG.md b/CHANGELOG.md index b166f4b..29aa536 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,29 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## 2.1.1 - 2020-11-09 + +### Changed + +- [#31](https://github.com/phly/PhlyBlog/pull/31) changes the `Compiler` to implement `EventsCapableInterface` instead of `EventManagerAwareInterface` (the latter is a superset of the former). Doing so ensures that any initializers for `EventManagerAwareInterface` do not trigger, which prevents double-injection of the `EventManager` instance, and thus prevents overwriting any listeners attached via delegator factories. The `setEventManager()` method is still defined. + + +----- + +### Release Notes for [2.1.1](https://github.com/phly/PhlyBlog/milestone/7) + +2.1.x bugfix release (patch) + +### 2.1.1 + +- Total issues resolved: **1** +- Total pull requests resolved: **1** +- Total contributors: **2** + +#### bug + + - [31: Make Compiler EventsCapable instead of EventManagerAware](https://github.com/phly/PhlyBlog/pull/31) thanks to @weierophinney and @vrkansagara + ## 2.1.0 - 2020-11-04 ### Added diff --git a/src/Compiler.php b/src/Compiler.php index 0960350..f1b26d7 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -5,18 +5,22 @@ use DateTime; use DateTimeZone; use Laminas\EventManager\EventManager; -use Laminas\EventManager\EventManagerAwareInterface; use Laminas\EventManager\EventManagerInterface; +use Laminas\EventManager\EventsCapableInterface; use RuntimeException; -class Compiler implements EventManagerAwareInterface +class Compiler implements EventsCapableInterface { protected $events; protected $files; - public function __construct(Compiler\PhpFileFilter $files) + public function __construct(Compiler\PhpFileFilter $files, ?EventManagerInterface $eventManager = null) { $this->files = $files; + + if ($eventManager) { + $this->setEventManager($eventManager); + } } public function setEventManager(EventManagerInterface $events) diff --git a/src/CompilerFactory.php b/src/CompilerFactory.php index 43df3a4..d8694bd 100644 --- a/src/CompilerFactory.php +++ b/src/CompilerFactory.php @@ -2,6 +2,7 @@ namespace PhlyBlog; +use Laminas\EventManager\EventManagerInterface; use PhlyBlog\Compiler\PhpFileFilter; use Psr\Container\ContainerInterface; @@ -13,7 +14,8 @@ public function __invoke(ContainerInterface $container): Compiler $config = $config['blog'] ?? []; return new Compiler( - new PhpFileFilter($config['posts_path'] ?? getcwd() . '/data/blog/') + new PhpFileFilter($config['posts_path'] ?? getcwd() . '/data/blog/'), + $container->get(EventManagerInterface::class) ); } } diff --git a/test/CompilerFactoryTest.php b/test/CompilerFactoryTest.php index 7254294..b577514 100644 --- a/test/CompilerFactoryTest.php +++ b/test/CompilerFactoryTest.php @@ -3,8 +3,10 @@ namespace PhlyBlogTest; use InvalidArgumentException; -use Laminas\EventManager\EventManagerAwareInterface; +use Laminas\EventManager\EventManagerInterface; +use Laminas\EventManager\EventsCapableInterface; use PhlyBlog\CompilerFactory; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -18,6 +20,22 @@ public function defaultConfigurationProvider(): iterable yield 'empty posts_path config' => [true, ['blog' => ['posts_path' => null]]]; } + public function prepareContainerRetrievalExpectations(MockObject $container, array $expectations): void + { + $arguments = []; + $services = []; + foreach ($expectations as $name => $service) { + $arguments[] = [$name]; + $services[] = $service; + } + + $container + ->expects($this->exactly(count($expectations))) + ->method('get') + ->withConsecutive(...$arguments) + ->willReturnOnConsecutiveCalls(...$services); + } + /** * @dataProvider defaultConfigurationProvider */ @@ -25,6 +43,8 @@ public function testFactoryUsesDefaultsWhenNoConfigurationPresent( bool $hasConfig, ?array $config ): void { + $containerServices = []; + $container = $this->createMock(ContainerInterface::class); $container ->expects($this->once()) @@ -33,15 +53,12 @@ public function testFactoryUsesDefaultsWhenNoConfigurationPresent( ->willReturn($hasConfig); if ($hasConfig) { - $container - ->expects($this->once()) - ->method('get') - ->with('config') - ->willReturn($config); + $containerServices['config'] = $config; } $factory = new CompilerFactory(); + $this->prepareContainerRetrievalExpectations($container, $containerServices); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage(getcwd() . '/data/blog'); $factory($container); @@ -56,18 +73,19 @@ public function testFactoryUsesConfigurationToProduceCompilerWhenPresent(): void ->with('config') ->willReturn(true); - $container - ->expects($this->once()) - ->method('get') - ->with('config') - ->willReturn([ + $containerServices = [ + 'config' => [ 'blog' => [ 'posts_path' => __DIR__, ], - ]); + ], + EventManagerInterface::class => $this->createMock(EventManagerInterface::class), + ]; + + $this->prepareContainerRetrievalExpectations($container, $containerServices); $factory = new CompilerFactory(); - $this->assertInstanceOf(EventManagerAwareInterface::class, $factory($container)); + $this->assertInstanceOf(EventsCapableInterface::class, $factory($container)); } }