From cffd28a73b46fbd2e964961f919199b6a8a6860b Mon Sep 17 00:00:00 2001 From: Indra Gunawan Date: Sun, 8 Mar 2020 01:54:04 +0700 Subject: [PATCH] symfony 5 compatibility (#3) * symfony 5 compatibility --- .gitattributes | 3 ++ .gitignore | 2 ++ .travis.yml | 7 ++--- AbstractFacade.php | 6 ++-- CHANGELOG.md | 5 ++++ .../Compiler/AddFacadePass.php | 6 ++-- README.md | 11 ++++--- Tests/FacadeTest.php | 10 +++---- Tests/Fixtures/Kernel.php | 30 +++++++++++++++++++ Tests/IndragunawanFacadeBundleTest.php | 27 ++--------------- composer.json | 9 +++--- phpunit.xml.dist | 5 ++++ 12 files changed, 71 insertions(+), 50 deletions(-) create mode 100755 .gitattributes create mode 100755 Tests/Fixtures/Kernel.php diff --git a/.gitattributes b/.gitattributes new file mode 100755 index 0000000..ebb9287 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +/Tests export-ignore +/phpunit.xml.dist export-ignore +/.gitignore export-ignore diff --git a/.gitignore b/.gitignore index fb8281c..f5ef8ab 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ composer.lock composer.phar .php_cs.cache /build +.phpunit.result.cache +/var diff --git a/.travis.yml b/.travis.yml index e61f972..ecb8724 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,17 @@ language: php -sudo: false - cache: directories: - $HOME/.composer/cache -matrix: +jobs: include: - - php: '7.0' - php: '7.1' - php: '7.2' - php: '7.2' env: deps=low + - php: '7.3' + - php: '7.4' before_install: - composer self-update diff --git a/AbstractFacade.php b/AbstractFacade.php index a8723f4..9076586 100644 --- a/AbstractFacade.php +++ b/AbstractFacade.php @@ -22,8 +22,6 @@ abstract class AbstractFacade /** * Facade service container. - * - * @param ContainerInterface $container */ public static function setFacadeContainer(ContainerInterface $container) { @@ -41,7 +39,7 @@ abstract protected static function getFacadeAccessor(); * Handle dynamic calls to the service. * * @param string $method - * @param array $arguments + * @param array $arguments * * @return mixed * @@ -49,7 +47,7 @@ abstract protected static function getFacadeAccessor(); */ public static function __callStatic($method, $arguments) { - $class = get_called_class(); + $class = \get_called_class(); if (!static::$container->has($class)) { throw new \RuntimeException(sprintf('"%s" facade has not been register.', $class)); diff --git a/CHANGELOG.md b/CHANGELOG.md index 8004986..fe081c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +v0.2.0 +------ + +* Symfony 5 compatibility + v0.1.0 ------ diff --git a/DependencyInjection/Compiler/AddFacadePass.php b/DependencyInjection/Compiler/AddFacadePass.php index 72c965c..8eeb1e0 100644 --- a/DependencyInjection/Compiler/AddFacadePass.php +++ b/DependencyInjection/Compiler/AddFacadePass.php @@ -42,11 +42,11 @@ public function process(ContainerBuilder $container) $r->setAccessible(true); $ref = $r->invoke(null); - if (!is_string($ref)) { - throw new InvalidArgumentException(sprintf('Facade accessor must be string, "%s" given.', is_object($ref) ? get_class($ref) : gettype($ref))); + if (!\is_string($ref)) { + throw new InvalidArgumentException(sprintf('Facade accessor must be string, "%s" given.', \is_object($ref) ? \get_class($ref) : \gettype($ref))); } - $ref = is_string($ref) && 0 === strpos($ref, '@') ? substr($ref, 1) : $ref; + $ref = \is_string($ref) && 0 === strpos($ref, '@') ? substr($ref, 1) : $ref; $facades[$id] = new Reference($ref); } diff --git a/README.md b/README.md index c51bc29..7366ddb 100644 --- a/README.md +++ b/README.md @@ -7,17 +7,17 @@ [![Source](https://img.shields.io/badge/source-IndraGunawan%2Ffacade--bundle-blue.svg)](https://github.com/IndraGunawan/facade-bundle) [![Packagist](https://img.shields.io/badge/packagist-indragunawan%2Ffacade--bundle-blue.svg)](https://packagist.org/packages/indragunawan/facade-bundle) - Support Facades for Symfony service. thanks to: + - [Service Locator](https://symfony.com/blog/new-in-symfony-3-3-service-locators) - for making all the referenced facade service lazy-loaded. - [Service Autoconfiguration](https://symfony.com/blog/new-in-symfony-3-3-service-autoconfiguration) - for making all classes that extend `Indragunawan\FacadeBundle\AbstractFacade` class automatically tagged as facade. ## Documentation -* [Installation](#installation) -* [Creating Facade](#creating-facade) +- [Installation](#installation) +- [Creating Facade](#creating-facade) ### Installation @@ -32,8 +32,8 @@ If you install without using Symfony Flex, first add the bundle by using compose ### Creating Facade - To create a facade create a class that extends base `Indragunawan\FacadeBundle\AbstractFacade` class and implement the `getFacadeAccessor` method that returns the `service id`, support **private** and **public** service. + ```php expects($this->exactly(2)) ->method('has') - ->will($this->returnValueMap([ + ->willReturnMap([ [Foo::class, true], - ])) + ]) ; $container ->expects($this->exactly(2)) ->method('get') - ->will($this->returnValueMap([ + ->willReturnMap([ [Foo::class, new FooService()], - ])) + ]) ; AbstractFacade::setFacadeContainer($container); @@ -57,7 +57,7 @@ public function testNotRegisteredFacade() $container ->expects($this->once()) ->method('has') - ->will($this->returnValueMap([])) + ->willReturnMap([]) ; AbstractFacade::setFacadeContainer($container); diff --git a/Tests/Fixtures/Kernel.php b/Tests/Fixtures/Kernel.php new file mode 100755 index 0000000..306d5c9 --- /dev/null +++ b/Tests/Fixtures/Kernel.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Indragunawan\FacadeBundle\Tests\Fixtures; + +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\HttpKernel\Kernel as BaseKernel; + +final class Kernel extends BaseKernel +{ + public function registerBundles() + { + return [ + new \Indragunawan\FacadeBundle\IndragunawanFacadeBundle(), + ]; + } + + public function registerContainerConfiguration(LoaderInterface $loader) + { + return null; + } +} diff --git a/Tests/IndragunawanFacadeBundleTest.php b/Tests/IndragunawanFacadeBundleTest.php index 0716c00..4bd1c17 100644 --- a/Tests/IndragunawanFacadeBundleTest.php +++ b/Tests/IndragunawanFacadeBundleTest.php @@ -11,40 +11,19 @@ namespace Indragunawan\FacadeBundle\Tests; -use Indragunawan\FacadeBundle\IndragunawanFacadeBundle; -use PHPUnit\Framework\TestCase; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\DependencyInjection\ServiceLocator; -use Symfony\Component\HttpKernel\Kernel; /** * @author Indra Gunawan */ -class IndragunawanFacadeBundleTest extends TestCase +class IndragunawanFacadeBundleTest extends KernelTestCase { public function testBundle() { - $kernel = $this->getKernel(); - $kernel->boot(); + $kernel = $this->bootKernel(['environment' => 'test', 'debug' => true]); $this->assertTrue($kernel->getContainer()->has('indragunawan.facade.container')); $this->assertInstanceOf(ServiceLocator::class, $kernel->getContainer()->get('indragunawan.facade.container')); } - - protected function getKernel() - { - $kernel = $this - ->getMockBuilder(Kernel::class) - ->setMethods(['registerBundles']) - ->setConstructorArgs(['test', false]) - ->getMockForAbstractClass() - ; - $kernel->method('registerBundles') - ->will($this->returnValue([new IndragunawanFacadeBundle()])) - ; - $p = new \ReflectionProperty($kernel, 'rootDir'); - $p->setAccessible(true); - $p->setValue($kernel, sys_get_temp_dir()); - - return $kernel; - } } diff --git a/composer.json b/composer.json index 9697310..ced1d19 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "indragunawan/facade-bundle", - "description": "Support Facades for Symfony service.", + "description": "Support Facades for Symfony services.", "type": "symfony-bundle", "license": "MIT", "authors": [ @@ -19,12 +19,13 @@ ] }, "require": { - "php": "^7.0", + "php": "^7.1.3", "psr/container": "^1.0", - "symfony/framework-bundle": "^3.3 || ^4.0" + "symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0" }, "require-dev": { - "phpunit/phpunit": "^6.5" + "phpunit/phpunit": "^7.5.2 || ^8.0", + "symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0" }, "config": { "preferred-install": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5726949..7908ea1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,6 +6,11 @@ bootstrap="./vendor/autoload.php" colors="true"> + + + + + ./Tests