Giter Club home page Giter Club logo

phpunit-seed's Introduction

phpunit-seed

DEPRECATED in favor of icanhazstring/phpunit-faker-extension

Build Status

phpunit extenstion with fzaninotto/Faker integration

Installation

To install this extension, simply use composer.

$ composer require --dev icanhazstring/phpunit-seed

Usage

To use this extension, make sure your tests derive from PHPUnitSeed\Framework\TestCase instead of the PHPUnit default.

This will add a new function fake() into your test suites.

class SuperTest extends PHPUnitSeed\Framework\Testcase
{
    public function testAwesome()
    {
        $name = $this->fake()->name();
        $this->assertEquals($name, $this->fake()->name());
        // should work
    }
}

Run tests with seed

To execute all your tests with random or specific seeds use the deliverd binary.

$ vendor/bin/phpunit-seed [--seed=<int>]

You will get an output similar to this

$ vendor/bin/phpunit-seed -c phpunit.xml
PHPUnit 6.4.3 by Sebastian Bergmann and contributors.

.                                                                   1 / 1 (100%)

Time: 128 ms, Memory: 6.00MB

OK (1 test, 2 assertions)

Randomized with seed: 1234

In the last output line you will see the seed number which was used for this execution. If you want to execute the same tests, with same random values, use the --seed=<int> argument for the binary.

Change Faker locale

You can change the locale of 'Faker' in two ways:

  1. Change the static FAKE_LOCALE in your test class
    class MyTestCase extends PHPUnitSeed\Framework\Testcase
    {
        protected static FAKE_LOCALE = 'de_DE';
    
         public function itShouldTestWithDELocale()
        {
            $name = $this->fake()->name; // will be name from de_DE provider
        }
    }
  2. Call the fake method with your desired locale
    class MyTestCase extends PHPUnitSeed\Framework\Testcase
    {
        public function itShouldTestWithDELocale()
        {
            $name = $this->fake('de_DE')->name; // will be name from de_DE provider
        }
    }

Faker Documentation

For a full usage on Faker see fzaninotto/Faker

phpunit-seed's People

Contributors

icanhazstring avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.