commit 1b28f3d45a94622266ce12a41687de643d05166e Author: magdev Date: Tue Apr 25 15:00:03 2023 +0200 Initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9141329 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_style = space +indent_size = 4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..33a071b --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/.phpunit.result.cache +/.phpunit.cache +/composer.lock +/phpunit.xml +/vendor/ +*~ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..efd7793 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "nuxt.isNuxtApp": false +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..df27e5f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT license + +Copyright (c) 2021-2022 Marco Grätsch + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..91ba056 --- /dev/null +++ b/composer.json @@ -0,0 +1,32 @@ +{ + "name": "magdev/redmine-bundle", + "description": "Symfony bundle to integrate Redmine", + "type": "symfony-bundle", + "require": { + }, + "require-dev": { + "phpunit/phpunit": "^9.5", + "symfony/http-kernel": "^6.2", + "symfony/dependency-injection": "^6.2", + "symfony/config": "^6.2", + "symfony/phpunit-bridge": "^6.0" + }, + "license": "MIT", + "autoload": { + "psr-4": { + "Magdev\\RedmineBundle\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Magdev\\RedmineBundle\\Tests\\": "tests/" + } + }, + "authors": [ + { + "name": "magdev", + "email": "magdev3.0@gmail.com" + } + ], + "minimum-stability": "stable" +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..340d6c3 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + tests + + + + + + src + + + + + + + diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php new file mode 100644 index 0000000..f54bf53 --- /dev/null +++ b/src/DependencyInjection/Configuration.php @@ -0,0 +1,42 @@ + + */ +final class Configuration implements ConfigurationInterface +{ + public function getConfigTreeBuilder(): TreeBuilder + { + $treeBuilder = new TreeBuilder('magdev_gitea'); + $rootNode = $treeBuilder->getRootNode(); + $rootNode->fixXmlConfig('connection') + ->children() + ->arrayNode('connections') + ->useAttributeAsKey('name') + ->normalizeKeys(false) + ->arrayPrototype() + ->children() + ->scalarNode('baseurl') + ->isRequired() + ->info('The base URL of the gitea instance') + ->end() + ->scalarNode('token') + ->isRequired() + ->info('The Gitea access token') + ->end() + ->end() + ->end() + ->end() + ->scalarNode('default_connection')->end() + ; + + return $treeBuilder; + } +} diff --git a/src/DependencyInjection/MagdevRedmineExtension.php b/src/DependencyInjection/MagdevRedmineExtension.php new file mode 100644 index 0000000..ac30802 --- /dev/null +++ b/src/DependencyInjection/MagdevRedmineExtension.php @@ -0,0 +1,34 @@ + + */ +final class MagdevRedmineExtension extends Extension +{ + public function load(array $configs, ContainerBuilder $container) + { + $config = $this->processConfiguration(new Configuration(), $configs); + + /*if (!isset($config['default_connection'])) { + $config['default_connection'] = array_key_first($config['connections']); + } + + foreach ($config['connections'] as $name => $connection) { + $id = sprintf('magdev.gitea.%s', $name); + $container->register($id, Client::class) + ->setArguments([null, null, $connection['baseurl']]) + ->addMethodCall('authenticate', [$connection['token'], null, Client::AUTH_ACCESS_TOKEN]); + $container->registerAliasForArgument($id, Client::class, "{$name}Client"); + + if ($name === $config['default_connection']) { + $container->setAlias(Client::class, $id); + } + }*/ + } +} diff --git a/src/MagdevRedmineBundle.php b/src/MagdevRedmineBundle.php new file mode 100644 index 0000000..1c74f1f --- /dev/null +++ b/src/MagdevRedmineBundle.php @@ -0,0 +1,12 @@ + + */ +final class MagdevRedmineBundle extends Bundle +{ +} diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php new file mode 100644 index 0000000..4da765e --- /dev/null +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -0,0 +1,41 @@ + + */ +class ConfigurationTest extends TestCase +{ + /** + * @dataProvider configsProvider + */ + public function testConfig(array $configs): void + { + $config = (new Processor())->processConfiguration(new Configuration(), $configs); + $this->assertSame('foo', $config['connections']['default']['token']); + $this->assertSame('bar', $config['connections']['default']['baseurl']); + } + + public function configsProvider(): iterable + { + yield [ + [ + 'magdev_redmine' => [ + 'connections' => [ + 'default' => [ + 'token' => 'foo', + 'baseurl' => 'bar' + ], + ], + ], + ], + ]; + } +} diff --git a/tests/DependencyInjection/MagdevRedmineExtensionTest.php b/tests/DependencyInjection/MagdevRedmineExtensionTest.php new file mode 100644 index 0000000..4444d0a --- /dev/null +++ b/tests/DependencyInjection/MagdevRedmineExtensionTest.php @@ -0,0 +1,39 @@ + + */ +class MagdevRedmineExtensionTest extends TestCase +{ + public function testExtension(): void + { + $container = new ContainerBuilder(); + + (new MagdevRedmineExtension())->load([ + 'magdev_redmine' => [ + 'connections' => [ + 'primary' => ['baseurl' => 'http://foo1', 'token' => 'bar1'], + 'secondary' => ['baseurl' => 'http://foo2', 'token' => 'bar2'], + ], + ], + ], $container); + + $this->assertTrue($container->has('magdev.redmine.primary')); + $this->assertTrue($container->has('magdev.redmine.secondary')); + + $this->assertTrue($container->hasAlias(Client::class)); + $this->assertTrue($container->hasAlias(Client::class.' $primaryClient')); + $this->assertTrue($container->hasAlias(Client::class.' $secondaryClient')); + + $this->assertInstanceOf(Client::class, $container->get('magdev.redmine.primary')); + $this->assertInstanceOf(Client::class, $container->get('magdev.redmine.secondary')); + } +}