diff --git a/.docheader b/.docheader new file mode 100644 index 0000000..a31bfa1 --- /dev/null +++ b/.docheader @@ -0,0 +1,3 @@ +@copyright Copyright (c) 2016 bushbaby multimedia. (https://bushbaby.nl) +@author Bas Kamer +@license MIT diff --git a/.gitignore b/.gitignore index 8f4f944..df888b1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ composer.phar composer.lock phpunit.xml vendor/ +/.phpunit.result.cache +/.php_cs.cache +/build/ diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..4da2d9d --- /dev/null +++ b/.php_cs @@ -0,0 +1,18 @@ + + * @license MIT + */ + +declare(strict_types=1); + +$config = new Bsb\CS\Config(); +$config->getFinder()->in(__DIR__)->append(['.php_cs']); + +$cacheDir = \getenv('TRAVIS') ? \getenv('HOME') . '/.php-cs-fixer' : __DIR__; + +$config->setCacheFile($cacheDir . '/.php_cs.cache'); + +return $config; diff --git a/.travis.yml b/.travis.yml index 13774a5..1b53271 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,29 +1,42 @@ -sudo: false - language: php +cache: + directories: + - $HOME/.composer/cache + - $HOME/.php-cs-fixer + matrix: - fast_finish: true include: - - php: 5.5 - - php: 5.6 - - php: 7 - - php: hhvm - allow_failures: - - php: hhvm + - php: 7.2 + env: + - DEPENDENCIES="" + - EXECUTE_CS_CHECK=true + - TEST_COVERAGE=true + - php: 7.2 + env: + - DEPENDENCIES="--prefer-lowest --prefer-stable" + - php: 7.3 + env: + - DEPENDENCIES="" + - php: 7.3 + env: + - DEPENDENCIES="--prefer-lowest --prefer-stable" + - php: 7.4 + env: + - DEPENDENCIES="" + - php: 7.4 + env: + - DEPENDENCIES="--prefer-lowest --prefer-stable" before_script: + - mkdir -p "$HOME/.php-cs-fixer" - composer self-update - - composer install --prefer-source + - composer update $DEPENDENCIES script: - - vendor/bin/phpunit -c ./phpunit.xml - - vendor/bin/phpcs --standard=PSR2 ./src/ - -after_script: - - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover test/_build/logs/clover.xml + - mkdir -p build/logs + - if [[ $TEST_COVERAGE == 'true' ]]; then php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-clover ./build/logs/clover.xml; else ./vendor/bin/phpunit; fi + - if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run; fi -notifications: - irc: "irc.freenode.org#zftalk.modules" - email: false \ No newline at end of file +after_success: + - if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry php vendor/bin/php-coveralls -v; fi diff --git a/README.md b/README.md index a77e051..6c4aba5 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,29 @@ -# ZF2 ServiceManager Doctrine's ManagerRegistry +# Laminas ServiceManager Doctrine's ManagerRegistry -An implementation Doctrine's ManagerRegistry for zend-servicemanager. +An implementation Doctrine's ManagerRegistry for laminas/laminas-servicemanager. -Install +##### Install -``` +```bash composer require "bushbaby/doctrine-managerregistry-servicemanager" ``` Register ManagerRegistryFactory in the service manager. -``` -[ - 'factories' => [ - Doctrine\Common\Persistence\ManagerRegistry::class => BsbDoctrineRegistry\Container\ManagerRegistryFactory::class, - ], -] +```php +return [ + 'dependencies' => [ + 'factories' => [ + \Doctrine\Common\Persistence\ManagerRegistry::class => BsbDoctrineRegistry\Container\ManagerRegistryFactory::class, + ], + ], +]; ``` -Usage +##### Usage -``` +```php $managerName = 'orm_default'; /** @var \Doctrine\Common\Persistence\ManagerRegistry $managerRegistry */ @@ -33,4 +35,4 @@ $objectManager = $managerRegistry->getManager($managerName); /** @var ObjectRepository $repo */ $repo = $objectManager->getRepository(SomeEntity::class); -``` \ No newline at end of file +``` diff --git a/composer.json b/composer.json index d3f636d..0a8524d 100644 --- a/composer.json +++ b/composer.json @@ -1,30 +1,40 @@ { - "name": "bushbaby/doctrine-managerregistry-servicemanager", - "description": "An implementation of Doctrine's ManagerRegistry for the ZendFramework ServiceManager", - "require": { - "php": "^5.5 || ^7.0", - "zendframework/zend-servicemanager" : "^2.6 || ^3.0", - "doctrine/orm": "^2.4" - }, - "require-dev": { - "phpunit/phpunit": "^5.1", - "squizlabs/php_codesniffer": "^2.5" - }, - "autoload": { - "psr-4": { - "BsbDoctrineRegistry\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "BsbDoctrineRegistryTest\\": "test/src/" - } - }, - "license": "MIT", - "authors": [ - { - "name": "Bas Kamer", - "email": "bas@bushbaby.nl" - } - ] + "name": "bushbaby/doctrine-managerregistry-servicemanager", + "description": "An implementation of Doctrine's ManagerRegistry for the Laminas ServiceManager", + "require": { + "php": "^7.2", + "laminas/laminas-servicemanager": "^3.0", + "doctrine/orm": "^2.4" + }, + "require-dev": { + "bushbaby/php-cs-fixer-config": "^1.0", + "phpunit/phpunit": "^8.5", + "php-coveralls/php-coveralls": "^2.0" + }, + "autoload": { + "psr-4": { + "BsbDoctrineRegistry\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "BsbDoctrineRegistryTest\\": "test/" + } + }, + "license": "MIT", + "authors": [ + { + "name": "Bas Kamer", + "email": "baskamer@gmail.com" + } + ], + "scripts": { + "check": [ + "@cs", + "@test" + ], + "cs": "php-cs-fixer fix -v --diff --dry-run", + "cs-fix": "php-cs-fixer fix -v --diff", + "test": "phpunit" + } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..d94c080 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,25 @@ + + + + + ./test + + + + + ./src + + + + + + + + diff --git a/src/Container/ManagerRegistryFactory.php b/src/Container/ManagerRegistryFactory.php index cc55b37..bb801ad 100644 --- a/src/Container/ManagerRegistryFactory.php +++ b/src/Container/ManagerRegistryFactory.php @@ -1,13 +1,18 @@ + * @license MIT + */ + +declare(strict_types=1); + namespace BsbDoctrineRegistry\Container; use BsbDoctrineRegistry\Registry\ManagerRegistry; use Interop\Container\ContainerInterface; -/** - * Class ManagerRegistryFactory - */ class ManagerRegistryFactory { public function __invoke(ContainerInterface $container) @@ -27,11 +32,7 @@ public function __invoke(ContainerInterface $container) return $registry; } - /** - * @param array $options - * @return array - */ - private function getEntityManagers(array $options) + private function getEntityManagers(array $options): array { $entityManagers = []; foreach ($options as $key => $entityManager) { @@ -41,11 +42,7 @@ private function getEntityManagers(array $options) return $entityManagers; } - /** - * @param array $options - * @return array - */ - private function getConnections(array $options) + private function getConnections(array $options): array { $connections = []; foreach ($options as $key => $connection) { diff --git a/src/Registry/ManagerRegistry.php b/src/Registry/ManagerRegistry.php index 458ef2b..a673de0 100644 --- a/src/Registry/ManagerRegistry.php +++ b/src/Registry/ManagerRegistry.php @@ -1,26 +1,29 @@ + * @license MIT + */ + +declare(strict_types=1); + namespace BsbDoctrineRegistry\Registry; use Doctrine\Common\Persistence\AbstractManagerRegistry; use Doctrine\ORM\ORMException; +use Doctrine\Persistence\ObjectManager; use Interop\Container\ContainerInterface; -use Zend\ServiceManager\ServiceManager; -/** - * Class ManagerRegistry - */ class ManagerRegistry extends AbstractManagerRegistry { /** - * @var ServiceManager + * @var ContainerInterface */ private $serviceManager; /** - * @inheritdoc - * - * @param ServiceManager $container + * {@inheritdoc} */ public function __construct( $name, @@ -29,17 +32,17 @@ public function __construct( $defaultConnection, $defaultManager, $proxyInterfaceName, - ServiceManager $serviceManager + ContainerInterface $container ) { parent::__construct($name, $connections, $managers, $defaultConnection, $defaultManager, $proxyInterfaceName); - $this->serviceManager = $serviceManager; + $this->serviceManager = $container; } /** * {@inheritdoc} */ - protected function getService($name) + protected function getService($name): ObjectManager { return $this->serviceManager->get($name); } @@ -47,7 +50,7 @@ protected function getService($name) /** * {@inheritdoc} */ - protected function resetService($name) + protected function resetService($name): void { $this->serviceManager->setService($name, null); } @@ -55,9 +58,9 @@ protected function resetService($name) /** * {@inheritdoc} */ - public function getAliasNamespace($alias) + public function getAliasNamespace($alias): string { - foreach (array_keys($this->getManagers()) as $name) { + foreach (\array_keys($this->getManagers()) as $name) { try { return $this->getManager($name)->getConfiguration()->getEntityNamespace($alias); } catch (ORMException $e) { diff --git a/test/src/Container/ManagerRegistryFactoryTest.php b/test/Container/ManagerRegistryFactoryTest.php similarity index 50% rename from test/src/Container/ManagerRegistryFactoryTest.php rename to test/Container/ManagerRegistryFactoryTest.php index fb466ed..1b9087e 100644 --- a/test/src/Container/ManagerRegistryFactoryTest.php +++ b/test/Container/ManagerRegistryFactoryTest.php @@ -1,31 +1,37 @@ + * @license MIT + */ + +declare(strict_types=1); + namespace BsbDoctrineRegistryTest\Container; use BsbDoctrineRegistry\Container\ManagerRegistryFactory; use BsbDoctrineRegistry\Registry\ManagerRegistry; -use Zend\Diactoros\Response; -use Zend\ServiceManager\ServiceLocatorInterface; -use Zend\ServiceManager\ServiceManager; +use Laminas\ServiceManager\ServiceManager; +use PHPUnit\Framework\TestCase; -class ManagerRegistryFactoryTest extends \PHPUnit_Framework_TestCase +class ManagerRegistryFactoryTest extends TestCase { - - public function testCanCreateInstance() + public function testCanCreateInstance(): void { - $container = $this->getMock(ServiceManager::class); + $container = $this->createMock(ServiceManager::class); $container->expects($this->any()) ->method('get') ->with('config') ->willReturn([ 'doctrine' => [ - 'connection' => ['orm_default' => []], + 'connection' => ['orm_default' => []], 'entitymanager' => ['orm_default' => []], - ] + ], ]); - $factory = new ManagerRegistryFactory(); + $factory = new ManagerRegistryFactory(); $managerRegistry = $factory($container); $this->assertInstanceOf(ManagerRegistry::class, $managerRegistry); diff --git a/test/Registry/ManagerRegistryTest.php b/test/Registry/ManagerRegistryTest.php new file mode 100644 index 0000000..51b3ed3 --- /dev/null +++ b/test/Registry/ManagerRegistryTest.php @@ -0,0 +1,21 @@ + + * @license MIT + */ + +declare(strict_types=1); + +namespace BsbDoctrineRegistryTest\Registry; + +use PHPUnit\Framework\TestCase; + +class ManagerRegistryTest extends TestCase +{ + public function testHelp() + { + // help..! You know how to test this? please feel free. :-) + } +} diff --git a/test/src/Registry/ManagerRegistryTest.php b/test/src/Registry/ManagerRegistryTest.php deleted file mode 100644 index 6a9908f..0000000 --- a/test/src/Registry/ManagerRegistryTest.php +++ /dev/null @@ -1,17 +0,0 @@ -