Skip to content

Instantly share code, notes, and snippets.

@tanakahisateru
Last active August 29, 2015 14:11
Show Gist options
  • Save tanakahisateru/3e5483ca0c15837ca29f to your computer and use it in GitHub Desktop.
Save tanakahisateru/3e5483ca0c15837ca29f to your computer and use it in GitHub Desktop.
Yii2のAcceptanceなしテストこんな構成にしてみた
.
├── codeception
│   ├── _output
│   ├── _support
│   │   └── FixtureLoader.php --- フィクスチャ全部ロードするやつ
│   ├── bin
│   │   ├── _bootstrap.php
│   │   ├── yii
│   │   └── yii.bat
│   ├── config
│   │   ├── config.php
│   │   ├── functional.php --- $config['components']['log']['targets'] = [] してログを吐かせないように
│   │   └── unit.php --- 上と同じ
│   ├── fixtures --- 共通のフィクスチャ
│   │   ├── UserFixture.php
│   │   ├── data --- templatesから生成したdataはgit addしちゃう。
│   │   │   └── user.php
│   │   └── templates --- yiit fixture/generate-all で Faker -> data 生成
│   │   ├── README.md --- これは data を書き換えちゃうためのソースなので注意って書いてある
│   │   └── user.php
│   ├── functional
│   │   ├── FunctionalTester.php --- codecept build で生成
│   │   ├── _bootstrap.php
│   │   ├── _pages
│   │   │   └── group_a
│   │   │   └── LoginPage.php
│   │   ├── fixture-map.php --- functional.suite.yml で設定して _support/FixtureLoader にこれを読ませてる
│   │   └── group_a
│   │   └── LoginCept.php
│   ├── unit
│   │   ├── UnitTester.php --- codecept build で生成
│   │   ├── _bootstrap.php
│   │   └── group_a
│   │   └── LoginFormTest.php --- UserFixture だけ個別にロードしてテスト
│   ├── _bootstrap.php
│   ├── functional.suite.yml
│   └── unit.suite.yml
├── README.md
├── codeception.yml
├── codecept -> ../vendor/codeception/codeception/codecept
└── yiit -> codeception/bin/yii
actor: Tester
paths:
tests: codeception
log: codeception/_output
data: codeception/_data
helpers: codeception/_support
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
memory_limit: 1024M
log: true
colors: true
config:
# the entry script URL (without host info) for functional and acceptance tests
# PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
test_entry_url: /index-test.php
<?php
return [
'user_student' => [
'class' => 'tests\codeception\fixtures\UserStudentFixture',
'dataFile' => '@tests/codeception/fixtures/data/user_student.php',
],
// ファンクショナルテスト時に一括ロードしたいフィクスチャはここに登録
];
<?php
namespace tests\codeception\_support;
use Codeception\Module;
use yii\test\FixtureTrait;
class FixtureLoader extends Module
{
use FixtureTrait;
protected $config = [
'mappingPath' => '@tests/fixture-map.php', // 要カスタマイズ
];
public function _beforeSuite($settings = [])
{
$this->loadFixtures();
}
public function _afterSuite()
{
$this->unloadFixtures();
}
public function fixtures()
{
/** @noinspection PhpIncludeInspection */
return require \Yii::getAlias($this->config['mappingPath']);
}
}
class_name: FunctionalTester
modules:
enabled:
- Filesystem
- Yii2
- tests\codeception\_support\FixtureLoader
config:
Yii2:
configFile: 'codeception/config/functional.php'
tests\codeception\_support\FixtureLoader:
mappingPath: '@tests/codeception/functional/fixture-map.php'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment