$brew_info = array('beer_name' => $beer_name, 'pub_name' => $pub_name, 'beer_rating' => $brew->getBeerRating(), 'brew_date' => $brew->getBrewDate()); array_push($brews, $brew_info); } return $app['twig']->render("drunk_profile.html.twig", array('drunk' => $drunk, 'brews' => $brews)); }); //route that adds a brew to a profile page $app->get('/add_brew', function () use($app) { $app['twig']->addGlobal('logged_user', $_SESSION['user']); $all_beers = Beer::getAll(); $all_pubs = Pub::getAll(); return $app['twig']->render("brew.html.twig", array('all_beers' => $all_beers, 'all_pubs' => $all_pubs)); }); //route posts a brew to a profile page $app->post('/public_login/{id}', function ($id) use($app) { $app['twig']->addGlobal('logged_user', $_SESSION['user']); $new_brew = new Brew($_POST['beer_id'], $_POST['drunk_id'], $_POST['pub_id'], $_POST['rating'], $_POST['date']); $new_brew->save(); $drunk = Drunk::find($id); $drunk_brews = $drunk->getBrews(); $brews = array(); foreach ($drunk_brews as $brew) { $beer = Beer::find($brew->getBeerId()); $beer_name = $beer->getName(); $pub = Pub::find($brew->getPubId()); $pub_name = $pub->getName(); $brew_info = array('beer_name' => $beer_name, 'pub_name' => $pub_name, 'beer_rating' => $brew->getBeerRating(), 'brew_date' => $brew->getBrewDate()); array_push($brews, $brew_info); } return $app['twig']->render("drunk_profile.html.twig", array('drunk' => $drunk, 'brews' => $brews)); }); //Display all beers
function testGetBrews() { //Arrange $name = "Person 1"; $date_of_birth = "1988-03-04"; $location = "Portland, OR"; $email = "*****@*****.**"; $password = "******"; $test_drunk = new Drunk($name, $date_of_birth, $location, $email, $password); $test_drunk->save(); $beer_id = 1; $drunk_id = $test_drunk->getId(); $pub_id = 1; $beer_rating = 4.5; $brew_date = "2015-04-03"; $new_brew = new Brew($beer_id, $drunk_id, $pub_id, $beer_rating, $brew_date); $new_brew->save(); $beer_id2 = 2; $drunk_id2 = $test_drunk->getId(); $pub_id2 = 2; $beer_rating2 = 4.5; $brew_date2 = "2015-04-03"; $new_brew2 = new Brew($beer_id2, $drunk_id2, $pub_id2, $beer_rating2, $brew_date2); $new_brew2->save(); //Act $result = $test_drunk->getBrews(); //Assert $this->assertEquals([$new_brew, $new_brew2], $result); }
function test_getRating() { //Arrange $id = null; $name = "Lip Blaster"; $type = "IPA"; $abv = 4.2; $ibu = 10; $region = "Pacific Northwest"; $brewery_id = 1; $test_beer = new Beer($id, $name, $type, $abv, $ibu, $region, $brewery_id); $test_beer->save(); $beer_id = $test_beer->getId(); $drunk_id = 1; $pub_id = 1; $beer_rating = 2; $brew_date = "2015-04-03"; $new_brew = new Brew($beer_id, $drunk_id, $pub_id, $beer_rating, $brew_date); $new_brew->save(); $beer_id2 = $test_beer->getId(); $drunk_id2 = 2; $pub_id2 = 2; $beer_rating2 = 4; $brew_date2 = "2015-04-03"; $new_brew2 = new Brew($beer_id2, $drunk_id2, $pub_id2, $beer_rating2, $brew_date2); $new_brew2->save(); //Act $result = $test_beer->getRating(); //Assert $this->assertEquals(3, $result); }
if (is_dir(VALET_HOME_PATH)) { Configuration::prune(); Site::pruneLinks(); } /** * Allow Valet to be run more conveniently by allowing the Node proxy to run password-less sudo. */ $app->command('install', function () { Caddy::stop(); Configuration::install(); Caddy::install(); PhpFpm::install(); DnsMasq::install(); Caddy::restart(); Valet::symlinkToUsersBin(); Brew::createSudoersEntry(); Valet::createSudoersEntry(); output(PHP_EOL . '<info>Valet installed successfully!</info>'); })->descriptions('Install the Valet services'); /** * Get or set the domain currently being used by Valet. */ $app->command('domain [domain]', function ($domain = null) { if ($domain === null) { return info(Configuration::read()['domain']); } DnsMasq::updateDomain($oldDomain = Configuration::read()['domain'], $domain = trim($domain, '.')); Configuration::updateKey('domain', $domain); Site::resecureForNewDomain($oldDomain, $domain); PhpFpm::restart(); Caddy::restart();
function testdelete() { //Arrange $beer_id = 1; $drunk_id = 1; $pub_id = 1; $beer_rating = 4.5; $brew_date = "2015-04-03"; $new_brew = new Brew($beer_id, $drunk_id, $pub_id, $beer_rating, $brew_date); $new_brew->save(); $beer_id2 = 2; $drunk_id2 = 2; $pub_id2 = 2; $beer_rating2 = 4.5; $brew_date2 = "2015-04-03"; $new_brew2 = new Brew($beer_id2, $drunk_id2, $pub_id2, $beer_rating2, $brew_date2); $new_brew2->save(); //Act $new_brew2->delete(); $result = Brew::getAll(); //Assert $this->assertEquals([$new_brew], $result); }
static function find($search_id) { $brews = Brew::getAll(); $found_brew = null; foreach ($brews as $brew) { $brew_id = $brew->getId(); if ($brew_id == $search_id) { $found_brew = $brew; } } return $found_brew; }