From a75e1d0cbd0cdbb51dc20eac96caa01f29fb9cfc Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 4 Nov 2020 18:53:17 +0000 Subject: [PATCH 1/7] Bumps changelog version to 2.1.1 Updates the CHANGELOG.md file to add a changelog entry for a new 2.1.1 version. --- CHANGELOG.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b166f4b..97774f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,28 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## 2.1.1 - TBD + +### Added + +- Nothing. + +### Changed + +- Nothing. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + ## 2.1.0 - 2020-11-04 ### Added From 46d7ec59da22218c95b3a246b7475a0a01884776 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 4 Nov 2020 15:30:24 -0600 Subject: [PATCH 2/7] qa: adds intl to list of required extensions when running tests --- .github/workflows/phpunit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 260b50e..0a81c4d 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -21,6 +21,7 @@ jobs: with: coverage: "pcov" php-version: "7.3" + extensions: intl ini-values: memory_limit=-1 - name: "Cache dependencies" From 3b68551bd09635b7e70dfabcf29e63993576c52b Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 4 Nov 2020 15:37:25 -0600 Subject: [PATCH 3/7] qa: pin intl extension to ICU 60.3 Doesn't require compilation, and known to work with `act`. --- .github/workflows/phpunit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 0a81c4d..07fa5f1 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -21,7 +21,7 @@ jobs: with: coverage: "pcov" php-version: "7.3" - extensions: intl + extensions: intl-60.3 ini-values: memory_limit=-1 - name: "Cache dependencies" From cc5f4888ce3e9904557cfb1c48bf1696855d6868 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 4 Nov 2020 15:46:54 -0600 Subject: [PATCH 4/7] qa: add build matrix for supported PHP versions --- .github/workflows/phpunit.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 07fa5f1..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,7 @@ 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 From 15fd5ddda09ccac03cce4ef7666920cba223043f Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 9 Nov 2020 08:42:44 -0600 Subject: [PATCH 5/7] fix: do not mark Compiler as EventsManagerAware, but rather EventsCapable laminas-mvc creates an initializer for classes marked EventsManagerAware. Since initializers run AFTER delegators, if you attempt to add any listeners via a delegator factory, they then get overwritten when a new EM instance is injected by the initializer. Additionally, this patch modifies the `Compiler` to optionally accept an EM instance to the constructor, and the `CompilerFactory` to pull one from the container when creating an instance. --- src/Compiler.php | 10 +++++--- src/CompilerFactory.php | 4 +++- test/CompilerFactoryTest.php | 44 +++++++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 17 deletions(-) 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)); } } From 32c1d756c972a66c5d736592181b5708acffd329 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 9 Nov 2020 08:47:00 -0600 Subject: [PATCH 6/7] docs: adds CHANGELOG entry for #31 Signed-off-by: Matthew Weier O'Phinney --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97774f2..74c09dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file, in reverse ### Changed -- Nothing. +- [#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. ### Deprecated From e6d974ac1b5b729b2e8a7241b0948ae0632d2b1f Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 9 Nov 2020 14:53:01 +0000 Subject: [PATCH 7/7] 2.1.1 readiness Updates the CHANGELOG.md to set the release date. --- CHANGELOG.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74c09dd..29aa536 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,27 +2,28 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.1.1 - TBD - -### Added - -- Nothing. +## 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. -### Deprecated -- Nothing. +----- -### Removed +### Release Notes for [2.1.1](https://github.com/phly/PhlyBlog/milestone/7) -- Nothing. +2.1.x bugfix release (patch) -### Fixed +### 2.1.1 + +- Total issues resolved: **1** +- Total pull requests resolved: **1** +- Total contributors: **2** + +#### bug -- Nothing. + - [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