recca0120 / package-phpunit by recca0120

laravel package development phpunit
47
4
2
Package Data
Maintainer Username: recca0120
Maintainer Contact: recca0120@gmail.com (recca0120)
Package Create Date: 2016-01-30
Package Last Update: 2016-06-03
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:13:14
Package Statistics
Total Downloads: 47
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 4
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Laravel Package Develop Phpunit

Install

step1

composer.json

require-dev: {
    "recca0120/package-phpunit": "~0.2.1"
}

composer install or composer update

step2

copy phpunit.xml, tests folder to root

step3

execute phpunit

Example

This package is auto setup database [sqlite]

you can add migrations to database/migrations

and in your test case add code

class DatabaseTest extends PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        $app = App::getInstance();
        $app->migrate('up');
    }

    public function tearDown()
    {
        $app = App::getInstance();
        $app->migrate('down');
    }
}

FULL DEMO

use Illuminate\Database\Eloquent\Model;

class DatabaseTest extends PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        $app = App::getInstance();
        $app->migrate('up');
    }

    public function tearDown()
    {
        $app = App::getInstance();
        $app->migrate('down');
    }

    public function test_app_environment()
    {
        $this->assertEquals(App::environment(), 'testing');
    }

    public function test_insert_into_database()
    {
        $data = [
            'test1' => 'test1',
            'test2' => 'test2',
            'test3' => 'test3',
        ];
        $test = Test::create($data);
        // $result = $test->toArray();
        $this->assertEquals($test->id, 1);
        $this->assertEquals($test->test1, $data['test1']);
        $this->assertEquals($test->test2, $data['test2']);
        $this->assertEquals($test->test3, $data['test3']);
    }
}

class Test extends Model
{
    protected $guarded = ['id'];
}

notice

sqlite is not support alter table