static function find($search_id) { $found_item = null; $items = Inventory::getAll(); foreach ($items as $item) { $item_id = $item->getId(); if ($item_id == $search_id) { $found_item = $item; } } return $found_item; }
function test_deleteAll() { $item = "POGs"; $item2 = "Pokemon Cards"; $test_item = new Inventory($item); $test_item->save(); $test_item2 = new Inventory($item2); $test_item2->save(); Inventory::deleteAll(); $result = Inventory::getAll(); $this->assertEquals([], $result); }
static function find($search_item) { $found_item = NULL; $inventory = Inventory::getAll(); foreach ($inventory as $item) { $item_name = $item->getItem(); if ($item_name == $search_item) { $found_item = $item; } } return $found_item; }
static function find($search_id) { $found_inventory = null; $inventory_array = Inventory::getAll(); foreach ($inventory_array as $inventory_item) { $inventory_id = $inventory_item->getId(); if ($inventory_id == $search_id) { $found_inventory = $inventory_item; } } return $found_inventory; }
function test_deleteAll() { //Arrange $item = "Antique Toothpick Holders"; $item2 = "Ornamental Mouse Traps"; $test_Inventory = new Inventory($item); $test_Inventory->save(); $test_Inventory2 = new Inventory($item2); $test_Inventory2->save(); //Act Inventory::deleteAll(); //Assert $result = Inventory::getAll(); $this->assertEquals([], $result); }
function test_deleteAll() { //Arrange $description = "Blue candy"; $description2 = "Light blue candy"; $test_Inventory = new Inventory($description); $test_Inventory->save(); $test_Inventory2 = new Inventory($description2); $test_Inventory2->save(); //Act Inventory::deleteAll(); //Assert $result = Inventory::getAll(); $this->assertEquals([], $result); }
function test_deleteAll() { //Arrange $item = 'action figure'; $item2 = 'stuffed animal'; $test_Inventory = new Inventory($item); $test_Inventory->save(); $test_Inventory2 = new Inventory($item2); $test_Inventory2->save(); //Act Inventory::deleteAll(); $result = Inventory::getAll(); //Assert $this->assertEquals([], $result); }
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Inventory.php"; $app = new Silex\Application(); $server = 'mysql:host=localhost;dbname=inventory'; $username = '******'; $password = '******'; $DB = new PDO($server, $username, $password); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig', array('inventory' => Inventory::getAll())); }); $app->post("/create", function () use($app) { $inventory = new Inventory($_POST['item']); $inventory->save(); return $app['twig']->render('index.html.twig', array('inventory' => Inventory::getAll())); }); $app->post("/delete", function () use($app) { Inventory::deleteAll(); return $app['twig']->render('index.html.twig'); }); $app->get("/search", function () use($app) { $search = Inventory::find($_GET['search']); return $app['twig']->render('search.html.twig', array('search' => $search, 'search_term' => $_GET['search'])); }); return $app;
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Inventory.php"; $app = new Silex\Application(); $server = 'mysql:host=localhost;dbname=inventory'; $username = '******'; $password = '******'; $DB = new PDO($server, $username, $password); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig', array('candies' => Inventory::getAll())); }); $app->get("/candies", function () use($app) { return $app['twig']->render('candies.html.twig', array('candies' => Inventory::getAll())); }); $app->post("/candies", function () use($app) { $candy = new Inventory($_POST['name']); $candy->save(); return $app['twig']->render('candies.html.twig', array('candies' => Inventory::getAll())); }); $app->post("/delete_candy", function () use($app) { Inventory::deleteAll(); return $app['twig']->render('index.html.twig'); }); $app->get("/found_candy", function () use($app) { return $app['twig']->render('found_candy.html.twig', array('candies' => Inventory::find($_GET['search']))); }); return $app;