Beispiel #1
0
 public function testUser()
 {
     $user = User::find(99);
     $this->assertSame(['id' => 99, 'username' => 'nmayert', 'created_at' => '2015-08-27 20:42:29'], $user->toArray());
     $this->assertSame(['id' => '99', 'username' => 'nmayert', 'password' => 'wYyZ*3:0kQ', 'created_at' => '2015-08-27 20:42:29', 'updated_at' => '2015-08-27 20:42:29'], $user->getAttributes());
     $this->assertInstanceOf(Collection::class, $user->articles);
     $this->assertInstanceOf(Article::class, $user->articles[0]);
     $this->assertSame(5, $user->articles->count());
     $this->assertInstanceOf(Collection::class, $user->hits);
     $this->assertInstanceOf(ArticleHit::class, $user->hits[0]);
     $this->assertSame(1, $user->hits->count());
 }
	`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)]);
}