lumen-generators/lumen-test/tests/acceptance/ModelCommandCept.php

80 lines
2.6 KiB
PHP
Raw Normal View History

2016-12-29 18:35:34 +03:00
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('generate a model without fillable fields or dates');
$I->runShellCommand('php artisan wn:model TestingModel --path=tests/tmp --force=true');
$I->seeInShellOutput('TestingModel model generated');
$I->seeFileFound('./tests/tmp/TestingModel.php');
$I->openFile('./tests/tmp/TestingModel.php');
2015-09-23 17:53:55 +03:00
$I->seeFileContentsEqual('<?php namespace Tests\Tmp;
use Illuminate\Database\Eloquent\Model;
class TestingModel extends Model {
2016-12-29 18:35:34 +03:00
protected $fillable = [];
2016-12-29 18:35:34 +03:00
protected $dates = [];
2015-09-23 17:53:55 +03:00
2016-12-29 18:35:34 +03:00
public static $rules = [
// Validation rules
];
2015-09-23 17:53:55 +03:00
2016-12-29 18:35:34 +03:00
// Relationships
2015-09-23 17:53:55 +03:00
}
');
$I->deleteFile('./tests/tmp/TestingModel.php');
$I->wantTo('generate a model with fillable fields');
$I->runShellCommand('php artisan wn:model TestingModel --fillable=name,title --path=tests/tmp');
$I->seeFileFound('./tests/tmp/TestingModel.php');
$I->openFile('./tests/tmp/TestingModel.php');
2015-09-23 17:53:55 +03:00
$I->seeInThisFile('protected $fillable = ["name", "title"];');
$I->deleteFile('./tests/tmp/TestingModel.php');
$I->wantTo('generate a model with dates fields');
$I->runShellCommand('php artisan wn:model TestingModel --dates=started_at --path=tests/tmp');
$I->seeFileFound('./tests/tmp/TestingModel.php');
$I->openFile('./tests/tmp/TestingModel.php');
2015-09-23 17:53:55 +03:00
$I->seeInThisFile('protected $dates = ["started_at"];');
$I->deleteFile('./tests/tmp/TestingModel.php');
$I->wantTo('generate a model with relations');
2015-09-23 17:53:55 +03:00
$I->runShellCommand('php artisan wn:model TestingModel --has-many=accounts --belongs-to="owner:App\User" --has-one=number:Phone --path=tests/tmp');
$I->seeFileFound('./tests/tmp/TestingModel.php');
$I->openFile('./tests/tmp/TestingModel.php');
2015-09-23 17:53:55 +03:00
$I->seeInThisFile('
2016-12-29 18:35:34 +03:00
public function accounts()
{
return $this->hasMany("Tests\\Tmp\\Account");
}
2015-09-23 17:53:55 +03:00
');
$I->seeInThisFile('
2016-12-29 18:35:34 +03:00
public function owner()
{
return $this->belongsTo("App\\User");
}
2015-09-23 17:53:55 +03:00
');
$I->seeInThisFile('
2016-12-29 18:35:34 +03:00
public function number()
{
return $this->hasOne("Tests\\Tmp\\Phone");
}
2015-09-23 17:53:55 +03:00
');
$I->deleteFile('./tests/tmp/TestingModel.php');
2015-09-23 17:53:55 +03:00
$I->wantTo('generate a model with validation rules');
$I->runShellCommand('php artisan wn:model TestingModel --rules="name=required age=integer|min:13 email=email|unique:users,email_address" --path=tests/tmp');
$I->seeFileFound('./tests/tmp/TestingModel.php');
$I->openFile('./tests/tmp/TestingModel.php');
$I->seeInThisFile(
" public static \$rules = [\n" .
" \"name\" => \"required\"," . PHP_EOL .
" \"age\" => \"integer|min:13\"," . PHP_EOL .
" \"email\" => \"email|unique:users,email_address\",\n".
" ];"
);
2015-09-24 05:04:44 +03:00
$I->deleteFile('./tests/tmp/TestingModel.php');