/** * Test the getter/setter methods for properties */ public function testGetSetProperty() { $user = new User([]); $key = 'foo'; $value = 'testing123'; $user->addProperty($key, $value); $this->assertEquals($value, $user->getProperty($key)); }
public function evaluate(User $subject, Policy $policy) { $pass = true; foreach ($policy->getChecks() as $type => $value) { $propertyValue = $subject->getProperty($type); $valueType = gettype($propertyValue); // Ensure all of the things in our policy are true foreach ($value as $test) { $typeNs = __NAMESPACE__ . '\\Test\\Test' . ucwords(strtolower($valueType)); if (class_exists($typeNs)) { $testInstance = new $typeNs($test); if ($testInstance->evaluate($propertyValue) === false) { return false; } } else { throw new \InvalidArgumentException('Test type "' . $valueType . '" does not exist.'); } } } return $pass; }
<?php /************************************************************************************************** portfolio.php This is the view page for a user's portfolio. ***************************************************************************************************/ $user = new User($_SESSION['user_id']); // instantiate a new user $record = $user->getPortfolio(); // get SQL result set of user's portfolio/ $record is a multi-dimensional array // each sub-array has data for each stock owned by the user. ?> <header class="user cf"> <h1>Portfolio - <?php echo $user->getProperty('firstName') . " " . $user->getProperty('lastName') . " (" . $user->getProperty('email') . ")"; ?> </h1> <nav> <ul> <li><a href="user">Account</a></li> <li><a href="logout">Log Out</a></li> </ul> </nav> </header> <?php // Array output: ( [symbol_id] => AAPL [shares] => 11 [total_value] => 1174.14 ) ?> <table id="portfolio-table"> <tr>
$sell_stock_msg = "Sell Error: <br/> Quantity must be a number greater than zero..."; } } } } else { if (isset($_POST['submit-sell']) and (empty($_POST['symbol-sell']) or empty($_POST['qty-sell']))) { $sell_stock_msg = "Sell Error: <br/> One or more fields were blank. Please try again."; // Set a purchase error message } } ?> <!-- HTML CODE for user account main page --> <header class="user cf"> <h1>Welcome! <?php echo $user->getProperty('firstName') . " " . $user->getProperty('lastName') . " (" . $user->getProperty('email') . ")"; ?> </h1> <nav> <ul> <li><a href="portfolio">Check Portfolio</a></li> <li><a href="logout">Log Out</a></li> </ul> </nav> </header> <section id="user-details"> <div id="user-header"> <h2>Current Balance: <?php echo "\$" . number_format($user->getProperty('balance'), 2, '.', ','); ?> </h2>
public function testGetAttribute_Undefined() { $this->assertThat($this->object->getProperty('undefined', 'default value'), $this->equalTo('default value')); }