From 869ed5127d927db08bbfbbb4473ee54506b0d424 Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Thu, 29 Oct 2020 12:22:47 +0100 Subject: [PATCH] Add a basic project --- .gitignore | 6 ++ .php_cs.dist | 22 +++++++ README.md | 24 ++++++- composer.json | 64 +++++++++++++++++++ phpstan.neon | 13 ++++ phpunit.xml.dist | 34 ++++++++++ psalm.xml | 16 +++++ src/Command/TestCommand.php | 32 ++++++++++ src/DbpStarterBundle.php | 15 +++++ .../DbpStarterExtension.php | 22 +++++++ src/Resources/config/services.yaml | 4 ++ src/Service/ExternalApi.php | 12 ++++ tests/Service/ExternalApiTest.php | 23 +++++++ tests/bootstrap.php | 5 ++ 14 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .php_cs.dist create mode 100644 composer.json create mode 100644 phpstan.neon create mode 100644 phpunit.xml.dist create mode 100644 psalm.xml create mode 100644 src/Command/TestCommand.php create mode 100644 src/DbpStarterBundle.php create mode 100644 src/DependencyInjection/DbpStarterExtension.php create mode 100644 src/Resources/config/services.yaml create mode 100644 src/Service/ExternalApi.php create mode 100644 tests/Service/ExternalApiTest.php create mode 100644 tests/bootstrap.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..11eda1d --- /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 0000000..53bdfdc --- /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 a1d8834..f621ab0 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 0000000..9ef32a2 --- /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 0000000..c0061da --- /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 0000000..069b8ca --- /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 0000000..49eb6d0 --- /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 0000000..aee7b69 --- /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 0000000..d602859 --- /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 0000000..058f349 --- /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 0000000..ac9d7af --- /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 0000000..a65c6cc --- /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 0000000..4784220 --- /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 0000000..927977a --- /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 -- GitLab