2017 © Pedro Peláez
 

library laravel-test-generator

Laravel 4 tests generator

image

davispeixoto/laravel-test-generator

Laravel 4 tests generator

  • Monday, February 23, 2015
  • by davispeixoto
  • Repository
  • 2 Watchers
  • 6 Stars
  • 1,146 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 7 Versions
  • 3 % Grown

The README.md

Laravel 4 Test Generator

Build Status, (*1)

This Laravel 4 package provides a powerful test generator to speed up your development process., (*2)

It's based on the facility PHPUnit Skeleton Generator provides and Jeffrey Way's Laravel 4 generators., (*3)

The first doesn't work 100% with all Laravel 4 application classes. Usually you need to add some dependency in the class to make it work, even if your project solves it all with the Composer PSR-0 compliant autoloader., (*4)

The second, generates a really tiny test class. It doesn't maps all class public methods and let everything in place., (*5)

This generator loads the target with and use the PHP Reflection features for reverse engineer all public methods, and provide an enhanced skeleton, including calls for data providers., (*6)

Installation

Begin by installing this package through Composer. Edit your project's composer.json file to require davispeixoto/testingtool., (*7)

"require": {
    "laravel/framework": "4.*",
    "davispeixoto/laravel-test-generator": "1.0.*"
},
"minimum-stability" : "stable"

Next, update Composer from the Terminal:, (*8)

composer update

Once this operation completes, the final step is to add the service provider. Open app/config/app.php, and add a new item to the providers array., (*9)

'Davispeixoto\TestGenerator\TestGeneratorServiceProvider'

That's it! You're all set to go. Run the artisan command from the Terminal to see the new tests:generate commands., (*10)

php artisan

Usage

Use tests:generate when you need to create a new PHPUnit test class. Here's an example:, (*11)


php artisan controller:make UserController php artisan tests:generate UserController

This will generate a resource controller and a test class app/tests/UserControllerTest.php as follows:, (*12)

<?php
class UserControllerTest extends TestCase {

    /**
     * Tests UserController::index
     */
    public function testindex()
    {
        //@TODO implement testindex body
    }

    /**
     * Tests UserController::create
     */
    public function testcreate()
    {
        //@TODO implement testcreate body
    }

    /**
     * Tests UserController::store
     */
    public function teststore()
    {
        //@TODO implement teststore body
    }

    /**
     * Tests UserController::show
     *
     * @dataProvider providershow
     */
    public function testshow($id)
    {
        //@TODO implement testshow body
    }

    /**
     * Tests UserController::edit
     *
     * @dataProvider provideredit
     */
    public function testedit($id)
    {
        //@TODO implement testedit body
    }

    /**
     * Tests UserController::update
     *
     * @dataProvider providerupdate
     */
    public function testupdate($id)
    {
        //@TODO implement testupdate body
    }

    /**
     * Tests UserController::destroy
     *
     * @dataProvider providerdestroy
     */
    public function testdestroy($id)
    {
        //@TODO implement testdestroy body
    }


    /**
     * Data provider function for UserController::show
     */
    public function providershow()
    {
        return $this->dataProvider('UserController.show.csv');
    }

    /**
     * Data provider function for UserController::edit
     */
    public function provideredit()
    {
        return $this->dataProvider('UserController.edit.csv');
    }

    /**
     * Data provider function for UserController::update
     */
    public function providerupdate()
    {
        return $this->dataProvider('UserController.update.csv');
    }

    /**
     * Data provider function for UserController::destroy
     */
    public function providerdestroy()
    {
        return $this->dataProvider('UserController.destroy.csv');
    }

}
?>

For full usage, I recommend first reading the article Testing Like a Boss in Laravel. There are some performance tuning to be made in the Laravel 4 core TestCase class., (*13)

Along with them, to add the data providers functionality. Add to your Laravel composer.json:, (*14)

"require": {
    "laravel/framework": "4.1.*",
    "davispeixoto/testingtool": "dev-master",
    "keboola/csv" : "dev-master"
},
"minimum-stability" : "dev"

Next, update Composer from the Terminal:, (*15)

composer update

And finally, let the TestCase class like this:, (*16)

prepareForTests();
    }

    /**
     * Creates the application.
     *
     * @return \Symfony\Component\HttpKernel\HttpKernelInterface
     */
    public function createApplication()
    {
        $unitTesting = true;
        $testEnvironment = 'testing';
        return require __DIR__.'/../../bootstrap/start.php';
    }
    
    /**
     * Migrates the database.
     * This will cause the tests to run quickly.
     */
    private function prepareForTests()
    {
        Artisan::call('migrate');
    }
    
    /**
     * dataProviders Factory
     * dataProvider Short Description
     *
     * @param string $fileName
     * @return \Keboola\Csv\CsvFile
     */
    public function dataProvider($fileName) {
        return new Keboola\Csv\CsvFile(__DIR__.'/data/'.$fileName);
    }
}
?>

With these little changes, you can really speed up your testing process for your Laravel application., (*17)

License

This Test Generator is open-sourced software licensed under the MIT license, (*18)

Versioning

This project follows the Semantic Versioning, (*19)

The Versions

23/02 2015

dev-master

9999999-dev

Laravel 4 tests generator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Davis Peixoto

laravel test generator artisan

23/02 2015

1.0.5

1.0.5.0

Laravel 4 tests generator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Davis Peixoto

laravel test generator artisan

05/10 2014

1.0.4

1.0.4.0

Laravel 4 tests generator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Davis Peixoto

laravel test generator artisan

05/10 2014

1.0.3

1.0.3.0

Laravel 4 tests generator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Davis Peixoto

laravel test generator artisan

24/04 2014

1.0.2

1.0.2.0

Laravel 4 tests generator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Davis Peixoto

laravel test generator artisan

16/04 2014

1.0.1

1.0.1.0

Laravel 4 tests generator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Davis Peixoto

laravel test generator artisan

22/02 2014

1.0.0

1.0.0.0

Laravel 4 tests generator

  Sources   Download

MIT

The Requires

 

by Davis Peixoto

laravel test generator artisan