public function inlineSave(array $data = []) { foreach ($data as $key => $value) { switch ($key) { case 'name': case 'last_name': $this->model->{$key} = trim($value); $this->model->save(); break; } } return true; }
/** * Tests if the repo removeAdministrator removes an * admin properly. */ public function testRepoRemoveAdminSuccessRemoval() { $admin = Factory::create('App\\Models\\Administrator'); $wasDeleted = $this->repository->removeAdministrator($admin->nickname); $this->assertTrue($wasDeleted); $this->assertNull(Administrator::find($admin->id)); }
/** * Run the database seeds. * * @return void */ public function run() { // foreach (Models\Administrator::all() as $admin) { // $admin->delete(); // } Models\Administrator::create(['username' => 'admin', 'password' => Hash::make('admin'), 'name' => 'Administrator']); }
/** * Tests if the remove match on the repo * works correclty. */ public function testRemoveMatchRemovalSuccess() { $match = Factory::create('App\\Models\\Match'); $result = $this->repository->removeMatch(Administrator::find($match->created_by), $match->id); $this->assertTrue($result); $this->assertNull(Match::find($match->id)); }
/** * Tests if the player validation works * as expected. * * @expectedException Illuminate\Database\Eloquent\ModelNotFoundException */ public function testTournamentPlayerValidation() { $tournament = Factory::create('App\\Models\\Tournament'); $admin = Administrator::find($tournament->created_by); $player = Factory::create('App\\Models\\Player'); $this->repository->addRanking($admin, $player, $tournament, 0); }
/** * @return \yii\db\ActiveQuery */ public function getAdministrator() { return $this->hasOne(Administrator::className(), ['id' => 'id']); }
/** * Tests if the dettach player method * works correctly. */ public function testRepoDettachPlayerPlayerDettached() { $player = Factory::create('App\\Models\\Player'); $tournament = Factory::create('App\\Models\\Tournament'); $admin = Administrator::find($tournament->created_by); $this->repository->attachPlayer($admin, $tournament->name, $player); $result = $this->repository->detachPlayer($admin, $tournament->name, $player); $this->assertTrue($result); $this->assertCount(0, $tournament->players); }
<?php use Laracasts\TestDummy\Factory; $factory('App\\Models\\User', ['name' => $faker->name, 'email' => $faker->email, 'password' => $faker->password]); $factory('App\\Models\\Player', ['nickname' => $faker->name, 'user_id' => 'factory:App\\Models\\User']); $factory('App\\Models\\Administrator', ['nickname' => $faker->name, 'user_id' => 'factory:App\\Models\\User']); $factory('App\\Models\\Game', ['name' => $faker->name]); $factory('App\\Models\\Tournament', ['name' => $faker->name, 'begin' => $faker->dateTimeBetween('now', '+3 days'), 'finish' => $faker->dateTimeBetween('+3 days', '+3 days'), 'has_ended' => false, 'created_by' => 'factory:App\\Models\\Administrator']); $factory('App\\Models\\Match', function ($faker) { $tournament = Factory::create('App\\Models\\Tournament'); $admin = \App\Models\Administrator::find($tournament->created_by); return ['tournament_id' => $tournament->id, 'first_player_id' => 'factory:App\\Models\\Player', 'second_player_id' => 'factory:App\\Models\\Player', 'winner' => 'factory:App\\Models\\Player', 'begin' => $faker->dateTimeBetween('now', '+2 days'), 'finish' => $faker->dateTimeBetween('+2 days', '+2 days'), 'created_by' => $admin->id]; }); $factory('App\\Models\\Ranking', ['tournament_id' => 'factory:App\\Models\\Tournament', 'player_id' => 'factory:App\\Models\\Player', 'score' => mt_rand(0, 150)]);
/** * Removes the specified admin. * * @param str $nickname * * @return boolean */ public function removeAdministrator($nickname) { return Administrator::where('nickname', $nickname)->firstOrFail()->delete(); }