/** * Test trying to call report() on an already reported match */ public function test_double_report() { $this->assertTrue($this->object->is_new()); $this->assertTrue($this->object->set_winner($this->object->team())); $this->assertSave($this->object->report()); //Already reported - it should throw a fit if I try again $this->assertFalse($this->object->report()); }
/** * If a match is reported, this method can be called to clear any * cached opponent results this team may have saved * * @return void */ public function reset_opponents() { //If the current match was reported, save it as the last_match $this->last_match =& $this->bb->ref(null); if (!is_null($this->match)) { if ($this->match->team_in_match($this)) { if (!$this->match->is_new()) { $this->last_match = $this->match; } } } //Assign to a new reference, so that we're not changing the original team value in Tournament::$teams $this->opponent =& $this->bb->ref(null); $this->match =& $this->bb->ref(null); $this->eliminated_by =& $this->bb->ref(null); //Clear all cache for this team's ID $this->clear_id_cache(); }
/** * Create a new match, or validate an existing one<br /><br /> * * <br /><br /> * Can be used 2 ways:<br /><br /> * <b>1)</b> Returns the open BBMatch object where the $team1 and $team2 meet,<br /> * it will try to return an unreported BBMatch from the open_matches array * * <br /> * <b>2)</b> Verifies that the provided BBMatch object is valid / part of this tournament * In which case, we return the valid most up-to-date object instance possible, even if the only thing that matches * from your BBMatch, is the id * * * @param int|BBTeam|BBMatch $team1 * <b>Possible values:</b> * - The <b>integer</b> ID the either team in the match * - The {@link BBTeam} object of either team in the match * - A {@link BBMatch} object - to verify that it exists and to fetch the latest and created instance, stored in our open matches array * * @param int|BBTeam $team2 * <b>Possible values:</b> * - The <b>integer</b> ID the either team in the match (can't be the same as <var>$team1</var>) * - The {@link BBTeam} object of either team in the match (can't be the same as <var>$team1</var>) * * @return BBMatch|null */ public function &match($team1 = null, $team2 = null) { //If given BBMatch, verify or return null if ($team1 instanceof BBMatch) { //if unreported - check it against our open_matches list if ($team1->is_new()) { return $this->get_child($team1, $this->open_matches()); } else { //Cast as a BBMatch $match = $this->bb->match($team1->id); $match->init($this); if ($match->tourney_id != $this->id) { return $this->bb->ref(null); } //success! return $match; } } //If team1 is a number, and team 2 is null, treat team1 as a tourney_match_id if (is_numeric($team1) && is_null($team2)) { $match = $this->bb->match($team1); $match->init($this); return $match->load(); } //Let open_match() take over return $this->open_match($team1, $team2); }