Skip to content

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Feb 25, 2019
1 parent 4ee5c70 commit 416e298
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 93 deletions.
11 changes: 6 additions & 5 deletions .gitattributes
@@ -1,5 +1,6 @@
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
.travis.yml export-ignore
phpunit.xml.dist export-ignore
10 changes: 5 additions & 5 deletions .gitignore
@@ -1,8 +1,8 @@
/.idea
/.vagrant
/vendor
/after.sh
/aliases
/composer.lock
/Homestead.yaml
/Vagrantfile
after.sh
aliases
composer.lock
Homestead.yaml
Vagrantfile
6 changes: 0 additions & 6 deletions .travis.yml
Expand Up @@ -18,15 +18,9 @@ matrix:
- php: 7.0
env: RELEASE=lowest
- php: 7.1
- php: 7.1
env: RELEASE=lowest
- php: 7.2
- php: 7.2
env: RELEASE=lowest
- php: 7.3
env: COVERAGE=yes
- php: 7.3
env: RELEASE=lowest
- php: 7.3
env: COVERAGE=yes DB=pgsql

Expand Down
176 changes: 99 additions & 77 deletions tests/TestCase.php
Expand Up @@ -27,6 +27,18 @@ protected function setUp()
$db->setAsGlobal();
$db->bootEloquent();

$this->migrate();

$this->seed();
}

/**
* Migrate the database.
*
* @return void
*/
protected function migrate()
{
DB::schema()->dropAllTables();

DB::schema()->create('countries', function (Blueprint $table) {
Expand Down Expand Up @@ -70,83 +82,93 @@ protected function setUp()
$table->unsignedInteger('tag_id');
$table->morphs('taggable');
});
}

Model::unguarded(function () {
Country::create();
Country::create();

User::create(['country_id' => 1]);
User::create(['country_id' => 2]);

Post::create(['user_id' => 1, 'created_at' => new Carbon('2018-01-01 00:00:01')]);
Post::create(['user_id' => 1, 'created_at' => new Carbon('2018-01-01 00:00:02')]);
Post::create(['user_id' => 1, 'created_at' => new Carbon('2018-01-01 00:00:03')]);
Post::create(['user_id' => 2, 'created_at' => new Carbon('2018-01-01 00:00:04')]);
Post::create(['user_id' => 2, 'created_at' => new Carbon('2018-01-01 00:00:05')]);
Post::create(['user_id' => 2, 'created_at' => new Carbon('2018-01-01 00:00:06')]);

Comment::create([
'commentable_type' => Post::class,
'commentable_id' => 1,
'created_at' => new Carbon('2018-01-01 00:00:01'),
]);
Comment::create([
'commentable_type' => Post::class,
'commentable_id' => 1,
'created_at' => new Carbon('2018-01-01 00:00:02'),
]);
Comment::create([
'commentable_type' => Post::class,
'commentable_id' => 1,
'created_at' => new Carbon('2018-01-01 00:00:03'),
]);
Comment::create([
'commentable_type' => Post::class,
'commentable_id' => 2,
'created_at' => new Carbon('2018-01-01 00:00:04'),
]);
Comment::create([
'commentable_type' => Post::class,
'commentable_id' => 2,
'created_at' => new Carbon('2018-01-01 00:00:05'),
]);
Comment::create([
'commentable_type' => Post::class,
'commentable_id' => 2,
'created_at' => new Carbon('2018-01-01 00:00:06'),
]);

Role::create(['created_at' => new Carbon('2018-01-01 00:00:01')]);
Role::create(['created_at' => new Carbon('2018-01-01 00:00:02')]);
Role::create(['created_at' => new Carbon('2018-01-01 00:00:03')]);
Role::create(['created_at' => new Carbon('2018-01-01 00:00:04')]);
Role::create(['created_at' => new Carbon('2018-01-01 00:00:05')]);
Role::create(['created_at' => new Carbon('2018-01-01 00:00:06')]);

DB::table('role_user')->insert([
['role_id' => 1, 'user_id' => 1],
['role_id' => 2, 'user_id' => 1],
['role_id' => 3, 'user_id' => 1],
['role_id' => 4, 'user_id' => 2],
['role_id' => 5, 'user_id' => 2],
['role_id' => 6, 'user_id' => 2],
]);

Tag::create(['created_at' => new Carbon('2018-01-01 00:00:01')]);
Tag::create(['created_at' => new Carbon('2018-01-01 00:00:02')]);
Tag::create(['created_at' => new Carbon('2018-01-01 00:00:03')]);
Tag::create(['created_at' => new Carbon('2018-01-01 00:00:04')]);
Tag::create(['created_at' => new Carbon('2018-01-01 00:00:05')]);
Tag::create(['created_at' => new Carbon('2018-01-01 00:00:06')]);

DB::table('taggables')->insert([
['tag_id' => 1, 'taggable_type' => Post::class, 'taggable_id' => 1],
['tag_id' => 2, 'taggable_type' => Post::class, 'taggable_id' => 1],
['tag_id' => 3, 'taggable_type' => Post::class, 'taggable_id' => 1],
['tag_id' => 4, 'taggable_type' => Post::class, 'taggable_id' => 2],
['tag_id' => 5, 'taggable_type' => Post::class, 'taggable_id' => 2],
['tag_id' => 6, 'taggable_type' => Post::class, 'taggable_id' => 2],
]);
});
/**
* Seed the database.
*
* @return void
*/
protected function seed()
{
Model::unguard();

Country::create();
Country::create();

User::create(['country_id' => 1]);
User::create(['country_id' => 2]);

Post::create(['user_id' => 1, 'created_at' => new Carbon('2018-01-01 00:00:01')]);
Post::create(['user_id' => 1, 'created_at' => new Carbon('2018-01-01 00:00:02')]);
Post::create(['user_id' => 1, 'created_at' => new Carbon('2018-01-01 00:00:03')]);
Post::create(['user_id' => 2, 'created_at' => new Carbon('2018-01-01 00:00:04')]);
Post::create(['user_id' => 2, 'created_at' => new Carbon('2018-01-01 00:00:05')]);
Post::create(['user_id' => 2, 'created_at' => new Carbon('2018-01-01 00:00:06')]);

Comment::create([
'commentable_type' => Post::class,
'commentable_id' => 1,
'created_at' => new Carbon('2018-01-01 00:00:01'),
]);
Comment::create([
'commentable_type' => Post::class,
'commentable_id' => 1,
'created_at' => new Carbon('2018-01-01 00:00:02'),
]);
Comment::create([
'commentable_type' => Post::class,
'commentable_id' => 1,
'created_at' => new Carbon('2018-01-01 00:00:03'),
]);
Comment::create([
'commentable_type' => Post::class,
'commentable_id' => 2,
'created_at' => new Carbon('2018-01-01 00:00:04'),
]);
Comment::create([
'commentable_type' => Post::class,
'commentable_id' => 2,
'created_at' => new Carbon('2018-01-01 00:00:05'),
]);
Comment::create([
'commentable_type' => Post::class,
'commentable_id' => 2,
'created_at' => new Carbon('2018-01-01 00:00:06'),
]);

Role::create(['created_at' => new Carbon('2018-01-01 00:00:01')]);
Role::create(['created_at' => new Carbon('2018-01-01 00:00:02')]);
Role::create(['created_at' => new Carbon('2018-01-01 00:00:03')]);
Role::create(['created_at' => new Carbon('2018-01-01 00:00:04')]);
Role::create(['created_at' => new Carbon('2018-01-01 00:00:05')]);
Role::create(['created_at' => new Carbon('2018-01-01 00:00:06')]);

DB::table('role_user')->insert([
['role_id' => 1, 'user_id' => 1],
['role_id' => 2, 'user_id' => 1],
['role_id' => 3, 'user_id' => 1],
['role_id' => 4, 'user_id' => 2],
['role_id' => 5, 'user_id' => 2],
['role_id' => 6, 'user_id' => 2],
]);

Tag::create(['created_at' => new Carbon('2018-01-01 00:00:01')]);
Tag::create(['created_at' => new Carbon('2018-01-01 00:00:02')]);
Tag::create(['created_at' => new Carbon('2018-01-01 00:00:03')]);
Tag::create(['created_at' => new Carbon('2018-01-01 00:00:04')]);
Tag::create(['created_at' => new Carbon('2018-01-01 00:00:05')]);
Tag::create(['created_at' => new Carbon('2018-01-01 00:00:06')]);

DB::table('taggables')->insert([
['tag_id' => 1, 'taggable_type' => Post::class, 'taggable_id' => 1],
['tag_id' => 2, 'taggable_type' => Post::class, 'taggable_id' => 1],
['tag_id' => 3, 'taggable_type' => Post::class, 'taggable_id' => 1],
['tag_id' => 4, 'taggable_type' => Post::class, 'taggable_id' => 2],
['tag_id' => 5, 'taggable_type' => Post::class, 'taggable_id' => 2],
['tag_id' => 6, 'taggable_type' => Post::class, 'taggable_id' => 2],
]);

Model::reguard();
}
}

0 comments on commit 416e298

Please sign in to comment.