Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ユニットテストを動作するよう修正 #99

Merged
merged 1 commit into from Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yaml
@@ -1,7 +1,7 @@
name: PHPStan
on: [workflow_dispatch, pull_request]
env:
PLUGIN_NAME: DataMigration4
PLUGIN_NAME: DataMigration42
DATABASE_URL: mysql://root:root@127.0.0.1:3306/eccube_db
DATABASE_SERVER_VERSION: 5

Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/test.yaml
Expand Up @@ -11,7 +11,7 @@ jobs:
php: [ '7.4', '8.0', '8.1' ]
db: [ 'mysql', 'mysql8', 'pgsql' ]
eccube_version: [ '4.2' ]
plugin_code: [ 'DataMigration4' ]
plugin_code: [ 'DataMigration42' ]
include:
- db: mysql
database_url: mysql://root:password@127.0.0.1:3306/eccube_db
Expand Down Expand Up @@ -72,6 +72,15 @@ jobs:
PLUGIN_CODE: ${{ matrix.plugin_code }}
run: |
tar cvzf ${GITHUB_WORKSPACE}/${PLUGIN_CODE}.tar.gz ./*

- name: Setup mock-package-api
env:
PLUGIN_CODE: ${{ matrix.plugin_code }}
run: |
mkdir -p /tmp/repos
cp ${GITHUB_WORKSPACE}/${PLUGIN_CODE}.tar.gz /tmp/repos/${PLUGIN_CODE}.tgz
docker run --name package-api -d -v /tmp/repos:/repos -e MOCK_REPO_DIR=/repos -p 8080:8080 eccube/mock-package-api:composer2

- name: Checkout EC-CUBE
uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -113,9 +122,12 @@ jobs:
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
DATABASE_CHARSET: ${{ matrix.database_charset }}
PLUGIN_CODE: ${{ matrix.plugin_code }}
ECCUBE_PACKAGE_API_URL: 'http://127.0.0.1:8080'
USE_SELFSIGNED_SSL_CERTIFICATE: '1'
working-directory: 'ec-cube'
run: |
bin/console eccube:plugin:install --code=${PLUGIN_CODE} --path=${GITHUB_WORKSPACE}/${PLUGIN_CODE}.tar.gz
bin/console doctrine:query:sql "update dtb_base_info set authentication_key='dummy'"
bin/console eccube:composer:require ec-cube/datamigration42
bin/console cache:clear --no-warmup
bin/console eccube:plugin:enable --code=${PLUGIN_CODE}
- name: Run PHPUnit
Expand All @@ -128,7 +140,7 @@ jobs:
PLUGIN_CODE: ${{ matrix.plugin_code }}
working-directory: 'ec-cube'
run: |
bin/console cache:clear --no-warmup
rm -rf var/cache
bin/phpunit app/Plugin/${PLUGIN_CODE}/Tests
- name: Disable Plugin
working-directory: 'ec-cube'
Expand Down
17 changes: 8 additions & 9 deletions Controller/Admin/ConfigController.php
@@ -1,6 +1,6 @@
<?php

namespace Plugin\DataMigration4\Controller\Admin;
namespace Plugin\DataMigration42\Controller\Admin;

//use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Connection;
Expand All @@ -9,7 +9,7 @@
use Eccube\Service\PluginService;
use Eccube\Util\StringUtil;
use nobuhiko\BulkInsertQuery\BulkInsertQuery;
use Plugin\DataMigration4\Form\Type\Admin\ConfigType;
use Plugin\DataMigration42\Form\Type\Admin\ConfigType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Filesystem\Filesystem;
Expand Down Expand Up @@ -64,8 +64,8 @@ public function __construct(
}

/**
* @Route("/%eccube_admin_route%/data_migration4/config", name="data_migration4_admin_config")
* @Template("@DataMigration4/admin/config.twig")
* @Route("/%eccube_admin_route%/data_migration42/config", name="data_migration42_admin_config")
* @Template("@DataMigration42/admin/config.twig")
*/
public function index(Request $request, Connection $em)
{
Expand Down Expand Up @@ -191,7 +191,8 @@ private function saveCustomerAndOrder($em, $csvDir)
if (!empty($this->order_item)) {
// すでに移行されている税率設定から取得する
$sql = 'SELECT * FROM dtb_tax_rule WHERE product_id IS NULL AND product_class_id IS NULL ORDER BY apply_date DESC';
$tax_rules = $em->fetchAll($sql);
$stmt = $em->query($sql);
$tax_rules = $stmt->fetchAllAssociative();
foreach ($tax_rules as $tax_rule) {
$this->tax_rule[$tax_rule['apply_date']] = [
'rounding_type_id' => $tax_rule['rounding_type_id'],
Expand Down Expand Up @@ -921,8 +922,7 @@ class_combination_id
FROM dtb_class_combination as c1
where parent_class_combination_id is not null
');
$stmt->execute();
$all = $stmt->fetchAll();
$all = $stmt->fetchAllAssociative();

$this->dtb_class_combination = [];
foreach ($all as $line) {
Expand All @@ -937,8 +937,7 @@ class_combination_id
FROM dtb_class_combination as c1
where parent_class_combination_id is null
');
$stmt->execute();
$all = $stmt->fetchAll();
$all = $stmt->fetchAllAssociative();

foreach ($all as $line) {
$this->dtb_class_combination[$line['class_combination_id']] = $line;
Expand Down
2 changes: 1 addition & 1 deletion Form/Type/Admin/ConfigType.php
@@ -1,6 +1,6 @@
<?php

namespace Plugin\DataMigration4\Form\Type\Admin;
namespace Plugin\DataMigration42\Form\Type\Admin;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
Expand Down
18 changes: 6 additions & 12 deletions Tests/Web/Admin/ConfigControllerTest.php
@@ -1,7 +1,7 @@
<?php


namespace Plugin\DataMigration4\Tests\Web\Admin;
namespace Plugin\DataMigration42\Tests\Web\Admin;


use Eccube\Common\Constant;
Expand Down Expand Up @@ -43,8 +43,8 @@ public function testバックアップファイルをアップロードできる
{
$project_dir = self::$container->getParameter('kernel.project_dir');

$file = $project_dir.'/app/Plugin/DataMigration4/Tests/Fixtures/'.$v.'.tar.gz';
$testFile = $project_dir.'/app/Plugin/DataMigration4/Tests/Fixtures/test.tar.gz';
$file = $project_dir.'/app/Plugin/DataMigration42/Tests/Fixtures/'.$v.'.tar.gz';
$testFile = $project_dir.'/app/Plugin/DataMigration42/Tests/Fixtures/test.tar.gz';

$fs = new Filesystem();
$fs->copy($file, $testFile);
Expand All @@ -67,18 +67,12 @@ public function testバックアップファイルをアップロードできる

$this->client->request(
'POST',
$this->generateUrl('data_migration4_admin_config'),
$post
$this->generateUrl('data_migration42_admin_config'),
$post,
['config' => ['import_file' => $file]]
);

//var_dump($this->client->getResponse()->getStatusCode());
//var_dump($this->client->getResponse()->getContent());

//self::assertEquals(Response::HTTP_FOUND, $this->client->getResponse()->getStatusCode());
//self::assertTrue($this->client->getResponse()->isRedirect($this->generateUrl('data_migration4_admin_config')));

$customers = $this->entityManager->getRepository(Customer::class)->findAll();
var_dump($customers);
self::assertEquals($c, count($customers));

if ($p > 0) {
Expand Down
6 changes: 3 additions & 3 deletions composer.json
@@ -1,16 +1,16 @@
{
"name": "ec-cube/datamigration4",
"name": "ec-cube/datamigration42",
"version": "4.2.0",
"description": "データ移行プラグイン",
"type": "eccube-plugin",
"require": {
"ec-cube/plugin-installer": "~0.0.8 || ^2.0",
"ec-cube/plugin-installer": "^2.0",
"pear/pear-core-minimal" : "^1.10.10",
"pear/archive_tar" : "^1.4.13",
"wapmorgan/unified-archive": "^1.1.1",
"nobuhiko/bulk-insert-query": "*"
},
"extra": {
"code": "DataMigration4"
"code": "DataMigration42"
}
}