From b3a79eb6ec9956cce8a6036c5e0b43cfb24468ce Mon Sep 17 00:00:00 2001 From: juananrey Date: Sat, 14 Apr 2018 10:48:20 +0200 Subject: [PATCH] Added HealthCheckController, SymfonyFrameworkExtraBundle to render Controller annotations and a basic unit test for the brand new HealthCheckController --- .gitignore | 7 +- bin/phpunit | 18 + composer.json | 4 +- composer.lock | 542 ++++++++++++++++++++++- config/bundles.php | 1 + config/routes/annotations.yaml | 3 + config/services_test.yaml | 9 + docker/php-fpm/Dockerfile | 2 +- phpunit.xml.dist | 35 ++ src/Controller/HealthCheckController.php | 19 + symfony.lock | 42 ++ {src/Controller => tests}/.gitignore | 0 tests/HealthCheckControllerUnitTest.php | 27 ++ 13 files changed, 704 insertions(+), 5 deletions(-) create mode 100755 bin/phpunit create mode 100644 config/routes/annotations.yaml create mode 100644 config/services_test.yaml create mode 100644 phpunit.xml.dist create mode 100644 src/Controller/HealthCheckController.php rename {src/Controller => tests}/.gitignore (100%) create mode 100644 tests/HealthCheckControllerUnitTest.php diff --git a/.gitignore b/.gitignore index 88b21b5..c0db4cc 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,9 @@ ###> PHPStorm #### .idea -###< PHPStorm #### \ No newline at end of file +###< PHPStorm #### + +###> symfony/phpunit-bridge ### +.phpunit +/phpunit.xml +###< symfony/phpunit-bridge ### diff --git a/bin/phpunit b/bin/phpunit new file mode 100755 index 0000000..75d5be8 --- /dev/null +++ b/bin/phpunit @@ -0,0 +1,18 @@ +#!/usr/bin/env php +2.2,<2.4" + }, + "require-dev": { + "alcaeus/mongo-php-adapter": "^1.1", + "mongodb/mongodb": "^1.1", + "phpunit/phpunit": "^5.7", + "predis/predis": "~1.0" + }, + "suggest": { + "alcaeus/mongo-php-adapter": "Required to use legacy MongoDB driver" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Caching library offering an object-oriented API for many cache backends", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "cache", + "caching" + ], + "time": "2017-08-25 07:02:50" + }, + { + "name": "doctrine/collections", + "version": "v1.5.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/collections.git", + "reference": "a01ee38fcd999f34d9bfbcee59dbda5105449cbf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/collections/zipball/a01ee38fcd999f34d9bfbcee59dbda5105449cbf", + "reference": "a01ee38fcd999f34d9bfbcee59dbda5105449cbf", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "~0.1@dev", + "phpunit/phpunit": "^5.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Collections\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Collections Abstraction library", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "array", + "collections", + "iterator" + ], + "time": "2017-07-22 10:37:32" + }, + { + "name": "doctrine/common", + "version": "v2.8.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/common.git", + "reference": "f68c297ce6455e8fd794aa8ffaf9fa458f6ade66" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/common/zipball/f68c297ce6455e8fd794aa8ffaf9fa458f6ade66", + "reference": "f68c297ce6455e8fd794aa8ffaf9fa458f6ade66", + "shasum": "" + }, + "require": { + "doctrine/annotations": "1.*", + "doctrine/cache": "1.*", + "doctrine/collections": "1.*", + "doctrine/inflector": "1.*", + "doctrine/lexer": "1.*", + "php": "~7.1" + }, + "require-dev": { + "phpunit/phpunit": "^5.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\": "lib/Doctrine/Common" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common Library for Doctrine projects", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "collections", + "eventmanager", + "persistence", + "spl" + ], + "time": "2017-08-31 08:43:38" + }, + { + "name": "doctrine/inflector", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/inflector.git", + "reference": "5527a48b7313d15261292c149e55e26eae771b0a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/5527a48b7313d15261292c149e55e26eae771b0a", + "reference": "5527a48b7313d15261292c149e55e26eae771b0a", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^6.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common String Manipulations with regard to casing and singular/plural rules.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "inflection", + "pluralize", + "singularize", + "string" + ], + "time": "2018-01-09 20:05:19" + }, + { + "name": "doctrine/lexer", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Lexer\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "lexer", + "parser" + ], + "time": "2014-09-09 13:34:57" + }, { "name": "psr/cache", "version": "1.0.1", @@ -197,6 +600,75 @@ ], "time": "2017-10-23 01:57:42" }, + { + "name": "sensio/framework-extra-bundle", + "version": "v5.1.6", + "source": { + "type": "git", + "url": "https://github.com/sensiolabs/SensioFrameworkExtraBundle.git", + "reference": "bf4940572e43af679aaa13be98f3446a1c237bd8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sensiolabs/SensioFrameworkExtraBundle/zipball/bf4940572e43af679aaa13be98f3446a1c237bd8", + "reference": "bf4940572e43af679aaa13be98f3446a1c237bd8", + "shasum": "" + }, + "require": { + "doctrine/common": "^2.2", + "symfony/config": "^3.3|^4.0", + "symfony/dependency-injection": "^3.3|^4.0", + "symfony/framework-bundle": "^3.3|^4.0", + "symfony/http-kernel": "^3.3|^4.0" + }, + "require-dev": { + "doctrine/doctrine-bundle": "^1.6", + "doctrine/orm": "^2.5", + "symfony/browser-kit": "^3.3|^4.0", + "symfony/dom-crawler": "^3.3|^4.0", + "symfony/expression-language": "^3.3|^4.0", + "symfony/finder": "^3.3|^4.0", + "symfony/phpunit-bridge": "^3.3|^4.0", + "symfony/psr-http-message-bridge": "^0.3", + "symfony/security-bundle": "^3.3|^4.0", + "symfony/twig-bundle": "^3.3|^4.0", + "symfony/yaml": "^3.3|^4.0", + "twig/twig": "~1.12|~2.0", + "zendframework/zend-diactoros": "^1.3" + }, + "suggest": { + "symfony/expression-language": "", + "symfony/psr-http-message-bridge": "To use the PSR-7 converters", + "symfony/security-bundle": "" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "5.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Sensio\\Bundle\\FrameworkExtraBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "This bundle provides a way to configure your controllers with annotations", + "keywords": [ + "annotations", + "controllers" + ], + "time": "2018-02-14 08:40:54" + }, { "name": "symfony/cache", "version": "v4.0.8", @@ -1329,6 +1801,72 @@ "environment" ], "time": "2018-01-03 17:15:19" + }, + { + "name": "symfony/phpunit-bridge", + "version": "v4.0.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/phpunit-bridge.git", + "reference": "e82f3f46384482f2a7dab5f00c58a36b9726bde9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/e82f3f46384482f2a7dab5f00c58a36b9726bde9", + "reference": "e82f3f46384482f2a7dab5f00c58a36b9726bde9", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "conflict": { + "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0" + }, + "suggest": { + "ext-zip": "Zip support is required when using bin/simple-phpunit", + "symfony/debug": "For tracking deprecated interfaces usages at runtime with DebugClassLoader" + }, + "bin": [ + "bin/simple-phpunit" + ], + "type": "symfony-bridge", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + }, + "thanks": { + "name": "phpunit/phpunit", + "url": "https://github.com/sebastianbergmann/phpunit" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Bridge\\PhpUnit\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony PHPUnit Bridge", + "homepage": "https://symfony.com", + "time": "2018-04-04 18:24:59" } ], "aliases": [], diff --git a/config/bundles.php b/config/bundles.php index 49d3fb6..0d71512 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -2,4 +2,5 @@ return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], + Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], ]; diff --git a/config/routes/annotations.yaml b/config/routes/annotations.yaml new file mode 100644 index 0000000..d49a502 --- /dev/null +++ b/config/routes/annotations.yaml @@ -0,0 +1,3 @@ +controllers: + resource: ../../src/Controller/ + type: annotation diff --git a/config/services_test.yaml b/config/services_test.yaml new file mode 100644 index 0000000..876c36b --- /dev/null +++ b/config/services_test.yaml @@ -0,0 +1,9 @@ +services: + _defaults: + public: true + + # If you need to access services in a test, create an alias + # and then fetch that alias from the container. As a convention, + # aliases are prefixed with test. For example: + # + # test.App\Service\MyService: '@App\Service\MyService' diff --git a/docker/php-fpm/Dockerfile b/docker/php-fpm/Dockerfile index 570e38a..90a4fb7 100644 --- a/docker/php-fpm/Dockerfile +++ b/docker/php-fpm/Dockerfile @@ -1,7 +1,7 @@ FROM phpdockerio/php72-fpm:latest WORKDIR "/application" -# Install selected extensions and other stuff (here, we simply install git to run composer updates on the VM). +# Install selected extensions and other stuff RUN apt-get update \ && apt-get -y --no-install-recommends install git \ && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..e578316 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + tests/ + + + + + + ./src/ + + + + + + + diff --git a/src/Controller/HealthCheckController.php b/src/Controller/HealthCheckController.php new file mode 100644 index 0000000..26a35ad --- /dev/null +++ b/src/Controller/HealthCheckController.php @@ -0,0 +1,19 @@ + 'i am ok']); + } +} diff --git a/symfony.lock b/symfony.lock index 0eb3607..0f59ca8 100644 --- a/symfony.lock +++ b/symfony.lock @@ -1,4 +1,28 @@ { + "doctrine/annotations": { + "version": "1.0", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "1.0", + "ref": "cb4152ebcadbe620ea2261da1a1c5a9b8cea7672" + } + }, + "doctrine/cache": { + "version": "v1.7.1" + }, + "doctrine/collections": { + "version": "v1.5.0" + }, + "doctrine/common": { + "version": "v2.8.1" + }, + "doctrine/inflector": { + "version": "v1.3.0" + }, + "doctrine/lexer": { + "version": "v1.0.1" + }, "psr/cache": { "version": "1.0.1" }, @@ -11,6 +35,15 @@ "psr/simple-cache": { "version": "1.0.1" }, + "sensio/framework-extra-bundle": { + "version": "4.0", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "4.0", + "ref": "aaddfdf43cdecd4cf91f992052d76c2cadc04543" + } + }, "symfony/cache": { "version": "v4.0.8" }, @@ -71,6 +104,15 @@ "symfony/lts": { "version": "4-dev" }, + "symfony/phpunit-bridge": { + "version": "3.3", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "3.3", + "ref": "179470cb6492db92dffee208cfdb436f175c93b4" + } + }, "symfony/polyfill-mbstring": { "version": "v1.7.0" }, diff --git a/src/Controller/.gitignore b/tests/.gitignore similarity index 100% rename from src/Controller/.gitignore rename to tests/.gitignore diff --git a/tests/HealthCheckControllerUnitTest.php b/tests/HealthCheckControllerUnitTest.php new file mode 100644 index 0000000..0cd38ac --- /dev/null +++ b/tests/HealthCheckControllerUnitTest.php @@ -0,0 +1,27 @@ +healthCheckController = new HealthCheckController(); + } + + public function testHealthCheckReturnsWhatWeExpect() + { + $response = $this->healthCheckController->healthCheck(); + $expected = json_encode(['status' => 'i am ok']); + $this->assertEquals($expected, $response->getContent()); + } +} \ No newline at end of file