示例#1
0
{
    expects(withKeys('first_name', 'last_name'), $data);
    return $data['first_name'] . ' ' . $data['last_name'];
}
try {
    getUserFullName(array('hello' => 'world'));
} catch (\InvalidArgumentException $e) {
    echo $e->getMessage() . "\n";
}
// 7. Specify object with methods
function pet($duck)
{
    expects(withMethod('quack'), $duck);
}
try {
    pet(new Integer());
} catch (\InvalidArgumentException $e) {
    echo $e->getMessage() . "\n";
}
// 8. Specify with custom checking function
function calculateAge($yearOfBirth)
{
    expectsToBe($yearOfBirth, 'to be an integer > 1900 and <= current year', function ($arg) {
        return is_int($arg) && $arg > 1900 && $arg <= (int) date('Y');
    });
    return (int) date('Y') - $yearOfBirth;
}
try {
    $age = calculateAge(1800);
} catch (\InvalidArgumentException $e) {
    echo $e->getMessage() . "\n";
示例#2
0
<div id="jsvars" data-error-general="<?php 
pet('JS_GENERAL_ERROR');
?>
" data-error-down="<?php 
pet('JS_SERVER_DOWN');
?>
" data-domain="<?php 
p(DOMAIN);
?>
" data-base="<?php 
p(WEB_ROOT);
?>
"></div>