Skip to content

Commit

Permalink
Merge pull request shlinkio#15 from acelaya-forks/feature/swoole-factory
Browse files Browse the repository at this point in the history
Added factory that returns a helper to check if swoole is installed
  • Loading branch information
acelaya authored Dec 5, 2021
2 parents 7c31b34 + bd02bd5 commit 4bde8c5
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [1.4.0] - 2021-12-05
### Added
* Created new factory to tell if either swoole or openswoole are enabled

### Changed
* *Nothing*

### Deprecated
* *Nothing*

### Removed
* *Nothing*

### Fixed
* *Nothing*


## [1.3.1] - 2021-11-01
### Added
* *Nothing*
Expand Down
3 changes: 3 additions & 0 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public function __invoke(): array
return [

'dependencies' => [
'factories' => [
Factory\SwooleInstalledFactory::SWOOLE_INSTALLED => Factory\SwooleInstalledFactory::class,
],
'abstract_factories' => [
Factory\DottedAccessConfigAbstractFactory::class,
],
Expand Down
17 changes: 17 additions & 0 deletions src/Factory/SwooleInstalledFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Shlinkio\Shlink\Config\Factory;

use function extension_loaded;

class SwooleInstalledFactory
{
public const SWOOLE_INSTALLED = 'Shlinkio\Shlink\Config\SwooleInstalled';

public function __invoke(): callable
{
return static fn (): bool => extension_loaded('openswoole') || extension_loaded('swoole');
}
}
4 changes: 4 additions & 0 deletions test/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Config\ConfigProvider;
use Shlinkio\Shlink\Config\Factory\DottedAccessConfigAbstractFactory;
use Shlinkio\Shlink\Config\Factory\SwooleInstalledFactory;

class ConfigProviderTest extends TestCase
{
Expand All @@ -23,6 +24,9 @@ public function configIsReturned(): void
$config = ($this->configProvider)();
self::assertArrayHasKey('dependencies', $config);
self::assertEquals([
'factories' => [
SwooleInstalledFactory::SWOOLE_INSTALLED => SwooleInstalledFactory::class,
],
'abstract_factories' => [
DottedAccessConfigAbstractFactory::class,
],
Expand Down
26 changes: 26 additions & 0 deletions test/Factory/SwooleInstalledFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace ShlinkioTest\Shlink\Config\Factory;

use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Config\Factory\SwooleInstalledFactory;

class SwooleInstalledFactoryTest extends TestCase
{
private SwooleInstalledFactory $factory;

public function setUp(): void
{
$this->factory = new SwooleInstalledFactory();
}

/** @test */
public function properlyCreatesHelperFunction(): void
{
$func = ($this->factory)();

self::assertFalse($func());
}
}

0 comments on commit 4bde8c5

Please sign in to comment.