From d033405c59fe047bd74080527ec01a36cca65c37 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Thu, 26 Nov 2020 16:22:49 +0900 Subject: [PATCH 1/6] Fix travis.yml --- .travis.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5d18ecf..0eff260 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,8 +22,10 @@ env: PLUGIN_CODE=Api ECCUBE_PACKAGE_API_URL=http://127.0.0.1:8080 matrix: - - DATABASE_URL=mysql://root:@localhost/cube4_dev DATABASE_SERVER_VERSION=5 - - DATABASE_URL=postgres://postgres:password@localhost/cube4_dev DATABASE_SERVER_VERSION=9 + - ECCUBE_VERSION=4.0.5 DATABASE_URL=mysql://root:@localhost/cube4_dev DATABASE_SERVER_VERSION=5 + - ECCUBE_VERSION=4.0.5 DATABASE_URL=postgres://postgres:password@localhost/cube4_dev DATABASE_SERVER_VERSION=9 + - ECCUBE_VERSION=4.1 DATABASE_URL=mysql://root:@localhost/cube4_dev DATABASE_SERVER_VERSION=5 + - ECCUBE_VERSION=4.1 DATABASE_URL=postgres://postgres:password@localhost/cube4_dev DATABASE_SERVER_VERSION=9 before_install: &php_setup | echo "opcache.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini @@ -37,8 +39,9 @@ install_eccube: &install_eccube | tar cvzf ${HOME}/${PLUGIN_CODE}.tar.gz ./* git clone https://github.com/EC-CUBE/ec-cube.git cd ec-cube - git checkout experimental/plugin_bundle - composer selfupdate --1 + git checkout ${ECCUBE_VERSION} + if [[ $ECCUBE_VERSION = '4.0.5' ]]; then composer selfupdate --1 ; fi + if [[ $ECCUBE_VERSION = '4.1' ]]; then composer selfupdate ; fi composer install --dev --no-interaction -o --apcu-autoloader package_api_setup: &package_api_setup | From a388b5b6d904484e783c3291d719cc2d59e3a230 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Thu, 26 Nov 2020 16:46:20 +0900 Subject: [PATCH 2/6] Fix composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 83b6e23..7ae2b2f 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,10 @@ { - "name": "ec-cube/Api", - "version": "1.0.0", + "name": "ec-cube/api", + "version": "2.0.0", "description": "Web API", "type": "eccube-plugin", "require": { - "ec-cube/plugin-installer": "~0.0.6", + "ec-cube/plugin-installer": "~0.0.6 || ^2.0@dev", "trikoder/oauth2-bundle": "^2.1", "nyholm/psr7": "^1.2", "webonyx/graphql-php": "^14.0" From 4fa064c64861e6cdf3affd640c6ad8b27efad34b Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Thu, 26 Nov 2020 17:43:21 +0900 Subject: [PATCH 3/6] Symfony4.4 support --- DependencyInjection/ApiExtension.php | 1 + GraphQL/Mutation/UpdateProductStockMutation.php | 6 +++--- GraphQL/Mutation/UpdateShippedMutation.php | 6 +++--- GraphQL/Query/SearchFormQuery.php | 12 ++++++------ Resource/config/services.yaml | 3 +++ Resource/locale/messages.en.yaml | 6 +++--- Resource/locale/messages.ja.yaml | 6 +++--- 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/DependencyInjection/ApiExtension.php b/DependencyInjection/ApiExtension.php index 342ff49..3d1e208 100644 --- a/DependencyInjection/ApiExtension.php +++ b/DependencyInjection/ApiExtension.php @@ -33,6 +33,7 @@ public function prepend(ContainerBuilder $container) 'security' => true, 'stateless' => true, 'oauth2' => true, + 'provider' => 'member_provider' ]; } $replaced[$name] = $origin[$name]; diff --git a/GraphQL/Mutation/UpdateProductStockMutation.php b/GraphQL/Mutation/UpdateProductStockMutation.php index dc11e1f..bafe0fa 100644 --- a/GraphQL/Mutation/UpdateProductStockMutation.php +++ b/GraphQL/Mutation/UpdateProductStockMutation.php @@ -13,7 +13,7 @@ namespace Plugin\Api\GraphQL\Mutation; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Eccube\Entity\ProductClass; use Eccube\Repository\ProductClassRepository; use GraphQL\Type\Definition\Type; @@ -34,14 +34,14 @@ class UpdateProductStockMutation implements Mutation private $productClassRepository; /** - * @var EntityManager + * @var EntityManagerInterface */ private $entityManager; public function __construct( Types $types, ProductClassRepository $productClassRepository, - EntityManager $entityManager + EntityManagerInterface $entityManager ) { $this->types = $types; $this->productClassRepository = $productClassRepository; diff --git a/GraphQL/Mutation/UpdateShippedMutation.php b/GraphQL/Mutation/UpdateShippedMutation.php index 2611c51..f83fc87 100644 --- a/GraphQL/Mutation/UpdateShippedMutation.php +++ b/GraphQL/Mutation/UpdateShippedMutation.php @@ -13,7 +13,7 @@ namespace Plugin\Api\GraphQL\Mutation; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Eccube\Common\EccubeConfig; use Eccube\Entity\Master\OrderStatus; use Eccube\Entity\Order; @@ -40,7 +40,7 @@ class UpdateShippedMutation implements Mutation private $eccubeConfig; /** - * @var EntityManager + * @var EntityManagerInterface */ private $entityManager; @@ -71,7 +71,7 @@ class UpdateShippedMutation implements Mutation public function __construct( EccubeConfig $eccubeConfig, - EntityManager $entityManager, + EntityManagerInterface $entityManager, MailService $mailService, OrderStateMachine $orderStateMachine, OrderStatusRepository $orderStatusRepository, diff --git a/GraphQL/Query/SearchFormQuery.php b/GraphQL/Query/SearchFormQuery.php index 264840d..39a04bf 100644 --- a/GraphQL/Query/SearchFormQuery.php +++ b/GraphQL/Query/SearchFormQuery.php @@ -16,7 +16,7 @@ use Eccube\Common\EccubeConfig; use Eccube\Util\StringUtil; use GraphQL\Type\Definition\Type; -use Knp\Component\Pager\Paginator; +use Knp\Component\Pager\PaginatorInterface; use Plugin\Api\GraphQL\Error\InvalidArgumentException; use Plugin\Api\GraphQL\Query; use Plugin\Api\GraphQL\Type\ConnectionType; @@ -24,14 +24,14 @@ use Symfony\Component\Form\Extension\Core\Type\DateTimeType; use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Form\FormFactory; +use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Validator\Constraints as Assert; abstract class SearchFormQuery implements Query { /** - * @var Paginator + * @var PaginatorInterface */ private $paginator; @@ -41,7 +41,7 @@ abstract class SearchFormQuery implements Query private $eccubeConfig; /** - * @var FormFactory + * @var FormFactoryInterface */ private $formFactory; @@ -53,7 +53,7 @@ abstract class SearchFormQuery implements Query /** * @required */ - public function setPaginator(Paginator $paginator): void + public function setPaginator(PaginatorInterface $paginator): void { $this->paginator = $paginator; } @@ -69,7 +69,7 @@ public function setEccubeConfig(EccubeConfig $eccubeConfig): void /** * @required */ - public function setFormFactory(FormFactory $formFactory): void + public function setFormFactory(FormFactoryInterface $formFactory): void { $this->formFactory = $formFactory; } diff --git a/Resource/config/services.yaml b/Resource/config/services.yaml index 7f21a99..644920b 100644 --- a/Resource/config/services.yaml +++ b/Resource/config/services.yaml @@ -68,6 +68,9 @@ services: nyholm.psr7.httplug_factory: class: Nyholm\Psr7\Factory\HttplugFactory + + Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory: '@sensio_framework_extra.psr7.http_message_factory' + core.api.allow_list: class: ArrayObject tags: ['eccube.api.allow_list'] diff --git a/Resource/locale/messages.en.yaml b/Resource/locale/messages.en.yaml index 8b1c445..f4d7b66 100644 --- a/Resource/locale/messages.en.yaml +++ b/Resource/locale/messages.en.yaml @@ -14,8 +14,8 @@ api: secret_tooltip: Up to 128 alphanumeric characters scope: Scope scope_tooltip: GraphQL Query requires read, Mutation requires write/write Scope - scope.read.description: Read %shop_name% data - scope.write.description: Write %shop_name% data + scope.read.description: 'Read %shop_name% data' + scope.write.description: 'Write %shop_name% data' redirect_uri: Redirect URI redirect_uri_tooltip: You can enter multiple URIs separated by commas grant_type: Grant Type @@ -26,7 +26,7 @@ api: clear_expired_tokens: Clears all expired access and/or refresh tokens copy: Copy copied: Copied - allow__confirm_message: Do you want to allow access this app to %shop_name%? + allow__confirm_message: 'Do you want to allow access this app to %shop_name%?' allow__confirm_description: 'Allow this app to:' allow: Allow deny: Deny diff --git a/Resource/locale/messages.ja.yaml b/Resource/locale/messages.ja.yaml index d90768c..8acbf97 100644 --- a/Resource/locale/messages.ja.yaml +++ b/Resource/locale/messages.ja.yaml @@ -14,8 +14,8 @@ api: secret_tooltip: 128文字以下の半角英数 scope: スコープ scope_tooltip: GraphQLのQueryにはread, Mutationにはwrite/writeのScopeが必要 - scope.read.description: %shop_name%のデータに対する読み取り - scope.write.description: %shop_name%のデータに対する書き込み + scope.read.description: '%shop_name%のデータに対する読み取り' + scope.write.description: '%shop_name%のデータに対する書き込み' redirect_uri: リダイレクトURI redirect_uri_tooltip: カンマ区切りで複数のURIを入力可能 grant_type: グラントタイプ @@ -26,7 +26,7 @@ api: clear_expired_tokens: 期限切れのアクセストークンとリフレッシュトークンを削除する copy: コピーする copied: コピーしました - allow__confirm_message: アプリから%shop_name%へのアクセスを許可しますか? + allow__confirm_message: 'アプリから%shop_name%へのアクセスを許可しますか?' allow__confirm_description: 'このアプリに以下を許可します:' allow: 許可する deny: 許可しない From e3b71376daeefa20831c14c394d8f692373dc0df Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Fri, 27 Nov 2020 09:50:50 +0900 Subject: [PATCH 4/6] Fix testcase --- .../Mutation/UpdateProductStockMutationTest.php | 4 ++-- Tests/GraphQL/Mutation/UpdateShippedMutationTest.php | 10 +++++----- Tests/GraphQL/SchemaTest.php | 2 +- Tests/GraphQL/TypesTest.php | 2 +- Tests/Service/WebHookServiceTest.php | 2 +- Tests/Web/Admin/LoginControllerTest.php | 2 +- Tests/Web/Admin/OAuthControllerTest.php | 2 +- Tests/Web/ApiControllerTest.php | 8 ++++---- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Tests/GraphQL/Mutation/UpdateProductStockMutationTest.php b/Tests/GraphQL/Mutation/UpdateProductStockMutationTest.php index ba33de4..836c683 100644 --- a/Tests/GraphQL/Mutation/UpdateProductStockMutationTest.php +++ b/Tests/GraphQL/Mutation/UpdateProductStockMutationTest.php @@ -31,8 +31,8 @@ class UpdateProductStockMutationTest extends EccubeTestCase public function setUp() { parent::setUp(); - $types = $this->container->get(Types::class); - $this->productClassRepository = $this->container->get(ProductClassRepository::class); + $types = self::$container->get(Types::class); + $this->productClassRepository = self::$container->get(ProductClassRepository::class); $this->updateProductStockMutation = new UpdateProductStockMutation($types, $this->productClassRepository, $this->entityManager); // テスト用の商品を作成 diff --git a/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php b/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php index cc9ad0d..823bb06 100644 --- a/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php +++ b/Tests/GraphQL/Mutation/UpdateShippedMutationTest.php @@ -42,11 +42,11 @@ public function setUp() { parent::setUp(); - $mailService = $this->container->get(MailService::class); - $orderStateMachine = $this->container->get(OrderStateMachine::class); - $orderStatusRepository = $this->container->get(OrderStatusRepository::class); - $types = $this->container->get(Types::class); - $shippingRepository = $this->container->get(ShippingRepository::class); + $mailService = self::$container->get(MailService::class); + $orderStateMachine = self::$container->get(OrderStateMachine::class); + $orderStatusRepository = self::$container->get(OrderStatusRepository::class); + $types = self::$container->get(Types::class); + $shippingRepository = self::$container->get(ShippingRepository::class); $this->updateShippedMutation = new UpdateShippedMutation( $this->eccubeConfig, diff --git a/Tests/GraphQL/SchemaTest.php b/Tests/GraphQL/SchemaTest.php index dca8523..ae12c9f 100644 --- a/Tests/GraphQL/SchemaTest.php +++ b/Tests/GraphQL/SchemaTest.php @@ -403,7 +403,7 @@ private function executeQuery($query, $variables = null, $readonly = false) { $op = OperationParams::create(['query' => $query, 'variables' => $variables], $readonly); $helper = new Helper(); - $config = ServerConfig::create()->setSchema($this->container->get(Schema::class)); + $config = ServerConfig::create()->setSchema(self::$container->get(Schema::class)); $result = $helper->executeOperation($config, $op); self::assertInstanceOf(ExecutionResult::class, $result); diff --git a/Tests/GraphQL/TypesTest.php b/Tests/GraphQL/TypesTest.php index f4e8c57..262f32e 100644 --- a/Tests/GraphQL/TypesTest.php +++ b/Tests/GraphQL/TypesTest.php @@ -28,7 +28,7 @@ class TypesTest extends EccubeTestCase public function setUp() { parent::setUp(); - $this->types = $this->container->get(Types::class); + $this->types = self::$container->get(Types::class); } /** diff --git a/Tests/Service/WebHookServiceTest.php b/Tests/Service/WebHookServiceTest.php index d7e1d50..e3a93eb 100644 --- a/Tests/Service/WebHookServiceTest.php +++ b/Tests/Service/WebHookServiceTest.php @@ -29,7 +29,7 @@ public function setUp() { parent::setUp(); - $this->service = $this->container->get(WebHookService::class); + $this->service = self::$container->get(WebHookService::class); } public function testCreateRequest_withSecret() diff --git a/Tests/Web/Admin/LoginControllerTest.php b/Tests/Web/Admin/LoginControllerTest.php index d4ef1cf..0d44cae 100644 --- a/Tests/Web/Admin/LoginControllerTest.php +++ b/Tests/Web/Admin/LoginControllerTest.php @@ -41,7 +41,7 @@ public function testRoutingAdminLoginCheck() ] ); - $this->assertNotNull($this->container->get('security.token_storage')->getToken(), 'ログインしているかどうか'); + $this->assertNotNull(self::$container->get('security.token_storage')->getToken(), 'ログインしているかどうか'); } public function testRoutingAdminLogin_ログインしていない場合はログイン画面を表示() diff --git a/Tests/Web/Admin/OAuthControllerTest.php b/Tests/Web/Admin/OAuthControllerTest.php index 855394d..ded8e05 100644 --- a/Tests/Web/Admin/OAuthControllerTest.php +++ b/Tests/Web/Admin/OAuthControllerTest.php @@ -32,7 +32,7 @@ public function setUp() { parent::setUp(); - $this->clientManager = $this->container->get(ClientManager::class); + $this->clientManager = self::$container->get(ClientManager::class); } public function testRoutingAdminSettingSystemOAuth2Client() diff --git a/Tests/Web/ApiControllerTest.php b/Tests/Web/ApiControllerTest.php index 99bbbad..a445601 100644 --- a/Tests/Web/ApiControllerTest.php +++ b/Tests/Web/ApiControllerTest.php @@ -40,10 +40,10 @@ class ApiControllerTest extends AbstractWebTestCase public function setUp() { parent::setUp(); - $this->clientManager = $this->container->get(ClientManager::class); - $this->clientRepository = $this->container->get(ClientRepositoryInterface::class); - $this->accessTokenRepository = $this->container->get(AccessTokenRepositoryInterface::class); - $this->authorizationServer = $this->container->get(AuthorizationServer::class); + $this->clientManager = self::$container->get(ClientManager::class); + $this->clientRepository = self::$container->get(ClientRepositoryInterface::class); + $this->accessTokenRepository = self::$container->get(AccessTokenRepositoryInterface::class); + $this->authorizationServer = self::$container->get(AuthorizationServer::class); } /** From 6e218274ac038a634294f85d06ec0d91c1389f17 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Mon, 30 Nov 2020 10:25:39 +0900 Subject: [PATCH 5/6] use eccube4-test-fixer --- .travis.yml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0eff260..3a08418 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,9 +65,29 @@ install: - *install_eccube - *package_api_setup - *eccube_setup + - composer require --dev kiy0taka/eccube4-test-fixer -script: - - ./vendor/bin/phpunit app/Plugin/${PLUGIN_CODE}/Tests; +script: | + if [[ $ECCUBE_VERSION = '4.0.5' ]] + then + while read TESTCASE + do + ./vendor/bin/phpunit --include-path vendor/kiy0taka/eccube4-test-fixer/src --loader 'Eccube\PHPUnit\Loader\Eccube4CompatTestSuiteLoader' app/Plugin/${PLUGIN_CODE}/Tests/${TESTCASE} + done < Date: Mon, 30 Nov 2020 15:18:40 +0900 Subject: [PATCH 6/6] use find thx @kurozumi --- .travis.yml | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3a08418..8a915c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,21 +70,10 @@ install: script: | if [[ $ECCUBE_VERSION = '4.0.5' ]] then - while read TESTCASE + find app/Plugin/${PLUGIN_CODE}/Tests -name "*Test.php" | while read TESTCASE do - ./vendor/bin/phpunit --include-path vendor/kiy0taka/eccube4-test-fixer/src --loader 'Eccube\PHPUnit\Loader\Eccube4CompatTestSuiteLoader' app/Plugin/${PLUGIN_CODE}/Tests/${TESTCASE} - done <