Merge pull request #447 from acelaya/feature/fix-command-error

Feature/fix command error
This commit is contained in:
Alejandro Celaya 2019-08-08 14:58:23 +02:00 committed by GitHub
commit 9de0cf5c03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 98 additions and 3 deletions

View file

@ -20,8 +20,14 @@ rsync -av * "${builtcontent}" \
--exclude=bin/test \
--exclude=data/infra \
--exclude=data/travis \
--exclude=data/cache/* \
--exclude=data/log/* \
--exclude=data/locks/* \
--exclude=data/proxies/* \
--exclude=data/migrations_template.txt \
--exclude=data/GeoLite2-City.mmdb \
--exclude=data/GeoLite2-City.* \
--exclude=data/database.sqlite \
--exclude=data/shlink-tests.db \
--exclude=**/.gitignore \
--exclude=CHANGELOG.md \
--exclude=composer.lock \
@ -47,7 +53,6 @@ ${composerBin} install --no-dev --optimize-autoloader --apcu-autoloader --no-pro
# Delete development files
echo 'Deleting dev files...'
rm composer.*
rm -f data/database.sqlite
# Update shlink version in config
sed -i "s/%SHLINK_VERSION%/${version}/g" config/autoload/app_options.global.php

View file

@ -29,7 +29,7 @@
"lstrojny/functional-php": "^1.8",
"mikehaertl/phpwkhtmltopdf": "^2.2",
"monolog/monolog": "^1.21",
"ocramius/proxy-manager": "^2.0",
"ocramius/proxy-manager": "~2.2.2",
"phly/phly-event-dispatcher": "^1.0",
"predis/predis": "^1.1",
"shlinkio/shlink-installer": "^1.2.1",

View file

@ -3,6 +3,7 @@ declare(strict_types=1);
use Shlinkio\Shlink\Common\Cache\RedisFactory;
use Shlinkio\Shlink\Common\Lock\RetryLockStoreDelegatorFactory;
use Shlinkio\Shlink\Common\Logger\LoggerAwareDelegatorFactory;
use Symfony\Component\Lock;
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
@ -27,6 +28,9 @@ return [
Lock\Store\RedisStore::class => [
RetryLockStoreDelegatorFactory::class,
],
Lock\Factory::class => [
LoggerAwareDelegatorFactory::class,
],
],
],

View file

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Common\Logger;
use Psr\Container\ContainerInterface;
use Psr\Log;
class LoggerAwareDelegatorFactory
{
public function __invoke(ContainerInterface $container, $name, callable $callback)
{
$instance = $callback();
if ($instance instanceof Log\LoggerAwareInterface) {
$instance->setLogger($container->get(Log\LoggerInterface::class));
}
return $instance;
}
}

View file

@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Common\Logger;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Container\ContainerInterface;
use Psr\Log;
use Psr\Log\LoggerInterface;
use Shlinkio\Shlink\Common\Logger\LoggerAwareDelegatorFactory;
use stdClass;
class LoggerAwareDelegatorFactoryTest extends TestCase
{
/** @var LoggerAwareDelegatorFactory */
private $delegator;
/** @var ObjectProphecy */
private $container;
public function setUp(): void
{
$this->container = $this->prophesize(ContainerInterface::class);
$this->delegator = new LoggerAwareDelegatorFactory();
}
/**
* @test
* @dataProvider provideInstances
*/
public function injectsLoggerOnInstanceWhenImplementingLoggerAware($instance, int $expectedCalls): void
{
$callback = function () use ($instance) {
return $instance;
};
$getLogger = $this->container->get(Log\LoggerInterface::class)->willReturn(new Log\NullLogger());
$result = ($this->delegator)($this->container->reveal(), '', $callback);
$this->assertSame($instance, $result);
$getLogger->shouldHaveBeenCalledTimes($expectedCalls);
}
public function provideInstances(): iterable
{
yield 'no logger aware' => [new stdClass(), 0];
yield 'logger aware' => [new class implements Log\LoggerAwareInterface {
public function setLogger(LoggerInterface $logger): void
{
Assert::assertInstanceOf(Log\NullLogger::class, $logger);
}
}, 1];
}
}

View file

@ -5,6 +5,7 @@ namespace Shlinkio\Shlink\EventDispatcher;
use Phly\EventDispatcher as Phly;
use Psr\EventDispatcher as Psr;
use Zend\ServiceManager\Proxy\LazyServiceFactory;
return [
@ -21,6 +22,16 @@ return [
'aliases' => [
Psr\EventDispatcherInterface::class => Phly\EventDispatcher::class,
],
'delegators' => [
Psr\ListenerProviderInterface::class => [
LazyServiceFactory::class,
],
],
'lazy_services' => [
'class_map' => [
Psr\ListenerProviderInterface::class => Psr\ListenerProviderInterface::class,
],
],
],
];