Giter VIP home page Giter VIP logo

fixture's People

Contributors

clphillips avatar tabennett avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

fixture's Issues

Auto increment ID values

Random IDs might be okay for testing, but seeding generally requires that table IDs increment in the order they were inserted.

This can be accomplished by assigning a count to each item in a table fixture and referencing the count when inserting.

// apples.php
return [
    // ID: 1
    'Granny-Smith' => [
        'color' => 'green',
        'description' => 'Tart'
    ],
    // ID: 2
    'Red Delicious' => [
        'color' => 'red',
        'description' => 'Slightly Tart'
    ]
];

So when we insert a foreign key:

// apple_sauces.php
return [
    // ID: 1
    'Treetop' => [
        'apple_id' => 'Red Delicious' // foreign key ID 1
    ],
    // ID: 2
    'Kirkland' => [
        'apple_id' => 'Red Delicious' // foreign key ID 1
    ]
];

Obviously requires preprocessing all fixtures.

Here's an alternative (allow integer values to be assigned as foreign keys):

// apple_sauces.php
return [
    // ID: 1
    'Treetop' => [
        'apple_id' => 1
    ],
    // ID: 2
    'Kirkland' => [
        'apple_id' => 1
    ]
];

Throw exception when fixture is not an array

This is an idiot proofing thing I guess but if I create a filetests/fixtures/users.php like this will give me an error...

<?php array(
  'User1' => array(
    'first_name' => 'Kelt'
  )
);

The problem above is that I am not returning an array so I get a strange error.

ErrorException: Invalid argument supplied for foreach()

/vendor/codesleeve/fixture/src/Codesleeve/Fixture/Repositories/IlluminateDatabaseRepository.php:55
/vendor/codesleeve/fixture/src/Codesleeve/Fixture/Fixture.php:181

It would be nice to throw an exception here instead letting the developer know what they did wrong. Something like

FixtureDataNotFoundException: 'No array was returned in users.php'

Truncating based on config, not inserts

It would be nice if invoking Fixture::down() truncated based on the tables defined by the config files, as opposed to the tables actually inserted into.

That would make it possible to use this library to seed databases. For example, I run my database migration, then I seed the database. The seed process needs to truncate data before inserting (which is contrary to fixtures for integration testing) because we're not starting with a fresh database.

Thoughts? I'm happy to hack on this and submit a PR.

Throw exception when fixture name doesn't exist

If we try to call Fixture::user('User1') instead of Fixture::users('User1') then we get a strange error...

ErrorException: array_key_exists() expects parameter 2 to be array, null given
at vendor/codesleeve/fixture/src/Codesleeve/Fixture/Fixture.php:109

This is happening because there is no user fixture but it would be nice to see an exception thrown here instead, something like:

InvalidFixtureNameException: There is no such fixture: 'user'.

ID integer values too large for column type 'integer' in postgres

generateKey function in Repository outputs a 10-digit integer, which is used for a record ID. The integer can exceed max size for Postgres integer column.

    protected function generateKey($value)
    {
        $hash = sha1($value);
        $integerHash = base_convert($hash, 16, 10);

        return (int)substr($integerHash, 0, 10);
    }

Changing the substring length will correct the issue.

    protected function generateKey($value)
    {
        $hash = sha1($value);
        $integerHash = base_convert($hash, 16, 10);

        return (int)substr($integerHash, 0, 8);
    }

Error when relationships are arrays.

Installed v1.0.0

 codesleeve/fixture                v1.0.0             A framework agnostic, simple (yet elegant) fixture library for php.
 codesleeve/fixture-l4             dev-master 23db25b A simple, easy to use fixture library for Laravel 4

ErrorException: explode() expects parameter 2 to be string, array given

/api/vendor/codesleeve/fixture/src/Codesleeve/Fixture/Drivers/Eloquent.php:147
/api/vendor/codesleeve/fixture/src/Codesleeve/Fixture/Drivers/Eloquent.php:113
/api/vendor/codesleeve/fixture/src/Codesleeve/Fixture/Drivers/Eloquent.php:71
/api/vendor/codesleeve/fixture/src/Codesleeve/Fixture/Fixture.php:312
/api/vendor/codesleeve/fixture/src/Codesleeve/Fixture/Fixture.php:289
/api/vendor/codesleeve/fixture/src/Codesleeve/Fixture/Fixture.php:252
/api/vendor/codesleeve/fixture/src/Codesleeve/Fixture/Fixture.php:203
/api/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:208

fixtures/assets.php

return array(
    'asset_1' => array(
        'account' => 'account_1',
        'url' => 'https://example.com/images/image1.jpg',
        'name' => 'image1.jpg',
        'type' => 'image',
    ),
    'asset_2' => array(
        'account' => 'account_1',
        'url' => 'https://example.com/images/image2.jpg',
        'name' => 'image2.jpg',
        'type' => 'image',
    ),
);

fixtures/products.php

return array(
    'product_2_service' => array(
        'type' => 'service',
        'name' => 'Test Service Product 2',
        'description' => 'Qui aliquid magni laborum et aliquam. Nesciunt ut reiciendis libero architecto aliquid atque maiores. Placeat cum incidunt omnis tempore qui.',
        'sku' => 'TEST_SKU-SERVICE-00002',
       ...
        'assets' => 'asset_1,asset_2'  // OK
       ...
        'assets' => array('asset_1', 'asset_2')  // ERROR
    ),
);

Your documentation says to use arrays for these many relationships, so either we should update the documentation or fix this to support array relationships?

Allow fixtures to support Closures

It would be nice if fixture files could support Closures. For example:

// users.php
return array(
    'AdminUser' => array(
        'first_name' => 'Admin',
        'last_name' => 'User',
        'email' => '[email protected]',
        'password' => function () {
            $mylib = new MyLibrary();
            return $mylib->hashPassword('password');
        }
    )
);

Thoughts?

Installation issues due to Faker

Trying to install via Composer, but getting this error

Problem 1 - codesleeve/fixture v1.0.0 requires fzaninotto/faker 1.3.0 -> no matching package found.

Not sure why as I see faker 1.3 in their repo

PHP requirement is wrong

Base requirement is really 5.3, not 5.4. Only dev dependencies actually require 5.4.

    "require": {
        "php": ">=5.4.0",
        "fzaninotto/faker": "~1.4"
    },
    "require-dev": {
        "mockery/mockery": "~0.9",
        "illuminate/support": "~5",
        "illuminate/database": "~5",
        "phpunit/phpunit": "~4.6"
    },

Should be:

    "require": {
        "php": ">=5.3.0",
        "fzaninotto/faker": "~1.4"
    },
    "require-dev": {
        "php": ">=5.4.0",
        "mockery/mockery": "~0.9",
        "illuminate/support": "~5",
        "illuminate/database": "~5",
        "phpunit/phpunit": "~4.6"
    },

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.