Author: Matthew J. Sahagian [mjs] (gent@dotink.org)
Inheritance: extends Quip
コード例 #1
0
ファイル: Test.php プロジェクト: dotink/parody
<?php

namespace Dotink\Lab;

use Dotink\Parody\Mime;
return ['setup' => function ($data, $shared) {
    needs('src/Quip.php');
    needs('src/Mime.php');
}, 'tests' => ['Test' => function ($data, $shared) {
    $static = Mime::define('Bar');
    $instance = Mime::create('Bar')->onCall('foo')->give('bar');
    $static->onCall('foo')->give('bar');
    assert(\Bar::foo())->equals('bar');
    assert($instance()->foo())->equals('bar');
    $instance = $static->create()->onCall('foo')->give('bar');
    assert($instance()->foo())->equals('bar');
    $static->onNew('test', function ($mime) {
        $mime->onCall('foo')->give('foo');
    });
    $instance = new \Bar('test');
    assert($instance->foo())->equals('foo');
}]];
コード例 #2
0
ファイル: 03 Manager.php プロジェクト: imarc/auth
<?php

namespace Dotink\Lab;

use iMarc\Auth\ACL;
use iMarc\Auth\Manager;
use Dotink\Parody\Mime;
return ['setup' => function ($data, $shared) {
    Mime::define('User')->implementing('iMarc\\Auth\\EntityInterface');
    needs($data['root'] . '/src/ACLInterface.php');
    needs($data['root'] . '/src/ACL.php');
    needs($data['root'] . '/src/Manager.php');
    $shared->user = Mime::create('User')->onCall('getRoles')->give(['Editor', 'User'])->onCall('getPermissions')->give(['user' => ['read']])->resolve();
    $shared->manager = new Manager($shared->user);
    $shared->acl = new ACL();
    $shared->acl->allow('Admin', 'User', ['create', 'read', 'update', 'delete', 'permit']);
    $shared->acl->allow('Admin', 'Article', ['create', 'read', 'UPDATE', 'delete', 'permit']);
    $shared->acl->allow('editor', 'Article', ['create', 'read', 'update', 'delete']);
    $shared->acl->allow('user', 'Article', ['read']);
    $shared->manager->add($shared->acl);
}, 'tests' => ['Can' => function ($data, $shared) {
    assert('iMarc\\Auth\\Manager::can')->using($shared->manager)->with('create', 'user')->equals(FALSE)->with('read', 'article')->equals(TRUE)->with('read', 'user')->equals(TRUE);
    $shared->manager->override('User', 'create', function ($auth, $user) {
        return TRUE;
    });
    assert('iMarc\\Auth\\Manager::can')->using($shared->manager)->with('create', 'user')->equals(TRUE);
}, 'Has' => function ($data, $shared) {
    assert('iMarc\\Auth\\Manager::has')->using($shared->manager)->with('create', 'user')->equals(FALSE)->with('read', 'article')->equals(TRUE);
}, 'Is' => function ($data, $shared) {
    assert('iMarc\\Auth\\Manager::is')->using($shared->manager)->with('Admin')->equals(FALSE)->with('EDITOR')->equals(TRUE);
}]];