예제 #1
0
<?php

namespace Cider\Spec;

/* @imports*/
use function Cider\import;
use function Cider\expect;
import('Cider\\Common\\Store');
describe('Cider\\Common\\Store', function () {
    $helloWorldDict = ['en' => 'Hello World', 'se' => 'Hejsan Världen', 'jp' => 'こんにちは世界', 'de' => 'Hallo Welt', 'es' => 'Hola mundo', 'nl' => 'Hello wereld', 'ru' => 'Здравствулте мир'];
    $gothamVillainsDict = ['jk' => 'The Joker', 'hq' => 'Harley Quinn', 'en' => 'Edward Nigma'];
    $store = new \Cider\Common\Store($helloWorldDict);
    beforeEach(function () use($store, $helloWorldDict) {
        $store->data = $helloWorldDict;
    });
    it('returns data store with Store::$data getter', function () use($store, $helloWorldDict) {
        return expect($store->data)->toEqual($helloWorldDict);
    });
    it('replaces data store with Store::$data setter', function () use($store, $gothamVillainsDict, $helloWorldDict) {
        $store->data = $gothamVillainsDict;
        return expect($store->data)->notToEqual($helloWorldDict);
    });
    it('returns size of data store with Store::$size', function () use($store, $helloWorldDict) {
        $helloWorldDictSize = count($helloWorldDict);
        return expect($store->size)->toEqual($helloWorldDictSize);
    });
    it('returns only keys from data store with Store::$keys', function () use($store, $helloWorldDict) {
        $helloWorldDictKeys = array_keys($helloWorldDict);
        return expect($store->keys)->toEqual($helloWorldDictKeys);
    });
    it('returns only values from data store with Store::$values getter', function () use($store, $helloWorldDict) {
<?php

namespace Cider\Spec;

/* @imports*/
use function Cider\import;
use function Cider\expect;
import('Cider\\Delegation\\Hookable');
import('Cider\\Delegation\\RoutePath');
describe('Cider\\Delegation\\RoutePath', function () {
    $routeHandler = function () {
        return 'Hello World';
    };
    $route = new \Cider\Delegation\RoutePath('/greet', $routeHandler);
    beforeEach(function () use($route) {
        $route->removeMiddlewares();
        $route->removeBeforeAndAfterCallbacks();
    });
    it('expects defined pattern to be /greet', function () use($route) {
        return expect($route->pattern())->toEqual('/greet');
    });
    it('expects pattern to match URI /greet', function () use($route) {
        return expect($route->matches('/greet'))->toBeTrue();
    });
    it('has no middlewares attached', function () use($route) {
        $numberOfMiddlewares = count($route->getMiddlewares());
        return expect($numberOfMiddlewares)->toEqual(0);
    });
    it('can attach at least one middleware', function () use($route) {
        $initialMiddlewareCount = count($route->getMiddlewares());
        $route->middleware(function ($request, $response) {