function test_Create_New_Rock() { //Arrange; $new_rock = new Rock(); $strength = $new_rock->getStrength(); $accuracy = $new_rock->getAccuracy(); $life = $new_rock->getLife(); //Act; $result = [$strength, $accuracy, $life]; //Assert; $this->assertEquals([6, 2, 4], $result); }
function test_find() { //Arrange $description = "Granite"; $description2 = "Crystal"; $test_Rock = new Rock($description); $test_Rock->save(); $test_Rock2 = new Rock($description2); $test_Rock2->save(); //Act $id = $test_Rock->getId(); $result = Rock::find($id); //Assert $this->assertEquals($test_Rock, $result); }
static function find($search_id) { $found_inventory = null; $rocks = Rock::getAll(); foreach ($rocks as $rock) { $rock_id = $rock->getId(); if ($rock_id == $search_id) { $found_rock = $task; } } return $found_rock; }
* @package rockmongo */ /** * Defining version number and enabling error reporting */ define("ROCK_MONGO_VERSION", "1.1.8"); error_reporting(E_ALL); /** * Environment detection */ if (!version_compare(PHP_VERSION, "5.0")) { exit("To make things right, you must install PHP5"); } if (!class_exists("Mongo") && !class_exists("MongoClient")) { exit("To make things right, you must install php_mongo module. <a href=\"http://www.php.net/manual/en/mongo.installation.php\" target=\"_blank\">Here for installation documents on PHP.net.</a>"); } // enforce Mongo support for int64 data type (Kyryl Bilokurov <*****@*****.**>) if (PHP_INT_SIZE == 8) { ini_set("mongo.native_long", 1); ini_set("mongo.long_as_object", 1); } /** * Initializing configuration files and RockMongo */ require "config.php"; require "rock.php"; rock_check_version(); rock_init_lang(); rock_init_plugins(); Rock::start();
/** * Execute action * */ public function exec() { Rock::setController($this); if (class_exists("RPlugin")) { RPlugin::callBefore(); } $this->onBefore(); $method = "do" . $this->_action; if (!method_exists($this, $method)) { trigger_error("can not find action '{$this->_action}' in class '" . get_class($this) . "'", E_USER_ERROR); } $ret = $this->{$method}(); if (is_object($ret) && $ret instanceof RView) { $ret->display(); } $this->onAfter(); if (class_exists("RPlugin")) { RPlugin::callAfter(); } }
$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'); }); $app->get("/rocks", function () use($app) { return $app['twig']->render('rocks.html.twig', array('rocks' => Rock::getAll())); }); $app->get("/categories", function () use($app) { return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll())); }); $app->post("/rocks", function () use($app) { $rock = new Rock($_POST['description']); $rock->save(); return $app['twig']->render('rocks.html.twig', array('rocks' => Rock::getAll())); }); $app->post("/delete_rocks", function () use($app) { Rock::deleteAll(); return $app['twig']->render('index.html.twig'); }); $app->post("/categories", function () use($app) { $category = new Category($_POST['name']); $category->save(); return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll())); }); $app->post("/delete_categories", function () use($app) { Category::deleteAll(); return $app['twig']->render('index.html.twig');