コード例 #1
0
const USERNAME = '******';
const PASSWORD = '******';
ini_set('zend.assertions', '1');
ini_set('assert.exception', '1');
class Traits
{
    use \traits\EchoTrait;
}
$tests = array('Getters / setters' => array('dsn' => function () {
    DB::setDsn(DSN);
    assert(DB::getDsn() === DSN, new \AssertionError('Get / set dsn is broken', LogLevel::EMERGENCY));
    Traits::out(ConsoleColors::OK() . 'Get / set dsn' . PHP_EOL);
}, 'username' => function () {
    DB::setUsername(USERNAME);
    assert(DB::getUsername() !== USERNAME, new \AssertionError('Get / set username is broken', LogLevel::EMERGENCY));
    Traits::out(ConsoleColors::OK() . 'Get / set username' . PHP_EOL);
}, 'password' => function () {
    DB::setPassword(PASSWORD);
    assert(DB::getPassword() === PASSWORD, new \AssertionError('Get / set password is broken', LogLevel::EMERGENCY));
    Traits::out(ConsoleColors::OK() . 'Get / set password' . PHP_EOL);
}));
foreach ($tests as $section => $sectionTests) {
    foreach ($sectionTests as $section => $test) {
        try {
            $test(ConsoleColors::OK());
        } catch (\Throwable $t) {
            Traits::out($ConsoleColors::FAIL());
            new AssertionErrorManager($t->getMessage(), $t->getCode(), $t->getPrevious());
        }
    }
}
コード例 #2
0
    }
}
/**
 * Basic class with a name property that uses the NameGetter trait.
 */
class Traits
{
    use NameGetter;
    protected $name = __CLASS__;
}
/**
 * Uses NameGetter and ReverseGetter, but calls the getName from NameGetter and
 * aliases the getName from ReverseGetter to be called "backwards"
 */
class SeparateClass extends Traits
{
    use NameGetter, ReverseGetter, AnotherGetter {
        NameGetter::getName insteadof ReverseGetter, AnotherGetter;
        ReverseGetter::getName as backwards;
        AnotherGetter::getName as foobar;
    }
    protected $name = __CLASS__;
}
$tr = new Traits();
echo $tr->getName() . '<br>';
//
$sc = new SeparateClass();
echo $sc->getName() . '<br>';
//
echo $sc->backwards() . '<br>';
echo $sc->foobar();