diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..11eda1d1be494733a3f95166052e9afe3306e5fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/vendor +/var +/.php_cs +/.idea +/*.cache +composer.lock \ No newline at end of file diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000000000000000000000000000000000000..53bdfdc22d1a52c97cc90f42e4dbe1d3d47a5d4d --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,22 @@ +<?php + +$finder = PhpCsFixer\Finder::create() + ->in(__DIR__) + ->exclude('var') +; + +return PhpCsFixer\Config::create() + ->setRules([ + '@Symfony' => true, + '@PHP70Migration' => true, + '@PHP71Migration' => true, + '@PHP73Migration' => true, + 'array_syntax' => ['syntax' => 'short'], + 'yoda_style' => false, + 'strict_comparison' => true, + 'strict_param' => true, + 'declare_strict_types' => true, + ]) + ->setRiskyAllowed(true) + ->setFinder($finder) +; \ No newline at end of file diff --git a/README.md b/README.md index a1d88342546572e749447f19b2dc1b40a6663a50..f621ab0c49e1f25dd90769091bb11be5e1b09f7b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,24 @@ -# starter-bundle +# DBP API Starter Bundle +This Symfony bundle can be used as a template for creating new bundles for the +DBP API project. + +When including this bundle into your DBP API server it will gain the following +features: + +* TODO +* TODO +* ... +* profit + + +## Integration into the API Server + +TODO: add to composer, create configuration, note how to see if it works + +## Development & Testing + +* Install dependencies: `composer install` +* Run tests: `composer test` +* Run linters: `composer run lint` +* Run cs-fixed: `composer run cs-fix` \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000000000000000000000000000000000000..9ef32a22203a11bbf397770150ed6dc9c88f25b7 --- /dev/null +++ b/composer.json @@ -0,0 +1,64 @@ +{ + "name": "dbp/api-starter-bundle", + "type": "symfony-bundle", + "license": "AGPL-3.0-or-later", + "require": { + "php": "^7.3", + "api-platform/core": "^2.4", + "symfony/framework-bundle": "^4.1.12", + "dbp/api-core-bundle": "@dev" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.16", + "phpstan/phpstan": "^0.12.33", + "phpstan/phpstan-phpunit": "^0.12.13", + "symfony/phpunit-bridge": "^4.4", + "vimeo/psalm": "^3.12" + }, + "repositories": [ + { + "type": "path", + "url": "../../API/bundles/api-core-bundle" + } + ], + "autoload": { + "psr-4": { + "DBP\\API\\StarterBundle\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "DBP\\API\\StarterBundle\\Tests\\": "tests/" + } + }, + "config": { + "sort-packages": true, + "platform": { + "php": "7.3" + } + }, + "scripts": { + "test": [ + "@php vendor/bin/simple-phpunit" + ], + "phpstan": [ + "@php vendor/bin/simple-phpunit --atleast-version 0", + "@php vendor/bin/phpstan analyze --ansi" + ], + "psalm": [ + "@php vendor/bin/simple-phpunit --atleast-version 0", + "@php vendor/bin/psalm" + ], + "lint": [ + "@composer run cs", + "@composer run phpstan", + "@composer run psalm" + ], + "cs-fix": [ + "@php vendor/bin/php-cs-fixer --ansi fix" + ], + "cs": [ + "@php vendor/bin/php-cs-fixer --ansi fix --dry-run --diff --diff-format=udiff" + ] + } +} \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000000000000000000000000000000000000..c0061da49f3ef50bdc30846b871da69d21c94a8b --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,13 @@ +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon + +parameters: + inferPrivatePropertyTypeFromConstructor: true + level: 3 + paths: + - src + - tests + bootstrapFiles: + - vendor/bin/.phpunit/phpunit-8-0/vendor/autoload.php + excludes_analyse: + - tests/bootstrap.php \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000000000000000000000000000000000000..069b8ca410c111e7600cbca494f6ebc7b497b1d4 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html --> +<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd" + backupGlobals="false" + colors="true" + bootstrap="tests/bootstrap.php" +> + <php> + <ini name="error_reporting" value="-1" /> + <server name="APP_ENV" value="test" force="true" /> + <server name="SHELL_VERBOSITY" value="-1" /> + <server name="SYMFONY_PHPUNIT_REMOVE" value="" /> + <server name="SYMFONY_PHPUNIT_VERSION" value="8" /> + </php> + + <testsuites> + <testsuite name="Project Test Suite"> + <directory>tests</directory> + </testsuite> + </testsuites> + + <filter> + <whitelist> + <directory>src</directory> + <directory>tests</directory> + </whitelist> + </filter> + + <listeners> + <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" /> + </listeners> +</phpunit> diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000000000000000000000000000000000000..49eb6d0737673e645ec11702339b3345fbeed294 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<psalm + totallyTyped="false" + errorLevel="5" + resolveFromConfigFile="true" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="https://getpsalm.org/schema/config" + xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" +> + <projectFiles> + <directory name="src" /> + <ignoreFiles> + <directory name="vendor" /> + </ignoreFiles> + </projectFiles> +</psalm> diff --git a/src/Command/TestCommand.php b/src/Command/TestCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..aee7b6921e536bdd6283c0bfff8ad4a4dba986b6 --- /dev/null +++ b/src/Command/TestCommand.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +namespace DBP\API\StarterBundle\Command; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class TestCommand extends Command +{ + public function __construct() + { + parent::__construct(); + } + + protected function configure() + { + $this->addArgument('argument', InputArgument::REQUIRED, 'Example.'); + $this->setDescription('Hey there!'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $argument = $input->getArgument('argument'); + $output->write($argument); + + return 0; + } +} diff --git a/src/DbpStarterBundle.php b/src/DbpStarterBundle.php new file mode 100644 index 0000000000000000000000000000000000000000..d6028598e93a32049fc72fd37c6cdbde44c0f094 --- /dev/null +++ b/src/DbpStarterBundle.php @@ -0,0 +1,15 @@ +<?php + +declare(strict_types=1); + +namespace DBP\API\StarterBundle; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\Bundle\Bundle; + +class DbpStarterBundle extends Bundle +{ + public function build(ContainerBuilder $container) + { + } +} diff --git a/src/DependencyInjection/DbpStarterExtension.php b/src/DependencyInjection/DbpStarterExtension.php new file mode 100644 index 0000000000000000000000000000000000000000..058f349f1b1194dadc8c560e1fc9effce488332f --- /dev/null +++ b/src/DependencyInjection/DbpStarterExtension.php @@ -0,0 +1,22 @@ +<?php + +declare(strict_types=1); + +namespace DBP\API\StarterBundle\DependencyInjection; + +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; + +class DbpStarterExtension extends Extension +{ + public function load(array $configs, ContainerBuilder $container) + { + $loader = new YamlFileLoader( + $container, + new FileLocator(__DIR__.'/../Resources/config') + ); + $loader->load('services.yaml'); + } +} diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ac9d7afd6af249850eeffc7c57c9042e3ad379fc --- /dev/null +++ b/src/Resources/config/services.yaml @@ -0,0 +1,4 @@ +services: + DBP\API\StarterBundle\Command\TestCommand: + autowire: true + autoconfigure: true \ No newline at end of file diff --git a/src/Service/ExternalApi.php b/src/Service/ExternalApi.php new file mode 100644 index 0000000000000000000000000000000000000000..a65c6ccc8e8caa1a4b9df0dd895d663b3908cf96 --- /dev/null +++ b/src/Service/ExternalApi.php @@ -0,0 +1,12 @@ +<?php + +declare(strict_types=1); + +namespace DBP\API\StarterBundle\Service; + +class ExternalApi +{ + public function __construct() + { + } +} diff --git a/tests/Service/ExternalApiTest.php b/tests/Service/ExternalApiTest.php new file mode 100644 index 0000000000000000000000000000000000000000..4784220da427a3b255103e9afa18147d747e05ff --- /dev/null +++ b/tests/Service/ExternalApiTest.php @@ -0,0 +1,23 @@ +<?php + +declare(strict_types=1); + +namespace DBP\API\StarterBundle\Tests\Service; + +use DBP\API\StarterBundle\Service\ExternalApi; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; + +class ExternalApiTest extends WebTestCase +{ + private $api; + + protected function setUp(): void + { + $this->api = new ExternalApi(); + } + + public function test() + { + $this->assertTrue(true); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000000000000000000000000000000000000..927977a0f688790cfb16cc3db8796e5fa48345eb --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,5 @@ +<?php + +declare(strict_types=1); + +require dirname(__DIR__).'/vendor/autoload.php'; \ No newline at end of file