예제 #1
0
 public function testAWordCanBeCreated()
 {
     $faker = Faker\Factory::create();
     $user = factory(User::class)->create(['username' => 'janedoe2']);
     $word_str = $faker->word;
     $args = array('word' => $word_str, 'user_id' => $user->id);
     $word = Word::create($args);
     $first_letter = Letter::where('word_id', $word->id)->where('ordinal', '1')->first();
     $this->assertEquals($word->word, $word_str);
     $this->assertEquals($first_letter->letter, substr($word_str, 0, 1));
     if (strlen($word_str) > 1) {
         $second_letter = Letter::where('word_id', $word->id)->where('ordinal', 2)->first();
         $this->assertEquals($second_letter->letter, substr($word_str, 1, 1));
     }
 }
예제 #2
0
 public function run()
 {
     $user = User::where('username', 'system')->first();
     $filename = "data/58000words.txt";
     $words_str = File::get($filename);
     if (env("COMPUTER") == "HOMEMAC") {
         $words = explode("\n", $words_str);
     } else {
         $words = explode("\r\n", $words_str);
     }
     foreach ($words as $word_str) {
         $word = Word::where('word', $word_str)->first();
         if (!$word) {
             $args = array('word' => $word_str, 'user_id' => $user->id);
             $word = Word::create($args);
         }
     }
 }