PHPackages                             magical-yuri/magical-girl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. magical-yuri/magical-girl

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

magical-yuri/magical-girl
=========================

Test Data Generator

1.0.0(11y ago)1076MITPHP

Since Oct 30Pushed 11y ago3 watchersCompare

[ Source](https://github.com/magical-yuri/magical-girl)[ Packagist](https://packagist.org/packages/magical-yuri/magical-girl)[ RSS](/packages/magical-yuri-magical-girl/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

What is MagicalGirl?
====================

[](#what-is-magicalgirl)

This is a library that insert test-data to your database.
MagicalGirl generate the random value for test-data that suitable for your table in database, and insert the test-data.

Environment
===========

[](#environment)

- PHP 5.6
- MySQL 5.6

How to Install
==============

[](#how-to-install)

You need Composer to install MagicalGirl.

1. Install Composer
-------------------

[](#1-install-composer)

```
curl -s http://getcomposer.org/installer | php

```

2. Prepare 'composer.json'
--------------------------

[](#2-prepare-composerjson)

```
{
    "require-dev": {
        "phpunit/phpunit": "*",
        "magical-yuri/magical-girl": "*"
    },
    "config": {
        "bin-dir": "bin/"
    }
}

```

3. Install MagicalGirl
----------------------

[](#3-install-magicalgirl)

```
php composer.phar install

```

Prepare to Use
==============

[](#prepare-to-use)

1. Initialize
-------------

[](#1-initialize)

Please execute the following command.

```
bin/magicalinit

```

2. Database Connection Setting
------------------------------

[](#2-database-connection-setting)

Please implement the method to get DB-host, DB-user-name and DB-password in 'lib/DB/DBConnections.php'
The following is an example, that database-name is 'example'.

```
    protected static function getExampleHost()
    {
        return '127.0.0.1';
    }

    protected static function getExampleUserName()
    {
        return 'user_name';
    }

    protected static function getExamplePassword()
    {
        return 'password';
    }

```

3. Generate the Importer class for your Table
---------------------------------------------

[](#3-generate-the-importer-class-for-your-table)

Execute the following command, and two files will be generated.

```
bin/magicalgen [databaseName] [tableName]

```

- `lib/DB/TableImporter/[shemaName]/[databaseName][tableName]Importer.php`
- `lib/DB/TableImporter/[shemaName]/base/Base[schemaName][tableName]Importer.php`

Do not modify the file that named 'Base...php'.
Every time you execute magicalgen command, it re-generate the file 'Base...php' from table structure of run time.
When you need to customize the Importer, please modify only the file '\[databaseName\]\[tableName\]Importer.php'

4. Prepare Master-data
----------------------

[](#4-prepare-master-data)

When you always need to import the same data, for example, master-data, you prepare the master-data formed tsv file.
Please prepare tsv file in following directory structure.

```
masterData
└── [databaseName]
    ├── [tableName1].tsv
    ├── [tableName2].tsv
    └── [tableName3].tsv

```

This tsv file does not include the header.
You can get this tsv file by executing the following command.

```
mysql -h 127.0.0.1 -u user -p -B -N -e 'select * from [tableName1]' [databaseName] > [tableName1].tsv

```

How to Use
==========

[](#how-to-use)

For example, you can use MagicalGirl by creating the following file.

```
