Skip to content

Merge release 2.1.1 into 2.2.x #32

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

Open
wants to merge 7 commits into
base: 2.2.x
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/CompilerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PhlyBlog;

use Laminas\EventManager\EventManagerInterface;
use PhlyBlog\Compiler\PhpFileFilter;
use Psr\Container\ContainerInterface;

Expand All @@ -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)
);
}
}
44 changes: 31 additions & 13 deletions test/CompilerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,13 +20,31 @@ 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
*/
public function testFactoryUsesDefaultsWhenNoConfigurationPresent(
bool $hasConfig,
?array $config
): void {
$containerServices = [];

$container = $this->createMock(ContainerInterface::class);
$container
->expects($this->once())
Expand All @@ -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);
Expand All @@ -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));
}
}