From ff990b1cb31882c0f9d05cf32d6c322b25a0b615 Mon Sep 17 00:00:00 2001 From: 77web Date: Tue, 7 Jul 2020 08:56:00 +0900 Subject: [PATCH 01/15] =?UTF-8?q?symfony/test-pack=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.test | 5 + .gitignore | 6 + bin/phpunit | 13 ++ composer.json | 1 + composer.lock | 324 +++++++++++++++++++++++++++++++++++++++++++- phpunit.xml.dist | 33 +++++ symfony.lock | 27 ++++ tests/bootstrap.php | 11 ++ 8 files changed, 419 insertions(+), 1 deletion(-) create mode 100644 .env.test create mode 100755 bin/phpunit create mode 100644 phpunit.xml.dist create mode 100644 tests/bootstrap.php diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..d048686 --- /dev/null +++ b/.env.test @@ -0,0 +1,5 @@ +# define your env variables for the test env here +KERNEL_CLASS='App\Kernel' +APP_SECRET='$ecretf0rt3st' +SYMFONY_DEPRECATIONS_HELPER=999999 +PANTHER_APP_ENV=panther diff --git a/.gitignore b/.gitignore index 465493f..177f5d1 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,9 @@ npm-debug.log yarn-error.log ###< symfony/webpack-encore-bundle ### + +###> symfony/phpunit-bridge ### +.phpunit +.phpunit.result.cache +/phpunit.xml +###< symfony/phpunit-bridge ### diff --git a/bin/phpunit b/bin/phpunit new file mode 100755 index 0000000..4d1ed05 --- /dev/null +++ b/bin/phpunit @@ -0,0 +1,13 @@ +#!/usr/bin/env php +=7.2.5", + "symfony/dom-crawler": "^4.4|^5.0" + }, + "require-dev": { + "symfony/css-selector": "^4.4|^5.0", + "symfony/http-client": "^4.4|^5.0", + "symfony/mime": "^4.4|^5.0", + "symfony/process": "^4.4|^5.0" + }, + "suggest": { + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\BrowserKit\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony BrowserKit Component", + "homepage": "https://symfony.com", + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-23T13:12:54+00:00" + }, { "name": "symfony/cache", "version": "v5.0.7", @@ -1842,6 +1915,73 @@ "homepage": "https://symfony.com", "time": "2020-03-30T11:42:42+00:00" }, + { + "name": "symfony/css-selector", + "version": "v5.0.10", + "source": { + "type": "git", + "url": "https://github.com/symfony/css-selector.git", + "reference": "79c224cdbfae58d54b257a8c684ad445042c90f2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/79c224cdbfae58d54b257a8c684ad445042c90f2", + "reference": "79c224cdbfae58d54b257a8c684ad445042c90f2", + "shasum": "" + }, + "require": { + "php": ">=7.2.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\CssSelector\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Jean-François Simon", + "email": "jeanfrancois.simon@sensiolabs.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony CssSelector Component", + "homepage": "https://symfony.com", + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-20T17:38:26+00:00" + }, { "name": "symfony/dependency-injection", "version": "v5.0.7", @@ -2011,6 +2151,81 @@ "homepage": "https://symfony.com", "time": "2020-03-27T16:56:45+00:00" }, + { + "name": "symfony/dom-crawler", + "version": "v5.0.10", + "source": { + "type": "git", + "url": "https://github.com/symfony/dom-crawler.git", + "reference": "9d86e7382e7fe96889440e29c1965e4e4f6f4aec" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/9d86e7382e7fe96889440e29c1965e4e4f6f4aec", + "reference": "9d86e7382e7fe96889440e29c1965e4e4f6f4aec", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "masterminds/html5": "<2.6" + }, + "require-dev": { + "masterminds/html5": "^2.6", + "symfony/css-selector": "^4.4|^5.0" + }, + "suggest": { + "symfony/css-selector": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\DomCrawler\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony DomCrawler Component", + "homepage": "https://symfony.com", + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-23T12:58:59+00:00" + }, { "name": "symfony/dotenv", "version": "v5.0.7", @@ -3040,6 +3255,85 @@ "description": "A pack for the Doctrine ORM", "time": "2020-02-10T18:03:48+00:00" }, + { + "name": "symfony/phpunit-bridge", + "version": "v5.1.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/phpunit-bridge.git", + "reference": "de5f0fec631a0cbfe98630b053be1fad7b75aece" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/de5f0fec631a0cbfe98630b053be1fad7b75aece", + "reference": "de5f0fec631a0cbfe98630b053be1fad7b75aece", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "conflict": { + "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0|<6.4,>=6.0|9.1.2" + }, + "suggest": { + "symfony/error-handler": "For tracking deprecated interfaces usages at runtime with DebugClassLoader" + }, + "bin": [ + "bin/simple-phpunit" + ], + "type": "symfony-bridge", + "extra": { + "branch-alias": { + "dev-master": "5.1-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", + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-06-09T09:56:30+00:00" + }, { "name": "symfony/polyfill-intl-icu", "version": "v1.15.0", @@ -3660,6 +3954,34 @@ "homepage": "https://symfony.com", "time": "2020-03-27T16:56:45+00:00" }, + { + "name": "symfony/test-pack", + "version": "v1.0.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/test-pack.git", + "reference": "ff87e800a67d06c423389f77b8209bc9dc469def" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/test-pack/zipball/ff87e800a67d06c423389f77b8209bc9dc469def", + "reference": "ff87e800a67d06c423389f77b8209bc9dc469def", + "shasum": "" + }, + "require": { + "php": "^7.0", + "symfony/browser-kit": "*", + "symfony/css-selector": "*", + "symfony/phpunit-bridge": "*" + }, + "type": "symfony-pack", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A pack for functional and end-to-end testing within a Symfony app", + "time": "2019-06-21T06:27:32+00:00" + }, { "name": "symfony/translation-contracts", "version": "v2.0.1", diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..d81f0c3 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + tests + + + + + + src + + + + + + + diff --git a/symfony.lock b/symfony.lock index 92d3d45..cbb53a5 100644 --- a/symfony.lock +++ b/symfony.lock @@ -105,6 +105,9 @@ "symfony/asset": { "version": "v5.0.7" }, + "symfony/browser-kit": { + "version": "v5.0.10" + }, "symfony/cache": { "version": "v5.0.7" }, @@ -127,12 +130,18 @@ "config/bootstrap.php" ] }, + "symfony/css-selector": { + "version": "v5.0.10" + }, "symfony/dependency-injection": { "version": "v5.0.7" }, "symfony/doctrine-bridge": { "version": "v5.0.7" }, + "symfony/dom-crawler": { + "version": "v5.0.10" + }, "symfony/dotenv": { "version": "v5.0.7" }, @@ -216,6 +225,21 @@ "symfony/orm-pack": { "version": "v1.0.8" }, + "symfony/phpunit-bridge": { + "version": "4.3", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "4.3", + "ref": "6d0e35f749d5f4bfe1f011762875275cd3f9874f" + }, + "files": [ + ".env.test", + "bin/phpunit", + "phpunit.xml.dist", + "tests/bootstrap.php" + ] + }, "symfony/polyfill-intl-icu": { "version": "v1.15.0" }, @@ -257,6 +281,9 @@ "symfony/stopwatch": { "version": "v5.0.7" }, + "symfony/test-pack": { + "version": "v1.0.6" + }, "symfony/translation-contracts": { "version": "v2.0.1" }, diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..469dcce --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,11 @@ +bootEnv(dirname(__DIR__).'/.env'); +} From 84bc1ee6df17cf9147ea2271534feab621273b4c Mon Sep 17 00:00:00 2001 From: 77web Date: Wed, 8 Jul 2020 12:47:16 +0900 Subject: [PATCH 02/15] =?UTF-8?q?LiipTestFixturesBundle=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 6 +- composer.lock | 776 ++++++++++++++++++++++++- config/bundles.php | 4 + config/packages/dev/nelmio_alice.yaml | 9 + config/packages/test/nelmio_alice.yaml | 2 + symfony.lock | 58 ++ 6 files changed, 852 insertions(+), 3 deletions(-) create mode 100644 config/packages/dev/nelmio_alice.yaml create mode 100644 config/packages/test/nelmio_alice.yaml diff --git a/composer.json b/composer.json index a32b48a..a6ea4dc 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,11 @@ "symfony/yaml": "5.0.*" }, "require-dev": { - "symfony/maker-bundle": "^1.15" + "doctrine/doctrine-fixtures-bundle": "^3.3", + "liip/test-fixtures-bundle": "^1.9", + "nelmio/alice": "^3.7", + "symfony/maker-bundle": "^1.15", + "theofidry/alice-data-fixtures": "^1.2" }, "config": { "preferred-install": { diff --git a/composer.lock b/composer.lock index 126f436..c287dfb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "dec37b88909505784eff4fea0c7138d2", + "content-hash": "32c927f18a5187678e6fbc8145df6c6b", "packages": [ { "name": "doctrine/annotations", @@ -4819,6 +4819,428 @@ } ], "packages-dev": [ + { + "name": "doctrine/data-fixtures", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/doctrine/data-fixtures.git", + "reference": "7ebac50901eb4516816ac39100dba1759d843943" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/7ebac50901eb4516816ac39100dba1759d843943", + "reference": "7ebac50901eb4516816ac39100dba1759d843943", + "shasum": "" + }, + "require": { + "doctrine/common": "^2.11", + "doctrine/persistence": "^1.3.3", + "php": "^7.2 || ^8.0" + }, + "conflict": { + "doctrine/phpcr-odm": "<1.3.0" + }, + "require-dev": { + "alcaeus/mongo-php-adapter": "^1.1", + "doctrine/coding-standard": "^6.0", + "doctrine/dbal": "^2.5.4", + "doctrine/mongodb-odm": "^1.3.0", + "doctrine/orm": "^2.7.0", + "phpunit/phpunit": "^7.0" + }, + "suggest": { + "alcaeus/mongo-php-adapter": "For using MongoDB ODM with PHP 7", + "doctrine/mongodb-odm": "For loading MongoDB ODM fixtures", + "doctrine/orm": "For loading ORM fixtures", + "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\DataFixtures\\": "lib/Doctrine/Common/DataFixtures" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Data Fixtures for all Doctrine Object Managers", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database" + ], + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdata-fixtures", + "type": "tidelift" + } + ], + "time": "2020-05-25T19:45:03+00:00" + }, + { + "name": "doctrine/doctrine-fixtures-bundle", + "version": "3.3.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/DoctrineFixturesBundle.git", + "reference": "39defca57ee0949e1475c46177b30b6d1b732e8f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/39defca57ee0949e1475c46177b30b6d1b732e8f", + "reference": "39defca57ee0949e1475c46177b30b6d1b732e8f", + "shasum": "" + }, + "require": { + "doctrine/data-fixtures": "^1.3", + "doctrine/doctrine-bundle": "^1.11|^2.0", + "doctrine/orm": "^2.6.0", + "doctrine/persistence": "^1.3", + "php": "^7.1", + "symfony/config": "^3.4|^4.3|^5.0", + "symfony/console": "^3.4|^4.3|^5.0", + "symfony/dependency-injection": "^3.4|^4.3|^5.0", + "symfony/doctrine-bridge": "^3.4|^4.1|^5.0", + "symfony/http-kernel": "^3.4|^4.3|^5.0" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "phpunit/phpunit": "^7.4", + "symfony/phpunit-bridge": "^4.1|^5.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "3.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Bundle\\FixturesBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Doctrine Project", + "homepage": "http://www.doctrine-project.org" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony DoctrineFixturesBundle", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "Fixture", + "persistence" + ], + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdoctrine-fixtures-bundle", + "type": "tidelift" + } + ], + "time": "2020-04-02T16:40:37+00:00" + }, + { + "name": "fzaninotto/faker", + "version": "v1.9.1", + "source": { + "type": "git", + "url": "https://github.com/fzaninotto/Faker.git", + "reference": "fc10d778e4b84d5bd315dad194661e091d307c6f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/fc10d778e4b84d5bd315dad194661e091d307c6f", + "reference": "fc10d778e4b84d5bd315dad194661e091d307c6f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "ext-intl": "*", + "phpunit/phpunit": "^4.8.35 || ^5.7", + "squizlabs/php_codesniffer": "^2.9.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Faker\\": "src/Faker/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "François Zaninotto" + } + ], + "description": "Faker is a PHP library that generates fake data for you.", + "keywords": [ + "data", + "faker", + "fixtures" + ], + "time": "2019-12-12T13:22:17+00:00" + }, + { + "name": "liip/test-fixtures-bundle", + "version": "1.9.1", + "source": { + "type": "git", + "url": "https://github.com/liip/LiipTestFixturesBundle.git", + "reference": "c8d4984f134e21c2b6e30b85dbd62e60fdf824dd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/liip/LiipTestFixturesBundle/zipball/c8d4984f134e21c2b6e30b85dbd62e60fdf824dd", + "reference": "c8d4984f134e21c2b6e30b85dbd62e60fdf824dd", + "shasum": "" + }, + "require": { + "doctrine/common": "^2.0", + "php": "^7.1", + "symfony/framework-bundle": "^3.4 || ^4.1 || ^5.0" + }, + "require-dev": { + "doctrine/data-fixtures": "^1.3", + "doctrine/doctrine-bundle": "^1.8 | ^2.0", + "doctrine/doctrine-fixtures-bundle": "^3.0.2", + "doctrine/orm": "^2.6", + "monolog/monolog": "~1.11 | ^2.0", + "phpunit/phpunit": "^7.5 || ^8.0", + "symfony/monolog-bridge": ">=3", + "symfony/monolog-bundle": "^3.2", + "symfony/phpunit-bridge": "^3.4 || ^4.1 || ^5.0", + "theofidry/alice-data-fixtures": "^1.0.1" + }, + "suggest": { + "doctrine/dbal": "Required when using the fixture loading functionality with an ORM and SQLite", + "doctrine/doctrine-fixtures-bundle": "Required when using the fixture loading functionality", + "doctrine/orm": "Required when using the fixture loading functionality with an ORM and SQLite", + "hautelook/alice-bundle": "Required when using loadFixtureFiles functionality with custom providers", + "theofidry/alice-data-fixtures": "Required when using loadFixtureFiles functionality" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Liip\\TestFixturesBundle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Liip AG", + "homepage": "http://www.liip.ch/" + }, + { + "name": "Community contributions", + "homepage": "https://github.com/liip/LiipTestFixturesBundle/contributors" + } + ], + "description": "This bundles enables efficient loading of Doctrine fixtures in functional test-cases for Symfony applications", + "keywords": [ + "fixtures", + "symfony", + "testing" + ], + "time": "2020-05-15T16:02:44+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.10.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/969b211f9a51aa1f6c01d1d2aef56d3bd91598e5", + "reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "replace": { + "myclabs/deep-copy": "self.version" + }, + "require-dev": { + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2020-06-29T13:22:24+00:00" + }, + { + "name": "nelmio/alice", + "version": "3.7.1", + "source": { + "type": "git", + "url": "https://github.com/nelmio/alice.git", + "reference": "d9a06e4b2e6ef274d4f572198e455cde993d87bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nelmio/alice/zipball/d9a06e4b2e6ef274d4f572198e455cde993d87bb", + "reference": "d9a06e4b2e6ef274d4f572198e455cde993d87bb", + "shasum": "" + }, + "require": { + "fzaninotto/faker": "^1.6", + "myclabs/deep-copy": "^1.5.2", + "php": "^7.3", + "sebastian/comparator": "^3.0 || ^4.0", + "symfony/property-access": "^2.8 || ^3.4 || ^4.0 || ^5.0", + "symfony/yaml": "^2.8 || ^3.4 || ^4.0 || ^5.0" + }, + "conflict": { + "symfony/framework-bundle": "<3.4" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.1.0", + "php-mock/php-mock": "^2.0", + "phpspec/prophecy": "^1.6", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^8.5.4 || ^9.0", + "symfony/phpunit-bridge": "^5.0", + "symfony/var-dumper": "^3.4 || ^4.0 || ^5.0" + }, + "suggest": { + "theofidry/alice-data-fixtures": "Wrapper for Alice to provide a persistence layer." + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": false + }, + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "autoload": { + "files": [ + "src/deep_clone.php" + ], + "psr-4": { + "Nelmio\\Alice\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be" + }, + { + "name": "Tim Shelburne", + "email": "shelburt02@gmail.com" + }, + { + "name": "Théo FIDRY", + "email": "theo.fidry@gmail.com" + } + ], + "description": "Expressive fixtures generator", + "keywords": [ + "Fixture", + "data", + "faker", + "test" + ], + "funding": [ + { + "url": "https://github.com/theofidry", + "type": "github" + } + ], + "time": "2020-06-03T12:55:55+00:00" + }, { "name": "nikic/php-parser", "version": "v4.4.0", @@ -4871,6 +5293,270 @@ ], "time": "2020-04-10T16:34:50+00:00" }, + { + "name": "sebastian/comparator", + "version": "4.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "dcc580eadfaa4e7f9d2cf9ae1922134ea962e14f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/dcc580eadfaa4e7f9d2cf9ae1922134ea962e14f", + "reference": "dcc580eadfaa4e7f9d2cf9ae1922134ea962e14f", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0", + "sebastian/diff": "^4.0", + "sebastian/exporter": "^4.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T12:05:46+00:00" + }, + { + "name": "sebastian/diff", + "version": "4.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "1e90b4cf905a7d06c420b1d2e9d11a4dc8a13113" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/1e90b4cf905a7d06c420b1d2e9d11a4dc8a13113", + "reference": "1e90b4cf905a7d06c420b1d2e9d11a4dc8a13113", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.0", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-30T04:46:02+00:00" + }, + { + "name": "sebastian/exporter", + "version": "4.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "571d721db4aec847a0e59690b954af33ebf9f023" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/571d721db4aec847a0e59690b954af33ebf9f023", + "reference": "571d721db4aec847a0e59690b954af33ebf9f023", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0", + "sebastian/recursion-context": "^4.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "^9.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T12:08:55+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "4.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "062231bf61d2b9448c4fa5a7643b5e1829c11d63" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/062231bf61d2b9448c4fa5a7643b5e1829c11d63", + "reference": "062231bf61d2b9448c4fa5a7643b5e1829c11d63", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-06-26T12:14:17+00:00" + }, { "name": "symfony/maker-bundle", "version": "v1.15.0", @@ -4938,6 +5624,91 @@ "scaffolding" ], "time": "2020-04-05T10:50:59+00:00" + }, + { + "name": "theofidry/alice-data-fixtures", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/theofidry/AliceDataFixtures.git", + "reference": "f98ef1b7965f043a497a49e8221f3327f2835cea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theofidry/AliceDataFixtures/zipball/f98ef1b7965f043a497a49e8221f3327f2835cea", + "reference": "f98ef1b7965f043a497a49e8221f3327f2835cea", + "shasum": "" + }, + "require": { + "nelmio/alice": "^3.5", + "php": "^7.2", + "psr/log": "^1.0" + }, + "conflict": { + "doctrine/orm": "<2.5", + "illuminate/database": "<5.5", + "ocramius/proxy-manager": "<2.1", + "symfony/framework-bundle": "<3.4" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.1", + "phpspec/prophecy": "^1.7", + "phpunit/phpunit": "^8.5.4 || ^9.0", + "symfony/phpunit-bridge": "^3.4 || ^4.0 || ^5.0" + }, + "suggest": { + "alcaeus/mongo-php-adapter": "To use Doctrine with the MongoDB flavour", + "doctrine/data-fixtures": "To use Doctrine", + "doctrine/dbal": "To use Doctrine with the PHPCR flavour", + "doctrine/mongodb": "To use Doctrine with the MongoDB flavour", + "doctrine/mongodb-odm": "To use Doctrine with the MongoDB flavour", + "doctrine/orm": "To use Doctrine ORM", + "doctrine/phpcr-odm": "To use Doctrine with the PHPCR flavour", + "illuminate/database": "To use Eloquent", + "jackalope/jackalope-doctrine-dbal": "To use Doctrine with the PHPCR flavour", + "ocramius/proxy-manager": "To avoid database connection on kernel boot" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": false + }, + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Fidry\\AliceDataFixtures\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Théo FIDRY", + "email": "theo.fidry@gmail.com", + "homepage": "https://github.com/theofidry" + } + ], + "description": "Nelmio alice extension to persist the loaded fixtures.", + "keywords": [ + "Fixture", + "alice", + "data", + "faker", + "orm", + "tests" + ], + "funding": [ + { + "url": "https://github.com/theofidry", + "type": "github" + } + ], + "time": "2020-06-19T13:54:56+00:00" } ], "aliases": [], @@ -4950,5 +5721,6 @@ "ext-ctype": "*", "ext-iconv": "*" }, - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "1.1.0" } diff --git a/config/bundles.php b/config/bundles.php index f702c9a..37966c3 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -8,4 +8,8 @@ Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], + Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['dev' => true, 'test' => true], + Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['dev' => true, 'test' => true], + Liip\TestFixturesBundle\LiipTestFixturesBundle::class => ['dev' => true, 'test' => true], + Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], ]; diff --git a/config/packages/dev/nelmio_alice.yaml b/config/packages/dev/nelmio_alice.yaml new file mode 100644 index 0000000..4cb9065 --- /dev/null +++ b/config/packages/dev/nelmio_alice.yaml @@ -0,0 +1,9 @@ +nelmio_alice: + functions_blacklist: + - 'current' + - 'shuffle' + - 'date' + - 'time' + - 'file' + - 'md5' + - 'sha1' diff --git a/config/packages/test/nelmio_alice.yaml b/config/packages/test/nelmio_alice.yaml new file mode 100644 index 0000000..caec543 --- /dev/null +++ b/config/packages/test/nelmio_alice.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: ../dev/nelmio_alice.yaml } diff --git a/symfony.lock b/symfony.lock index cbb53a5..bed1a16 100644 --- a/symfony.lock +++ b/symfony.lock @@ -20,6 +20,9 @@ "doctrine/common": { "version": "2.12.0" }, + "doctrine/data-fixtures": { + "version": "1.4.3" + }, "doctrine/dbal": { "version": "v2.10.1" }, @@ -38,6 +41,18 @@ "src/Repository/.gitignore" ] }, + "doctrine/doctrine-fixtures-bundle": { + "version": "3.0", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "3.0", + "ref": "fc52d86631a6dfd9fdf3381d0b7e3df2069e51b3" + }, + "files": [ + "src/DataFixtures/AppFixtures.php" + ] + }, "doctrine/doctrine-migrations-bundle": { "version": "1.2", "recipe": { @@ -75,9 +90,31 @@ "doctrine/reflection": { "version": "1.2.1" }, + "fzaninotto/faker": { + "version": "v1.9.1" + }, "jdorn/sql-formatter": { "version": "v1.2.17" }, + "liip/test-fixtures-bundle": { + "version": "1.9.1" + }, + "myclabs/deep-copy": { + "version": "1.10.1" + }, + "nelmio/alice": { + "version": "3.2", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "3.2", + "ref": "0b9900ece737bec7752e4155c0164639dd9b0cb0" + }, + "files": [ + "config/packages/dev/nelmio_alice.yaml", + "config/packages/test/nelmio_alice.yaml" + ] + }, "nikic/php-parser": { "version": "v4.4.0" }, @@ -102,6 +139,18 @@ "psr/log": { "version": "1.1.3" }, + "sebastian/comparator": { + "version": "4.0.3" + }, + "sebastian/diff": { + "version": "4.0.2" + }, + "sebastian/exporter": { + "version": "4.0.2" + }, + "sebastian/recursion-context": { + "version": "4.0.2" + }, "symfony/asset": { "version": "v5.0.7" }, @@ -348,6 +397,15 @@ "symfony/yaml": { "version": "v5.0.7" }, + "theofidry/alice-data-fixtures": { + "version": "1.0", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "1.0", + "ref": "fe5a50faf580eb58f08ada2abe8afbd2d4941e05" + } + }, "twig/extra-bundle": { "version": "v3.0.3" }, From 9b2dab67ec5a652bc4a9fe1e06ec160bf6da6472 Mon Sep 17 00:00:00 2001 From: 77web Date: Wed, 8 Jul 2020 12:47:22 +0900 Subject: [PATCH 03/15] =?UTF-8?q?npm=20install=E3=81=97=E3=81=9F=E3=82=89?= =?UTF-8?q?=E5=87=BA=E3=81=9F=E5=B7=AE=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index cd34d96..bb1d0c3 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,5 @@ "watch": "encore dev --watch", "build": "encore production --progress" }, - "dependencies": { - } + "dependencies": {} } From 3a6dc4f0edfd909a56a63a77b287baa3f478aec1 Mon Sep 17 00:00:00 2001 From: 77web Date: Wed, 8 Jul 2020 12:47:33 +0900 Subject: [PATCH 04/15] =?UTF-8?q?=E4=B8=80=E8=A6=A7=E7=94=BB=E9=9D=A2?= =?UTF-8?q?=E3=81=AE=E6=A9=9F=E8=83=BD=E3=83=86=E3=82=B9=E3=83=88=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/articles/index.html.twig | 1 - tests/Controller/Articles/IndexTest.php | 26 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/Controller/Articles/IndexTest.php diff --git a/templates/articles/index.html.twig b/templates/articles/index.html.twig index d605356..3941cbd 100644 --- a/templates/articles/index.html.twig +++ b/templates/articles/index.html.twig @@ -34,7 +34,6 @@ {{ article.createdAt|date('Y/m/d') }} {% endfor %} - diff --git a/tests/Controller/Articles/IndexTest.php b/tests/Controller/Articles/IndexTest.php new file mode 100644 index 0000000..c916e90 --- /dev/null +++ b/tests/Controller/Articles/IndexTest.php @@ -0,0 +1,26 @@ +loadFixtureFiles([ + __DIR__.'/../../../var/fixtures/Controller/Articles/index.yaml', + ]); + + $crawler = $client->request('GET', '/articles'); + + $response = $client->getResponse(); + $this->assertTrue($response->isOk(), $response->getStatusCode()); + + $this->assertCount(2, $crawler->filter('table tbody tr')); + } +} From efd196821dba552acfb903580f4453b2f296ea4c Mon Sep 17 00:00:00 2001 From: 77web Date: Wed, 8 Jul 2020 12:47:40 +0900 Subject: [PATCH 05/15] =?UTF-8?q?=E6=96=B0=E8=A6=8F=E7=99=BB=E9=8C=B2?= =?UTF-8?q?=E3=81=AE=E6=A9=9F=E8=83=BD=E3=83=86=E3=82=B9=E3=83=88=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/articles/new.html.twig | 1 + tests/Controller/Articles/NewTest.php | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/Controller/Articles/NewTest.php diff --git a/templates/articles/new.html.twig b/templates/articles/new.html.twig index 0743329..529eba2 100644 --- a/templates/articles/new.html.twig +++ b/templates/articles/new.html.twig @@ -6,6 +6,7 @@

フォーム

{{ form_start(form) }} {{ form_widget(form) }} + {{ form_end(form) }} {% endblock %} diff --git a/tests/Controller/Articles/NewTest.php b/tests/Controller/Articles/NewTest.php new file mode 100644 index 0000000..135075c --- /dev/null +++ b/tests/Controller/Articles/NewTest.php @@ -0,0 +1,27 @@ +loadFixtureFiles([]); + + $crawler = $client->request('GET', '/articles/new'); + $form = $crawler->selectButton('投稿する')->form(); + + $form['article[name]'] = 'test-name'; + $form['article[body]'] = 'test-body'; + $client->submit($form); + + $response = $client->getResponse(); + $this->assertTrue($response->isRedirect('/articles'), $response->headers->get('Location')); + } +} From f0db3266d828ad80af9a5e4141d55aa7b981602a Mon Sep 17 00:00:00 2001 From: 77web Date: Wed, 8 Jul 2020 12:47:49 +0900 Subject: [PATCH 06/15] =?UTF-8?q?sensio/framework-extra-bundle=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 1 + composer.lock | 73 +++++++++++++++++++++ config/bundles.php | 1 + config/packages/sensio_framework_extra.yaml | 3 + symfony.lock | 12 ++++ 5 files changed, 90 insertions(+) create mode 100644 config/packages/sensio_framework_extra.yaml diff --git a/composer.json b/composer.json index a6ea4dc..27f7768 100644 --- a/composer.json +++ b/composer.json @@ -5,6 +5,7 @@ "php": "^7.2.5", "ext-ctype": "*", "ext-iconv": "*", + "sensio/framework-extra-bundle": "^5.5", "symfony/asset": "5.0.*", "symfony/console": "5.0.*", "symfony/dotenv": "5.0.*", diff --git a/composer.lock b/composer.lock index c287dfb..65b35a9 100644 --- a/composer.lock +++ b/composer.lock @@ -1509,6 +1509,79 @@ ], "time": "2020-03-23T09:12:05+00:00" }, + { + "name": "sensio/framework-extra-bundle", + "version": "v5.5.6", + "source": { + "type": "git", + "url": "https://github.com/sensiolabs/SensioFrameworkExtraBundle.git", + "reference": "b49f079d8a87a6e6dd434062085ff5a132af466b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sensiolabs/SensioFrameworkExtraBundle/zipball/b49f079d8a87a6e6dd434062085ff5a132af466b", + "reference": "b49f079d8a87a6e6dd434062085ff5a132af466b", + "shasum": "" + }, + "require": { + "doctrine/annotations": "^1.0", + "php": ">=7.1.3", + "symfony/config": "^4.4|^5.0", + "symfony/dependency-injection": "^4.4|^5.0", + "symfony/framework-bundle": "^4.4|^5.0", + "symfony/http-kernel": "^4.4|^5.0" + }, + "conflict": { + "doctrine/doctrine-cache-bundle": "<1.3.1" + }, + "require-dev": { + "doctrine/doctrine-bundle": "^1.11|^2.0", + "doctrine/orm": "^2.5", + "nyholm/psr7": "^1.1", + "symfony/browser-kit": "^4.4|^5.0", + "symfony/dom-crawler": "^4.4|^5.0", + "symfony/expression-language": "^4.4|^5.0", + "symfony/finder": "^4.4|^5.0", + "symfony/monolog-bridge": "^4.0|^5.0", + "symfony/monolog-bundle": "^3.2", + "symfony/phpunit-bridge": "^4.3.5|^5.0", + "symfony/psr-http-message-bridge": "^1.1", + "symfony/security-bundle": "^4.4|^5.0", + "symfony/twig-bundle": "^4.4|^5.0", + "symfony/yaml": "^4.4|^5.0", + "twig/twig": "^1.34|^2.4|^3.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "5.5.x-dev" + } + }, + "autoload": { + "psr-4": { + "Sensio\\Bundle\\FrameworkExtraBundle\\": "src/" + }, + "exclude-from-classmap": [ + "/tests/" + ] + }, + "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": "2020-06-15T20:28:02+00:00" + }, { "name": "symfony/asset", "version": "v5.0.7", diff --git a/config/bundles.php b/config/bundles.php index 37966c3..6c97571 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -12,4 +12,5 @@ Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['dev' => true, 'test' => true], Liip\TestFixturesBundle\LiipTestFixturesBundle::class => ['dev' => true, 'test' => true], Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], + Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], ]; diff --git a/config/packages/sensio_framework_extra.yaml b/config/packages/sensio_framework_extra.yaml new file mode 100644 index 0000000..1821ccc --- /dev/null +++ b/config/packages/sensio_framework_extra.yaml @@ -0,0 +1,3 @@ +sensio_framework_extra: + router: + annotations: false diff --git a/symfony.lock b/symfony.lock index bed1a16..57b4d8c 100644 --- a/symfony.lock +++ b/symfony.lock @@ -151,6 +151,18 @@ "sebastian/recursion-context": { "version": "4.0.2" }, + "sensio/framework-extra-bundle": { + "version": "5.2", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "5.2", + "ref": "fb7e19da7f013d0d422fa9bce16f5c510e27609b" + }, + "files": [ + "config/packages/sensio_framework_extra.yaml" + ] + }, "symfony/asset": { "version": "v5.0.7" }, From fca5507b9533f9db97a518e81ce0b66aea8aadec Mon Sep 17 00:00:00 2001 From: 77web Date: Wed, 8 Jul 2020 12:48:08 +0900 Subject: [PATCH 07/15] =?UTF-8?q?render=E3=81=A7=E3=81=AA=E3=81=8F@Templat?= =?UTF-8?q?e=E3=82=A2=E3=83=8E=E3=83=86=E3=83=BC=E3=82=B7=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=82=92=E4=BD=BF=E3=81=86=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/ArticlesController.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Controller/ArticlesController.php b/src/Controller/ArticlesController.php index 9efa30c..f4358dc 100644 --- a/src/Controller/ArticlesController.php +++ b/src/Controller/ArticlesController.php @@ -8,6 +8,7 @@ use App\Repository\PostCountRepository; use DateTime; use Exception; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -18,20 +19,24 @@ class ArticlesController extends AbstractController { /** * @Route("/articles", name="articles") + * @Template() + * @return array */ public function index() { $articleRepository = $this->getDoctrine()->getRepository(Article::class); $articles = $articleRepository->findAll(); - return $this->render('articles/index.html.twig', [ + + return [ 'articles' => $articles, - ]); + ]; } /** * @Route("/articles/new", name="articles_new") + * @Template * @param Request $request - * @return RedirectResponse|Response + * @return RedirectResponse|array * @throws Exception */ public function new(Request $request) @@ -61,8 +66,8 @@ public function new(Request $request) return $this->redirectToRoute('articles'); } - return $this->render('articles/new.html.twig', [ + return [ 'form' => $form->createView(), - ]); + ]; } } From 8e1ac6eb585a4d93673837e08c1cf7ad1f918bc6 Mon Sep 17 00:00:00 2001 From: 77web Date: Wed, 8 Jul 2020 12:51:55 +0900 Subject: [PATCH 08/15] =?UTF-8?q?[=E7=99=BB=E9=8C=B2]=20=E6=8A=95=E7=A8=BF?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=9FArticle,=20=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=82=8BArticle,=20Article=E3=82=92=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E3=81=99=E3=82=8B=E3=82=AF=E3=83=A9=E3=82=B9=E3=81=AE?= =?UTF-8?q?interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Model/ArticleInterface.php | 8 ++++++++ src/Model/ArticlePersisterInterface.php | 8 ++++++++ src/Model/PostedArticleInterface.php | 7 +++++++ 3 files changed, 23 insertions(+) create mode 100644 src/Model/ArticleInterface.php create mode 100644 src/Model/ArticlePersisterInterface.php create mode 100644 src/Model/PostedArticleInterface.php diff --git a/src/Model/ArticleInterface.php b/src/Model/ArticleInterface.php new file mode 100644 index 0000000..e29e61d --- /dev/null +++ b/src/Model/ArticleInterface.php @@ -0,0 +1,8 @@ + Date: Wed, 8 Jul 2020 22:09:45 +0900 Subject: [PATCH 09/15] =?UTF-8?q?[=E7=99=BB=E9=8C=B2]=20ArticlePersister?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E3=81=A3=E3=81=A6=E7=99=BB=E9=8C=B2=E3=81=99?= =?UTF-8?q?=E3=82=8BUseCase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DTO/Request/PostedArticle.php | 60 +++++++++++++++++++ src/Entity/Article.php | 7 +-- .../Article/Exception/RegisterException.php | 8 +++ .../UseCase/Article/RegisterUseCase.php | 37 ++++++++++++ .../UseCase/Article/RegisterUseCaseTest.php | 37 ++++++++++++ 5 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 src/DTO/Request/PostedArticle.php create mode 100644 src/Service/UseCase/Article/Exception/RegisterException.php create mode 100644 src/Service/UseCase/Article/RegisterUseCase.php create mode 100644 tests/Service/UseCase/Article/RegisterUseCaseTest.php diff --git a/src/DTO/Request/PostedArticle.php b/src/DTO/Request/PostedArticle.php new file mode 100644 index 0000000..9b61894 --- /dev/null +++ b/src/DTO/Request/PostedArticle.php @@ -0,0 +1,60 @@ +name; + } + + /** + * @param string|null $name + * @return PostedArticle + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * @return string|null + */ + public function getBody(): ?string + { + return $this->body; + } + + /** + * @param string|null $body + * @return PostedArticle + */ + public function setBody($body) + { + $this->body = $body; + + return $this; + } +} diff --git a/src/Entity/Article.php b/src/Entity/Article.php index 50996b2..b7626cd 100644 --- a/src/Entity/Article.php +++ b/src/Entity/Article.php @@ -2,15 +2,15 @@ namespace App\Entity; +use App\Model\ArticleInterface; use DateTimeInterface as DateTimeInterfaceAlias; use Doctrine\ORM\Mapping as ORM; -use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Entity(repositoryClass="App\Repository\ArticleRepository") * @ORM\HasLifecycleCallbacks() */ -class Article +class Article implements ArticleInterface { /** * @ORM\Id() @@ -21,14 +21,11 @@ class Article /** * @ORM\Column(type="string", length=255) - * @Assert\NotBlank - * @Assert\Length(max=255) */ private $name; /** * @ORM\Column(type="text") - * @Assert\Length(max=1000) */ private $body; diff --git a/src/Service/UseCase/Article/Exception/RegisterException.php b/src/Service/UseCase/Article/Exception/RegisterException.php new file mode 100644 index 0000000..1f524e0 --- /dev/null +++ b/src/Service/UseCase/Article/Exception/RegisterException.php @@ -0,0 +1,8 @@ +articlePersister = $articlePersister; + } + + /** + * @param PostedArticle $postedArticle + * @throws RegisterException + */ + public function register(PostedArticle $postedArticle): void + { + try { + $this->articlePersister->persist($postedArticle, new Article()); + } catch (\Exception $e) { + throw new RegisterException($e->getMessage(), '', $e); + } + } +} diff --git a/tests/Service/UseCase/Article/RegisterUseCaseTest.php b/tests/Service/UseCase/Article/RegisterUseCaseTest.php new file mode 100644 index 0000000..ce2e368 --- /dev/null +++ b/tests/Service/UseCase/Article/RegisterUseCaseTest.php @@ -0,0 +1,37 @@ +articlePersisterP = $this->prophesize(ArticlePersisterInterface::class); + } + + public function test() + { + $postedArticle = $this->prophesize(PostedArticle::class)->reveal(); + + $this->articlePersisterP->persist($postedArticle, new Article())->willReturnArgument(1)->shouldBeCalled(); + + $this->getSUT()->register($postedArticle); + } + + private function getSUT(): RegisterUseCase + { + return new RegisterUseCase($this->articlePersisterP->reveal()); + } +} From 74db0e3d86c896c6ce9b65d4c99ee03fa5ad7205 Mon Sep 17 00:00:00 2001 From: 77web Date: Wed, 7 Oct 2020 21:44:57 +0900 Subject: [PATCH 10/15] =?UTF-8?q?ArticlePersister=E3=81=AE=E5=AE=9F?= =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Entity/Article.php | 4 +-- src/Model/ArticleInterface.php | 2 ++ src/Model/PostedArticleInterface.php | 3 ++ src/Service/ArticlePersister.php | 42 ++++++++++++++++++++++++ tests/Service/ArticlePersisterTest.php | 44 ++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 src/Service/ArticlePersister.php create mode 100644 tests/Service/ArticlePersisterTest.php diff --git a/src/Entity/Article.php b/src/Entity/Article.php index b7626cd..8925aa9 100644 --- a/src/Entity/Article.php +++ b/src/Entity/Article.php @@ -49,7 +49,7 @@ public function getName(): ?string return $this->name; } - public function setName(string $name): self + public function setName(string $name): ArticleInterface { $this->name = $name; @@ -61,7 +61,7 @@ public function getBody(): ?string return $this->body; } - public function setBody(string $body): self + public function setBody(string $body): ArticleInterface { $this->body = $body; diff --git a/src/Model/ArticleInterface.php b/src/Model/ArticleInterface.php index e29e61d..814c311 100644 --- a/src/Model/ArticleInterface.php +++ b/src/Model/ArticleInterface.php @@ -4,5 +4,7 @@ interface ArticleInterface { + public function setName(string $name): self; + public function setBody(string $body): self; } diff --git a/src/Model/PostedArticleInterface.php b/src/Model/PostedArticleInterface.php index 1312c91..208520b 100644 --- a/src/Model/PostedArticleInterface.php +++ b/src/Model/PostedArticleInterface.php @@ -4,4 +4,7 @@ interface PostedArticleInterface { + public function getName(): ?string; + + public function getBody(): ?string; } diff --git a/src/Service/ArticlePersister.php b/src/Service/ArticlePersister.php new file mode 100644 index 0000000..ca76da9 --- /dev/null +++ b/src/Service/ArticlePersister.php @@ -0,0 +1,42 @@ +em = $em; + } + + public function persist(PostedArticleInterface $postedArticle, ArticleInterface $saveArticle): ArticleInterface + { + /** @var PostedArticle $postedArticle */ + /** @var Article $saveArticle */ + $saveArticle + ->setName($postedArticle->getName()) + ->setBody($postedArticle->getBody()) + ; + + $this->em->persist($saveArticle); + $this->em->flush(); + + return $saveArticle; + } + +} diff --git a/tests/Service/ArticlePersisterTest.php b/tests/Service/ArticlePersisterTest.php new file mode 100644 index 0000000..aa8873e --- /dev/null +++ b/tests/Service/ArticlePersisterTest.php @@ -0,0 +1,44 @@ +emP = $this->prophesize(EntityManagerInterface::class); + } + + public function test() + { + $dto = new PostedArticle(); + $dto + ->setName($name = 'dummy-name') + ->setBody($body = 'dummy-body') + ; + $ormEntity = new Article(); + + $this->emP->persist($ormEntity)->shouldBeCalled(); + $this->emP->flush()->shouldBeCalled(); + + $returned = $this->getSUT()->persist($dto, $ormEntity); + $this->assertSame($ormEntity, $returned); + $this->assertEquals($name, $returned->getName()); + $this->assertEquals($body, $returned->getBody()); + } + + private function getSUT(): ArticlePersister + { + return new ArticlePersister( + $this->emP->reveal() + ); + } +} From b2ab76b421812cebdd75c09fcef739c91216c61b Mon Sep 17 00:00:00 2001 From: 77web Date: Sat, 10 Oct 2020 23:19:42 +0900 Subject: [PATCH 11/15] =?UTF-8?q?=E8=A8=98=E4=BA=8B=E4=BB=B6=E6=95=B0?= =?UTF-8?q?=E3=82=92=E4=BF=9D=E5=AD=98=E3=81=99=E3=82=8BArticleCounterInte?= =?UTF-8?q?rface=E3=82=92=E5=AE=9A=E7=BE=A9=EF=BC=88=E3=81=99=E3=81=A7?= =?UTF-8?q?=E3=81=AB=E7=99=BB=E9=8C=B2=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=82=8B=E3=82=82=E3=81=AE=E3=81=AE=E6=9B=B4=E6=96=B0=E6=99=82?= =?UTF-8?q?=E3=81=AB=E3=81=AF=E4=BD=BF=E3=82=8F=E3=81=AA=E3=81=84=E3=81=AE?= =?UTF-8?q?=E3=81=A7Persister=E3=81=AB=E3=81=AF=E5=85=A5=E3=82=8C=E3=81=AA?= =?UTF-8?q?=E3=81=84=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Model/ArticleCounterInterface.php | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/Model/ArticleCounterInterface.php diff --git a/src/Model/ArticleCounterInterface.php b/src/Model/ArticleCounterInterface.php new file mode 100644 index 0000000..79a959b --- /dev/null +++ b/src/Model/ArticleCounterInterface.php @@ -0,0 +1,8 @@ + Date: Sat, 10 Oct 2020 23:27:28 +0900 Subject: [PATCH 12/15] =?UTF-8?q?RegisterUseCase=E3=81=A7ArticleCounter?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E3=81=86=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UseCase/Article/RegisterUseCase.php | 16 ++++++++-- .../UseCase/Article/RegisterUseCaseTest.php | 32 ++++++++++++++++++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/Service/UseCase/Article/RegisterUseCase.php b/src/Service/UseCase/Article/RegisterUseCase.php index 0c7485d..f4164af 100644 --- a/src/Service/UseCase/Article/RegisterUseCase.php +++ b/src/Service/UseCase/Article/RegisterUseCase.php @@ -4,6 +4,7 @@ use App\DTO\Request\PostedArticle; use App\Entity\Article; +use App\Model\ArticleCounterInterface; use App\Model\ArticlePersisterInterface; use App\Service\UseCase\Article\Exception\RegisterException; @@ -14,12 +15,19 @@ class RegisterUseCase */ private $articlePersister; + /** + * @var ArticleCounterInterface + */ + private $articleCounter; + /** * @param ArticlePersisterInterface $articlePersister + * @param ArticleCounterInterface $articleCounter */ - public function __construct(ArticlePersisterInterface $articlePersister) + public function __construct(ArticlePersisterInterface $articlePersister, ArticleCounterInterface $articleCounter) { $this->articlePersister = $articlePersister; + $this->articleCounter = $articleCounter; } /** @@ -29,9 +37,11 @@ public function __construct(ArticlePersisterInterface $articlePersister) public function register(PostedArticle $postedArticle): void { try { - $this->articlePersister->persist($postedArticle, new Article()); + $savedArticle = $this->articlePersister->persist($postedArticle, new Article()); } catch (\Exception $e) { - throw new RegisterException($e->getMessage(), '', $e); + throw new RegisterException($e->getMessage(), $e->getCode(), $e); } + + $this->articleCounter->count($savedArticle); } } diff --git a/tests/Service/UseCase/Article/RegisterUseCaseTest.php b/tests/Service/UseCase/Article/RegisterUseCaseTest.php index ce2e368..6670090 100644 --- a/tests/Service/UseCase/Article/RegisterUseCaseTest.php +++ b/tests/Service/UseCase/Article/RegisterUseCaseTest.php @@ -4,9 +4,12 @@ use App\DTO\Request\PostedArticle; use App\Entity\Article; +use App\Model\ArticleCounterInterface; use App\Model\ArticlePersisterInterface; +use App\Service\UseCase\Article\Exception\RegisterException; use App\Service\UseCase\Article\RegisterUseCase; use PHPUnit\Framework\TestCase; +use Prophecy\Argument; use Prophecy\Prophecy\ObjectProphecy; class RegisterUseCaseTest extends TestCase @@ -16,9 +19,21 @@ class RegisterUseCaseTest extends TestCase */ private $articlePersisterP; + /** + * @var ArticleCounterInterface|ObjectProphecy + */ + private $articleCounterP; + protected function setUp(): void { $this->articlePersisterP = $this->prophesize(ArticlePersisterInterface::class); + $this->articleCounterP = $this->prophesize(ArticleCounterInterface::class); + } + + protected function tearDown(): void + { + $this->articlePersisterP = null; + $this->articleCounterP = null; } public function test() @@ -26,12 +41,27 @@ public function test() $postedArticle = $this->prophesize(PostedArticle::class)->reveal(); $this->articlePersisterP->persist($postedArticle, new Article())->willReturnArgument(1)->shouldBeCalled(); + $this->articleCounterP->count(Argument::type(Article::class))->shouldBeCalled(); + + $this->getSUT()->register($postedArticle); + } + + public function test_保存でエラーが出たらcountは更新しない() + { + $this->expectException(RegisterException::class); + + $postedArticle = $this->prophesize(PostedArticle::class)->reveal(); + $this->articlePersisterP->persist($postedArticle, new Article())->willThrow( new \Exception('dummy-error'))->shouldBeCalled(); + $this->articleCounterP->count(Argument::any())->shouldNotBeCalled(); $this->getSUT()->register($postedArticle); } private function getSUT(): RegisterUseCase { - return new RegisterUseCase($this->articlePersisterP->reveal()); + return new RegisterUseCase( + $this->articlePersisterP->reveal(), + $this->articleCounterP->reveal() + ); } } From 0db4027427742c0ac8e66b0b5072fabe3539fffc Mon Sep 17 00:00:00 2001 From: 77web Date: Sat, 10 Oct 2020 23:31:54 +0900 Subject: [PATCH 13/15] =?UTF-8?q?ArticleCounter=E3=81=AE=E5=AE=9F=E3=82=AF?= =?UTF-8?q?=E3=83=A9=E3=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Entity/PostCount.php | 8 +++- src/Model/ArticleInterface.php | 2 + src/Model/PostCountFinderInterface.php | 8 ++++ src/Model/PostCountInterface.php | 8 ++++ src/Repository/PostCountRepository.php | 20 ++++++++- src/Service/ArticleCounter.php | 43 +++++++++++++++++++ .../FindOneByPostDateOrCreateTest.php | 42 ++++++++++++++++++ tests/Service/ArticleCounterTest.php | 38 ++++++++++++++++ 8 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 src/Model/PostCountFinderInterface.php create mode 100644 src/Model/PostCountInterface.php create mode 100644 src/Service/ArticleCounter.php create mode 100644 tests/Functional/Repository/PostCountRepositoryTest/FindOneByPostDateOrCreateTest.php create mode 100644 tests/Service/ArticleCounterTest.php diff --git a/src/Entity/PostCount.php b/src/Entity/PostCount.php index 4c141f1..e79f0b4 100644 --- a/src/Entity/PostCount.php +++ b/src/Entity/PostCount.php @@ -2,6 +2,7 @@ namespace App\Entity; +use App\Model\PostCountInterface; use Doctrine\ORM\Mapping as ORM; /** @@ -10,7 +11,7 @@ * @ORM\UniqueConstraint(columns={"post_date"} * )}) */ -class PostCount +class PostCount implements PostCountInterface { /** * @ORM\Id() @@ -57,4 +58,9 @@ public function setPostCount(int $postCount): self return $this; } + + public function countUp(): void + { + $this->postCount++; + } } diff --git a/src/Model/ArticleInterface.php b/src/Model/ArticleInterface.php index 814c311..2e0c127 100644 --- a/src/Model/ArticleInterface.php +++ b/src/Model/ArticleInterface.php @@ -7,4 +7,6 @@ interface ArticleInterface public function setName(string $name): self; public function setBody(string $body): self; + + public function getCreatedAt(): ?\DateTimeInterface; } diff --git a/src/Model/PostCountFinderInterface.php b/src/Model/PostCountFinderInterface.php new file mode 100644 index 0000000..ecb8cb9 --- /dev/null +++ b/src/Model/PostCountFinderInterface.php @@ -0,0 +1,8 @@ +findOneBy([ + 'postDate' => $postedDate, + ]); + if (!$targetCount) { + $targetCount = new PostCount(); + $targetCount + ->setPostDate($postedDate) + ->setPostCount(0) + ; + } + + return $targetCount; + } + // /** // * @return PostCount[] Returns an array of PostCount objects // */ diff --git a/src/Service/ArticleCounter.php b/src/Service/ArticleCounter.php new file mode 100644 index 0000000..4d9a592 --- /dev/null +++ b/src/Service/ArticleCounter.php @@ -0,0 +1,43 @@ +postCountFinder = $postCountFinder; + $this->em = $em; + } + + public function count(ArticleInterface $article): void + { + /** @var Article $article */ + $postCount = $this->postCountFinder->findOneByPostDateOrCreate($article->getCreatedAt()); + $postCount->countUp(); + + $this->em->persist($postCount); + $this->em->flush(); + } + +} diff --git a/tests/Functional/Repository/PostCountRepositoryTest/FindOneByPostDateOrCreateTest.php b/tests/Functional/Repository/PostCountRepositoryTest/FindOneByPostDateOrCreateTest.php new file mode 100644 index 0000000..d3018d3 --- /dev/null +++ b/tests/Functional/Repository/PostCountRepositoryTest/FindOneByPostDateOrCreateTest.php @@ -0,0 +1,42 @@ +loadFixtureFiles([ + __DIR__.'/../../../../var/fixtures/Repository/PostCountRepository/find_one_by_post_date_or_create.yaml', + ]); + static::ensureKernelShutdown(); + } + + public function test_既存PostCountがある場合() + { + $actual = $this->getSUT()->findOneByPostDateOrCreate(new \DateTimeImmutable('2020-09-01')); + $this->assertEquals(1, $actual->getPostCount(), '保存されているエンティティが出てきている'); + } + + public function test_既存PostCountがない場合() + { + $actual = $this->getSUT()->findOneByPostDateOrCreate(new \DateTimeImmutable('2020-09-02')); + $this->assertNull($actual->getId()); + $this->assertNotNull($actual->getPostDate(), '日付はセット済'); + $this->assertEquals(null, $actual->getPostCount(), 'newされたばかりなのでnull'); + } + + private function getSUT(): PostCountRepository + { + static::bootKernel(); + + return self::$kernel->getContainer()->get('doctrine')->getManager()->getRepository(PostCount::class); + } +} diff --git a/tests/Service/ArticleCounterTest.php b/tests/Service/ArticleCounterTest.php new file mode 100644 index 0000000..0ffc6e6 --- /dev/null +++ b/tests/Service/ArticleCounterTest.php @@ -0,0 +1,38 @@ +prophesize(ArticleInterface::class); + $articleP->getCreatedAt()->willReturn($createdAt)->shouldBeCalled(); + $article = $articleP->reveal(); + + $postCountP = $this->prophesize(PostCountInterface::class); + $postCountP->countUp()->shouldBeCalled(); + $postCount = $postCountP->reveal(); + + $finderP = $this->prophesize(PostCountFinderInterface::class); + $emP = $this->prophesize(EntityManagerInterface::class); + + $finderP->findOneByPostDateOrCreate($createdAt)->willReturn($postCount)->shouldBeCalled(); + $emP->persist($postCount)->shouldBeCalled(); + $emP->flush()->shouldBeCalled(); + + $SUT = new ArticleCounter( + $finderP->reveal(), + $emP->reveal() + ); + $SUT->count($article); + } +} From 80ba040060c3fbb2472ccdd697ebbe7ee8f32ae8 Mon Sep 17 00:00:00 2001 From: 77web Date: Sun, 11 Oct 2020 00:03:03 +0900 Subject: [PATCH 14/15] =?UTF-8?q?ArticleType=E3=81=A7=E6=89=B1=E3=81=86?= =?UTF-8?q?=E3=81=AE=E3=82=92=E3=82=A8=E3=83=B3=E3=83=86=E3=82=A3=E3=83=86?= =?UTF-8?q?=E3=82=A3=E3=81=8B=E3=82=89DTO\Request\PostedArticle=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Form/ArticleType.php | 4 ++-- tests/Form/ArticleTypeTest.php | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/Form/ArticleTypeTest.php diff --git a/src/Form/ArticleType.php b/src/Form/ArticleType.php index 591ad6e..a6a5ef2 100644 --- a/src/Form/ArticleType.php +++ b/src/Form/ArticleType.php @@ -2,7 +2,7 @@ namespace App\Form; -use App\Entity\Article; +use App\DTO\Request\PostedArticle; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextareaType; @@ -24,7 +24,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ - 'data_class' => Article::class, + 'data_class' => PostedArticle::class, ]); } } diff --git a/tests/Form/ArticleTypeTest.php b/tests/Form/ArticleTypeTest.php new file mode 100644 index 0000000..fd8731e --- /dev/null +++ b/tests/Form/ArticleTypeTest.php @@ -0,0 +1,23 @@ +factory->create(ArticleType::class); + $form->submit([ + 'name' => 'aaa', + 'body' => 'bbb', + ]); + + $this->assertTrue($form->isSubmitted()); + $this->assertTrue($form->isValid()); + $this->assertInstanceOf(PostedArticle::class, $form->getData()); + } +} From 709d91beadc7d0b40d893292ad08a5487caae77e Mon Sep 17 00:00:00 2001 From: 77web Date: Sun, 11 Oct 2020 00:04:41 +0900 Subject: [PATCH 15/15] =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=83=88=E3=83=AD?= =?UTF-8?q?=E3=83=BC=E3=83=A9=E3=81=8B=E3=82=89=E3=82=82=E7=99=BB=E9=8C=B2?= =?UTF-8?q?=E6=99=82=E3=81=AEUseCase=E3=82=92=E4=BD=BF=E3=81=86=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4=EF=BC=88=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=82=E9=80=9A=E3=82=8B=E3=81=93=E3=81=A8=E3=82=92?= =?UTF-8?q?=E7=A2=BA=E8=AA=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/ArticlesController.php | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Controller/ArticlesController.php b/src/Controller/ArticlesController.php index f4358dc..673e703 100644 --- a/src/Controller/ArticlesController.php +++ b/src/Controller/ArticlesController.php @@ -6,6 +6,7 @@ use App\Entity\PostCount; use App\Form\ArticleType; use App\Repository\PostCountRepository; +use App\Service\UseCase\Article\RegisterUseCase; use DateTime; use Exception; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; @@ -17,6 +18,19 @@ class ArticlesController extends AbstractController { + /** + * @var RegisterUseCase + */ + private $registerUseCase; + + /** + * @param RegisterUseCase $registerUseCase + */ + public function __construct(RegisterUseCase $registerUseCase) + { + $this->registerUseCase = $registerUseCase; + } + /** * @Route("/articles", name="articles") * @Template() @@ -41,26 +55,12 @@ public function index() */ public function new(Request $request) { - $article = new Article(); - $form = $this->createForm(ArticleType::class, $article); + $form = $this->createForm(ArticleType::class); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $article = $form->getData(); - $entityManager = $this->getDoctrine()->getManager(); - $entityManager->persist($article); - /** @var PostCountRepository $postCountRepository */ - $postCountRepository = $this->getDoctrine()->getRepository(PostCount::class); - $postCount = $postCountRepository->findOneBy([ - 'postDate' => new DateTime(), - ]); - if (empty($postCount)) { - $postCount = new PostCount(); - $postCount->setPostDate(new DateTime()); - $entityManager->persist($postCount); - } - $postCount->setPostCount($postCount->getPostCount() + 1); - $entityManager->flush(); + $this->registerUseCase->register($article); $this->addFlash('success', '登録しました'); return $this->redirectToRoute('articles');