Giter Club home page Giter Club logo

yii2-faker's Introduction

Faker Extension for Yii 2


This extension provides a Faker fixture command for the Yii framework 2.0.

For license information check the LICENSE-file.

Documentation is at docs/guide/README.md.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yiisoft/yii2-faker

or add

"yiisoft/yii2-faker": "~2.0.0"

to the require section of your composer.json.

Usage

To use this extension, simply add the following code in your application configuration (console.php):

'controllerMap' => [
    'fixture' => [
        'class' => 'yii\faker\FixtureController',
    ],
],

yii2-faker's People

Contributors

arhell avatar bizley avatar cebe avatar creocoder avatar d1rtyf1ng3rs avatar drsdre avatar funivan avatar joshijitendra avatar klimov-paul avatar krsriq avatar lichunqiang avatar machour avatar mohorev avatar nineinchnick avatar ofixone avatar pana1990 avatar qiangxue avatar ragazzo avatar samdark avatar schmunk42 avatar silverfire avatar softark avatar sonicgd avatar tom-- avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-faker's Issues

Unknown formatter "internet"

I want to add faker for random domain name like domain.com and use :

$faker->internet

Is throw Unknown formatter "internet"

And added

$faker = \Faker\Factory::create();
$faker->addProvider(new \Faker\Provider\Internet($faker));

Still same

Unknown formatter "randonElement"

After running yii fixture/generate car --count=200 I get this error:

Exception 'InvalidArgumentException' with message 'Unknown formatter "randonElement"'
in vendor\fzaninotto\faker\src\Faker\Generator.php:209

<?php

/**
 * @var $faker \Faker\Generator
 * @var $index integer
 */
return [
    'name' => $faker->name,
    'brand' => $faker->randomElement(['audi', 'skoda', 'volkswagen', 'seat']),
    'model' => $faker->word,
    'type' => $faker->randomElement(['new','used','rental']),
    'fuel' => $faker->randonElement(['gasoline','diesel']),
    'doors' => $faker->randonElement(['3-doors','5-doors']),
    'price' => $faker->randomFloat(2, 0, 100000),
    'year' => $faker->year($max = 'now'),
    'mileage' => $faker->randomNumber(3),
    'transmission' => $faker->randomElement(['manual','automatic']),
    'created_at' => $faker->unixTime(),
];

https://github.com/fzaninotto/Faker#formatters

Index and databese id's dont match

Is anyone else having an issue with $index not being the same as the record id?
Because my database id's start at 1 and the index being passed into the faker template starts at 0 the record id does not match the index.

if in the loop was for ($i = 1; $i <= $this->count; $i++) { The index and the record id would be the same.

findTemplatesFiles() can`t replace $templatePath from $fileName due '/'

What steps will reproduce the problem?

yii fixture/generate-all

What's expected?

The following fixtures template files were generated:

        * users
       [something else fixtures]

What do you get instead?

PHP Compile Error 'yii\base\ErrorException' with message 'yii\faker\FixtureController::generateFixture(): Failed opening required 'D:\OSPanel\domains\app/tests/fixtures\templates/D:\OSPanel\domains\app/tests/fixtures\templates/users.php' (include_path='.;d:/osp
anel/modules/php/PHP-7.0-x64;d:/ospanel/modules/php/PHP-7.0-x64/PEAR/pear')
in D:\OSPanel\domains\app\vendor\yiisoft\yii2-faker\FixtureController.php:446

Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
...

Description

I guess, this problem arises from the fact that FileHelper, whos looking for data in folders, use DIRECTORY_SEPARATOR constant:

// yii\helpers\BaseFileHelper
public static function findFiles($dir, $options = []) {
...
$path = $dir . DIRECTORY_SEPARATOR . $file; // creating path
...
}

while FixtureController uses a '/' symbol to trim path to the file and leave the only name:

//  yii\faker\FixtureController
protected function findTemplatesFiles(array $templatesNames = []) {
...
$relativeName = str_replace(Yii::getAlias($this->templatePath) . '/', "", $fileName);
...
}

so it tries to find $this->templatePath into $fileName but they differ in the last character before filename:

D:\OSPanel\domains\app/tests/fixtures\templates\users.php"
D:\OSPanel\domains\app/tests/fixtures\templates/

And after that FixtureController can`t create a right way to find a fixture's data

Additional info

Q A
Yii vesion 2.0.14-dev
Yii2 Faker version dev-master
PHP version 7.0
Operating system Windows 7

Implement fixture guesser for Faker extension

This issue has originally been reported by @Ragazzo at yiisoft/yii2#4056.
Moved here by @cebe.


In the Faker there are some column guessers like this one and this, their purpose is to help user to avoid manual matching attribute names on correct providers, because in most cases username or email in table or other storage means simple user name and email that is userName and email providers in Faker.

In this way it would be great if we will implement such functionality for generating templates based on some tables or mongo collections or other storages. So overall usage of command is :

//generate fixture template for users table, basing on some guessing mechanism
php yii fixture/template users

and if for example users table contains email / username / first_name / last_name and other, the resulting fixture template file will be like this :

//keys are attributes names, while values are anonymous functions or faker provider method names
return [
    'username'  => 'userName',
    'first_name' => 'firstName',
    'email' => 'email',
    'last_name' => 'lastName'
];

Overall what we achive :

  • more automating generation in testing to help user;
  • we can implement different guessing strategies;
  • we can implement different storages that provides metadata for particular fixture template (it can be users table, or users collection in mongo, or some data in redis).

What is your thoughts @samdark @qiangxue @cebe @klimov-paul ?

faker本身是支持zh_CH的,而yii2-faker为什么不支持了?

/src/tests/codeception/config/config.php
··· php
'controllerMap' => [
'fixture' => [
'class' => 'yii\faker\FixtureController',
'fixtureDataPath' => '@tests/codeception/common/fixtures/data',
'templatePath' => '@tests/codeception/common/templates/fixtures',
'namespace' => 'tests\codeception\common\fixtures',
'language'=>'zh_CN',
],
],

yii fixture/generate city --count=2 --language=zh_CN

结果:
··· php
return [
    [
        'name' => 'Iure.',
        'parent_id' => 10,
    ],
    [
        'name' => 'Quia.',
        'parent_id' => 5,
    ],
];

Error when load data

Hello Everybody!

I seen problem below:

$ php yii fixture/load Page
Some fixtures were not found under path:
F:\www\xxx/tests/unit/fixtures

Check that they have correct namespace "tests\unit\fixtures"
1. Page

Error: No files were found by name: "Page".
Check that files with these name exists, under fixtures path:
"F:\www\xxx/tests/unit/fixtures".

In folder test\unit\fixtures i have file name page.php with content:

update root folder links

What steps will reproduce the problem?

What's expected?

What do you get instead?

Additional info

Q A
Yii version
Yii Faker version
Faker version
PHP version
Operating system

`$fixtureDataPath` should be '@tests/_data' as Codeception does

Codeception sets protected $dataDir = 'tests/_data'; in src/Codeception/Template/Bootstrap.php:

protected $dataDir = 'tests/_data';

and yii2-app-basic sets it in codeception.yml:

data: tests/_data

but yii2-faker sets $fixtureDataPath as '@tests/unit/fixtures/data':

public $fixtureDataPath = '@tests/unit/fixtures/data';

yii2-faker should sets $fixtureDataPath = 'tests/_data', as Codeception does.

Q A
Yii vesion 2.0.14
PHP version 7.2.2-3+ubuntu16.04.1+deb.sury.org+1
Operating system Ubuntu 16.04.3 LTS

Path inconsistencies

(From yiisoft/yii2-app-basic#155)

This seems to match the default path for fixtures generated by yii2-faker which is
@tests/unit/fixtures/data

However, the Yii2 Testing Documentation then gives an example of the data path as:

// fixture data located in tests/_data/user.php
'dataFile' => codecept_data_dir() . 'user.php'

Why? That is not where yii2-faker puts the generated data by default and the documentation does not explain why it is different.

Additional info

Q A
Yii vesion dev-master
PHP version 7.2
Operating system

Wrong randomFloat() results

In my yii basic-template project, I create the tests/codeception/unit/templates/fixtures/articulos.php file with the following content:

<?php

// users.php file under the template path (by default @tests/unit/templates/fixtures)
/**
 * @var $faker \Faker\Generator
 * @var $index integer
 */
return [
    'precio' => $faker->randomFloat(2, 0, 9999.99),
];

Then I create the fixtures with:

$ ./yii fixture/generate articulos --count=5

Creating the tests/codeception/unit/fixtures/data/articulos.php file with the following content:

<?php

return [
    [
        'precio' => 6941.9399999999996,
    ],
    [
        'precio' => 4859.3999999999996,
    ],
    [
        'precio' => 5985.3900000000003,
    ],
    [
        'precio' => 1983.96,
    ],
    [
        'precio' => 1103.45,
    ],
];

As you can see, float numbers have wrong number of decimals (they should have 2 decimal digits, but three of them have many more).

Additional information:

$ composer info
bower-asset/bootstrap                 v3.3.5             The most popular front-end framework for developing responsive, m...
bower-asset/jquery                    2.2.2              
bower-asset/jquery.inputmask          3.2.7              jquery.inputmask is a jquery plugin which create an input mask.
bower-asset/punycode                  v1.3.2             
bower-asset/typeahead.js              v0.11.1            
bower-asset/yii2-pjax                 v2.0.6             
cebe/markdown                         1.1.0              A super fast, highly extensible markdown parser for PHP
dnoegel/php-xdg-base-dir              0.1                implementation of xdg base directory specification for php
ezyang/htmlpurifier                   v4.6.0             Standards compliant HTML filter written in PHP
fxp/composer-asset-plugin             v1.1.2             NPM/Bower Dependency Manager for Composer
fzaninotto/faker                      v1.5.0             Faker is a PHP library that generates fake data for you.
jakub-onderka/php-console-color       0.1                
jakub-onderka/php-console-highlighter v0.3.2             
johnitvn/yii2-ajaxcrud                2.1.2              Gii CRUD template for Single Page Ajax Administration for yii2
kartik-v/bootstrap-popover-x          v1.4.1             Bootstrap Popover Extended - Popover with modal behavior, styling...
kartik-v/mpdf                         v1.0.2             A PHP class to generate PDF files from HTML with Unicode/UTF-8 an...
kartik-v/yii2-editable                v1.7.4             An enhanced editable widget for Yii 2.0 that allows easy editing ...
kartik-v/yii2-grid                    dev-master e4a33f6 Yii 2 GridView on steroids. Various enhancements and utilities fo...
kartik-v/yii2-krajee-base             1.8.2              Base library and foundation components for all Yii2 Krajee extens...
kartik-v/yii2-mpdf                    v1.0.0             A Yii2 wrapper component for the mPDF library which generates PDF...
kartik-v/yii2-popover-x               v1.3.3             An extended bootstrap 3.0 popover widget which combines both the ...
nikic/php-parser                      v2.0.1             A PHP parser written in PHP
phpspec/php-diff                      v1.0.2             A comprehensive library for generating differences between two ha...
psy/psysh                             v0.7.2             An interactive shell for modern PHP.
squizlabs/php_codesniffer             2.5.1              PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detec...
swiftmailer/swiftmailer               v5.4.1             Swiftmailer, free feature-rich PHP mailer
symfony/console                       v3.0.3             Symfony Console Component
symfony/polyfill-mbstring             v1.1.1             Symfony polyfill for the Mbstring extension
symfony/var-dumper                    v3.0.3             Symfony mechanism for exploring and dumping PHP variables
yiisoft/yii2                          2.0.7              Yii PHP Framework Version 2
yiisoft/yii2-bootstrap                2.0.6              The Twitter Bootstrap extension for the Yii framework
yiisoft/yii2-codeception              2.0.5              The Codeception integration for the Yii framework
yiisoft/yii2-coding-standards         2.0.1              Yii PHP Framework Version 2 - Coding standard tools
yiisoft/yii2-composer                 2.0.4              The composer plugin for Yii extension installer
yiisoft/yii2-debug                    2.0.6              The debugger extension for the Yii framework
yiisoft/yii2-faker                    2.0.3              Fixture generator. The Faker integration for the Yii framework.
yiisoft/yii2-gii                      2.0.5              The Gii extension for the Yii framework
yiisoft/yii2-shell                    dev-master 294735e The interactive shell extension for Yii framework
yiisoft/yii2-swiftmailer              2.0.5              The SwiftMailer integration for the Yii framework

update tests folder links

What steps will reproduce the problem?

What's expected?

What do you get instead?

Additional info

Q A
Yii version
Yii Faker version
Faker version
PHP version
Operating system

update docs folder links

What steps will reproduce the problem?

What's expected?

What do you get instead?

Additional info

Q A
Yii version
Yii Faker version
Faker version
PHP version
Operating system

Faker docs problem

This issue has originally been reported by @slinstj at yiisoft/yii2#8692.
Moved here by @cebe.


Under USAGE, please change this:

    'controllerMap' => [
        'fixture' => [
            'class' => 'yii\faker\FixtureController',
            // please, add this line [in yii2-advanced, i dont know in basic]:
            'templatePath' => '@tests/codeception/common/templates/fixtures',
        ],
    ],

It will avoid this stupid error that made me (and probably many other, based in google searchs!) waste so much time to figure out where to fix that:
Error: The template path "@tests/unit/templates/fixtures" does not exist

yii help fixture results should also be updated, please.

update irc link

What steps will reproduce the problem?

What's expected?

What do you get instead?

Additional info

Q A
Yii version
Yii Faker version
Faker version
PHP version
Operating system

Insert faker data to database

If I want to insert faker data to database, what should I do?
I add the following code in my application configuration (console.php):

'controllerMap' => [
    'fixture' => [
        'class' => '@tests\faker\FixtureController',
    ],
],

And I rewrite the actionGenerate in @tests\faker\FixtureController. Is it right?

update github folder links

What steps will reproduce the problem?

http=>https

What's expected?

What do you get instead?

Additional info

Q A
Yii version
Yii Faker version
Faker version
PHP version
Operating system

update src folder links

What steps will reproduce the problem?

What's expected?

What do you get instead?

Additional info

Q A
Yii version
Yii Faker version
Faker version
PHP version
Operating system

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.