recca0120 / package-phpunit
laravel 包开发 phpunit
v0.2.1
2016-02-01 06:19 UTC
Requires
- php: >=5.5.9
- illuminate/container: ~5.1
- illuminate/contracts: ~5.1
- illuminate/database: ~5.1
- illuminate/events: ~5.1
- illuminate/hashing: ~5.1
- illuminate/support: ~5.1
- nesbot/carbon: ~1.20
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~4.0
Suggests
- recca0120/terminal: Required to use the Terminal Panel (~2.0.5)
This package is auto-updated.
Last update: 2024-09-10 05:59:29 UTC
README
安装
步骤1
composer.json
require-dev: {
"recca0120/package-phpunit": "~0.2.1"
}
运行 composer install 或 composer update
步骤2
将 phpunit.xml 和 tests 文件夹复制到根目录
步骤3
执行 phpunit
示例
此包自动设置数据库 [sqlite]
您可以将迁移添加到 database/migrations
并在您的测试用例中添加代码
class DatabaseTest extends PHPUnit_Framework_TestCase { public function setUp() { $app = App::getInstance(); $app->migrate('up'); } public function tearDown() { $app = App::getInstance(); $app->migrate('down'); } }
完整示例
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']; }