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

Codeception のデータ生成に対応 #277

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,542 changes: 0 additions & 1,542 deletions ctests/acceptance/AcceptanceTester.php

This file was deleted.

23 changes: 23 additions & 0 deletions ctests/acceptance/ProductListCept.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,33 @@
$I->see('EC-CUBE発!世界中を旅して見つけた立方体グルメを立方隊長が直送!');
$I->seeElement('#site_description');

$I->expect('50件まで一覧表示する');
$I->selectOption(['css' => '#page_navi_top > div > div.change > select'], '50件');
$all_products = $I->grabMultiple(['css' => '#undercolumn > form > div > div.listrightbloc > h3 > a']);
if (count($all_products) <= 50) {
$I->see(count($all_products).'件', ['css' => '#undercolumn > div > span.attention']);
} else {
$I->comment('50件超過の商品が存在します');
$I->dontSee(count($all_products).'件', ['css' => '#undercolumn > div > span.attention']);
}

$I->dontSeeElement('.error');

// 食品
$I->amOnPage('/products/list.php?category_id=3');
$I->expect('50件まで一覧表示する');
$I->selectOption(['css' => '#page_navi_top > div > div.change > select'], '50件');

$I->expect('カテゴリにアクセスすると商品が絞り込まれる');
$I->comment('see https://github.com/EC-CUBE/eccube-2_13/pull/273');
$products_in_category = $I->grabMultiple(['css' => '#undercolumn > form > div > div.listrightbloc > h3 > a']);

if (count($products_in_category) <= 50) {
$I->see(count($products_in_category).'件', ['css' => '#undercolumn > div > span.attention']);
} else {
$I->comment('50件超過の商品が存在します');
$I->dontSee(count($products_in_category).'件', ['css' => '#undercolumn > div > span.attention']);
}

$I->dontSeeElement('.error');

Expand Down
60 changes: 60 additions & 0 deletions ctests/acceptance/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
<?php
require __DIR__.'/../../tests/require.php';
// Here you can initialize variables that will be available to your tests
$config = parse_ini_file(__DIR__.'/config.ini', true);

$faker = Faker\Factory::create('ja_JP');
Codeception\Util\Fixtures::add('faker', $faker);

/** @var SC_Query $objQuery */
$objQuery = SC_Query_Ex::getSingletonInstance();

$objGenerator = new FixtureGenerator($objQuery, 'ja_JP');
Codeception\Util\Fixtures::add('objGenerator', $objGenerator);

$num = $objQuery->count('dtb_customer');

if ($num < $config['fixture_customer_num']) {
$num = $config['fixture_customer_num'] - $num;
echo 'Generating Customers';
for ($i = 0; $i < $num; $i++) {
$objGenerator->createCustomer();
echo '.';
}
$objGenerator->createCustomer(null, ['status' => '1']); // non-active member
echo '.'.PHP_EOL;
}

$num = $objQuery->count('dtb_products');
$product_ids = [];
// 受注生成件数 + 初期データの商品が生成されているはず
if ($num < ($config['fixture_product_num'] + 2)) {
echo 'Generating Products';
// 規格なしも含め $config['fixture_product_num'] の分だけ生成する
for ($i = 0; $i < $config['fixture_product_num'] - 1; $i++) {
$product_ids[] = $objGenerator->createProduct();
echo '.';
}
$product_ids[] = $objGenerator->createProduct('規格なし商品', 0);
echo '.'.PHP_EOL;

$category_ids = $objGenerator->createCategories();
foreach ($product_ids as $product_id) {
$objGenerator->relateProductCategories($product_id, array_rand($category_ids, $faker->numberBetween(1, count($category_ids) - 1)));
}
$objDb = new SC_Helper_DB_Ex();
$objDb->sfCountCategory($objQuery);
}

$num = $objQuery->count('dtb_order');
$customer_ids = $objQuery->getCol('customer_id', 'dtb_customer', 'del_flg = 0');
$product_class_ids = $objQuery->getCol('product_class_id', 'dtb_products_class', 'del_flg = 0');
if ($num < $config['fixture_order_num']) {
echo 'Generating Orders';
foreach ($customer_ids as $customer_id) {
$target_product_class_ids = $product_class_ids[$faker->numberBetween(0, count($product_class_ids) - 1)];
$charge = $faker->randomNumber(4);
$discount = $faker->numberBetween(0, $charge);
$order_count_per_customer = $objQuery->count('dtb_order', 'customer_id = ?', [$customer_id]);
for ($i = $order_count_per_customer; $i < $config['fixture_order_num'] / count($customer_ids); $i++) {
$objGenerator->createOrder($customer_id, $target_product_class_ids, 1, $charge, $discount, $faker->numberBetween(1, 7));
echo '.';
}
}
echo PHP_EOL;
}
4 changes: 4 additions & 0 deletions ctests/acceptance/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fixture_customer_num = 10 ; 各カスタマー作成時に注文を1つづつつくる。さらに、注文を作る際に1つ商品を作る
; フロント側のテストとして3以上が必要
fixture_product_num = 20
fixture_order_num = 25
2 changes: 1 addition & 1 deletion tests/class/Common_TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Common_TestCase extends PHPUnit_Framework_TestCase
'_MDB2_dsninfo_default',
);

/** SC_Query インスタンス */
/** @var SC_Query */
protected $objQuery;

/** 期待値 */
Expand Down
Loading