Ejemplo n.º 1
0
 public function testArticle()
 {
     $article = Article::find(82);
     $this->assertSame(['id' => 82, 'username' => 'unique06', 'content' => 'Explicabo deserunt officia aspernatur. Ut ut sequi non. ' . 'Natus perferendis maiores non numquam. Qui pariatur repellendus pariatur laboriosam.', 'vote' => 0, 'created_at' => '2015-08-27 20:42:29', 'updated_at' => '2015-08-27 20:42:29'], $article->toArray());
     $this->assertInstanceOf(User::class, $article->user);
     $this->assertSame(['id' => 37, 'username' => 'unique06', 'created_at' => '2015-08-27 20:42:28'], $article->user->toArray());
     $this->assertInstanceOf(Collection::class, $article->categories);
     $this->assertInstanceOf(Category::class, $article->categories[0]);
     $this->assertSame(2, $article->categories->count());
     $this->assertInstanceOf(Collection::class, $article->hits);
     $this->assertInstanceOf(ArticleHit::class, $article->hits[0]);
     $this->assertSame(1, $article->hits->count());
 }
Ejemplo n.º 2
0
	`content`	varchar(100),
	`vote`	INTEGER DEFAULT 0,
	`ancestor_vote`	INTEGER DEFAULT 0,
	`order`	VARBINARY(255) DEFAULT 000,
	`ancestor_order`	VARBINARY(255) DEFAULT 000
);
*/
$capsule->schema()->create('article_hits', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->bigInteger('article_id')->unsingied();
    $table->bigInteger('user_id')->unsingied();
    $table->timestamps();
});
$capsule->schema()->create('categories', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->bigInteger('article_id')->unsigned();
    $table->string('name', 100);
});
$faker = Factory::create();
for ($i = 0; $i < 100; $i++) {
    User::create(['username' => $faker->userName, 'password' => $faker->password]);
}
for ($i = 0; $i < 200; $i++) {
    Article::create(['username' => User::find(rand(1, 100))['username'], 'content' => $faker->text]);
}
for ($i = 0; $i < 200; $i++) {
    Category::create(['article_id' => rand(1, 200), 'name' => ['Q&A', 'PHP', 'FreeBoard', 'Javascript', 'Go'][rand(0, 4)]]);
}
for ($i = 0; $i < 400; $i++) {
    ArticleHit::create(['article_id' => rand(1, 200), 'user_id' => rand(1, 100)]);
}