Exemple #1
0
<?php

namespace Kahlan\Spec\Suite;

use Exception;
use RuntimeException;
use stdClass;
use DateTime;
use Kahlan\Specification;
use Kahlan\Matcher;
use Kahlan\Expectation;
use Kahlan\Plugin\Stub;
describe("Expectation", function () {
    beforeEach(function () {
        $this->matchers = Matcher::get();
    });
    afterEach(function () {
        Matcher::reset();
        foreach ($this->matchers as $name => $value) {
            foreach ($value as $for => $class) {
                Matcher::register($name, $class, $for);
            }
        }
    });
    describe("->__call()", function () {
        it("throws an exception when using an undefined matcher name", function () {
            $closure = function () {
                $result = Expectation::expect(true)->toHelloWorld(true);
            };
            expect($closure)->toThrow(new Exception("Unexisting matcher attached to `'toHelloWorld'`."));
        });
     });
 });
 describe('->getTemplate()', function () {
     context('when expected message has been set', function () {
         beforeEach(function () {
             $this->matcher->setExpectedMessage('message');
         });
         it('should return the set message template', function () {
             $template = new ArrayTemplate([]);
             $this->matcher->setMessageTemplate($template);
             expect($this->matcher->getTemplate())->to->equal($template);
         });
     });
     context('when a custom template has been set', function () {
         beforeEach(function () {
             $this->template = new ArrayTemplate([]);
             $this->matcher->setTemplate($this->template);
         });
         it('should return the set template', function () {
             expect($this->matcher->getTemplate())->to->equal($this->template);
         });
     });
 });
 describe('->getArguments()', function () {
     it('should fetch callable arguments', function () {
         $args = [1, 2, 3];
         $this->matcher->setArguments($args);
         expect($this->matcher->getArguments())->to->equal($args);
     });
 });
 describe('->getExpectedMessage()', function () {
     it('should fetch expected message', function () {
Exemple #3
0
<?php

use NetRivet\Container\Container;
use NetRivet\WordPress\Route;
use Rad\DependencyInterface;
describe('Route', function () {
    beforeEach(function () {
        $this->container = new Container();
        $this->container->bind('Rad\\DependencyInterface', 'Rad\\DependencyImpl');
    });
    it('should be able to resolve dependencies of a responder', function () {
        $injected = null;
        $route = new Route('slug', function (DependencyInterface $rad) use(&$injected) {
            $injected = $rad;
        });
        $route->bind($this->container);
        $route->resolve();
        expect($injected)->to->be->instanceof('Rad\\DependencyImpl');
    });
    it('should be able to resolve dependencies of a class responder', function () {
        $route = new Route('slug', 'Rad\\Responder');
        $route->bind($this->container);
        $dep = $route->resolve();
        expect($dep)->to->be->an->instanceof('Rad\\DependencyImpl');
    });
    it('should be able to resolve dependencies registered as a factory', function () {
        $container = new Container();
        $container->bind('Rad\\DependencyInterface', function () {
            return new \Rad\DependencyImpl();
        });
        $route = new Route('slug', 'Rad\\Responder');
Exemple #4
0
     });
     describe("with provided hash", function () {
         it("returns `false` for registered stub", function () {
             expect(Stub::registered('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo'))->toBe(false);
         });
         it("returns `true` for registered stub", function () {
             Stub::on('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->method('foo', function () {
             });
             expect(Stub::registered('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo'))->toBe(true);
         });
     });
 });
 describe("::reset()", function () {
     beforeEach(function () {
         Stub::on('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo')->method('foo', function () {
         });
         Stub::on('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Bar')->method('bar', function () {
         });
     });
     it("clears all stubs", function () {
         Stub::reset();
         expect(Stub::registered())->toBe([]);
     });
     it("clears one stub", function () {
         Stub::reset('Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Foo');
         expect(Stub::registered())->toBe(['Kahlan\\Spec\\Fixture\\Plugin\\Pointcut\\Bar']);
     });
 });
 describe("::_generateAbstractMethods()", function () {
     it("throws an exception when called with a non-existing class", function () {
         expect(function () {
             $stub = Stub::classname(['extends' => 'Kahlan\\Plugin\\Stub', 'methods' => ['::generateAbstractMethods']]);
<?php

use Calculator\Operator\Operator;
use spec\mock\MockOperator;
describe('Operator', function () {
    beforeEach(function () {
        $this->obj = new MockOperator();
    });
    describe('getOperator', function () {
        it('gets operator', function () {
            expect($this->obj->getOperator())->toEqual('$');
        });
    });
    describe('getPrecedence', function () {
        it('gets precedence', function () {
            expect($this->obj->getPrecedence())->toEqual(Operator::PRECEDENCE_LOW);
        });
    });
    describe('execute', function () {
        it('executes operation', function () {
            expect($this->obj->execute(1, 2))->toEqual(1);
        });
    });
    describe('getType', function () {
        it('gets type', function () {
            expect($this->obj->getType())->toEqual('operator');
        });
    });
    describe('getStringOrder', function () {
        it('gets string order', function () {
            expect($this->obj->getStringOrder())->toBe(1);
<?php

/**
 * Created by PhpStorm.
 * User: cs3620
 * Date: 11/17/15
 * Time: 6:46 PM
 */
use Notes\Domain\Entity\UserFactory;
//use Notes\Domain\ValueObject\StringLiteral;
use Notes\Persistence\Entity\SQLUserRepository;
use Notes\Domain\Entity\User;
use Notes\Domain\ValueObject\Uuid;
describe('Notes\\Persistence\\Entity\\SQLUserRepository', function () {
    beforeEach(function () {
        $this->repo = new SQLUserRepository();
        $this->userFactory = new UserFactory();
    });
    describe('->__construct()', function () {
        it('should construct an SQLUserRepository object', function () {
            expect($this->repo)->to->be->instanceof('Notes\\Persistence\\Entity\\SQLUserRepository');
        });
    });
    describe('->add()', function () {
        it('should a 1 user to the repository', function () {
            $this->repo->add($this->userFactory->create());
            expect($this->repo->count())->to->equal(1);
        });
    });
    describe('->getByUsername()', function () {
        it('should return a single User object', function () {
            /** @var \Notes\Domain\Entity\User $user */
Exemple #7
0
 describe("->offsetSet/offsetGet()", function () {
     it("allows array access", function () {
         $collection = new Collection();
         $collection[] = 'foo';
         expect($collection[0])->toBe('foo');
         expect($collection)->toHaveLength(1);
     });
     it("sets at a specific key", function () {
         $collection = new Collection();
         $collection['mykey'] = 'foo';
         expect($collection['mykey'])->toBe('foo');
         expect($collection)->toHaveLength(1);
     });
     context("when a model is defined", function () {
         beforeEach(function () {
             $this->model = Stub::classname(['extends' => Model::class]);
         });
         it("autoboxes setted data", function () {
             $collection = new Collection(['model' => $this->model]);
             $collection[] = ['id' => 1, 'title' => 'first record', 'enabled' => 1, 'created' => time()];
             $entity = $collection[0];
             expect($entity)->toBeAnInstanceOf($this->model);
             expect($entity->parent())->toBe($collection);
             expect($entity->rootPath())->toBe(null);
         });
     });
 });
 describe("->offsetUnset()", function () {
     it("unsets items", function () {
         $collection = new Collection(['data' => [5, 3, 4, 1, 2]]);
         unset($collection[1]);
Exemple #8
0
 });
 context("with a default column value", function () {
     it("sets up the default value", function () {
         $data = ['name' => 'fieldname', 'type' => 'integer', 'default' => 1];
         $result = $this->dialect->column($data);
         expect($result)->toBe('"fieldname" integer DEFAULT 1');
     });
     context("with a casting handler defined", function () {
         beforeEach(function () {
             $dialect = $this->dialect;
             $dialect->caster(function ($value, $states) use($dialect) {
                 if (!isset($states['field']['type'])) {
                     return $value;
                 }
                 switch ($states['field']['type']) {
                     case 'integer':
                         return (int) $value;
                         break;
                     default:
                         return (string) $dialect->quote($value);
                         break;
                 }
             });
         });
         it("casts the default value to an integer", function () {
             $data = ['name' => 'fieldname', 'type' => 'integer', 'default' => '1'];
             $result = $this->dialect->column($data);
             expect($result)->toBe('"fieldname" integer DEFAULT 1');
         });
         it("casts the default value to an string", function () {
             $data = ['name' => 'fieldname', 'type' => 'string', 'length' => 64, 'default' => 1];
             $result = $this->dialect->column($data);
Exemple #9
0
<?php

use Peridot\Leo\Interfaces\Assert;
describe('assert', function () {
    beforeEach(function () {
        $this->assert = new Assert();
    });
    it('should throw a BadMethodCallException when an unknown method is called', function () {
        $this->assert->throws(function () {
            $this->assert->nope();
        }, 'BadMethodCallException', 'Call to undefined method nope');
    });
    describe('->equal()', function () {
        it('should match to loosely equal values', function () {
            $this->assert->equal(3, '3');
        });
        it('should throw exception when values are not loosely equal', function () {
            $this->assert->throws(function () {
                $this->assert->equal(4, 3);
            }, 'Exception');
        });
        it('should throw exception with a user supplied message', function () {
            $this->assert->throws(function () {
                $this->assert->equal(4, 3, 'not equal');
            }, 'Exception', 'not equal');
        });
        it('should throw a formatted exception message', function () {
            $this->assert->throws(function () {
                $this->assert->equal(4, 3);
            }, 'Exception', 'Expected 3, got 4');
        });
            $actual = $this->srvrMgr->servers();
            expect($actual)->to->be->instanceof('Emris\\Cli\\Scaler\\Domain\\ServerCollection');
            expect($actual->count())->to->equal(3);
        });
    });
    describe('->add($servers)', function () {
        beforeEach(function () {
            $this->srvrBldr = new ServerBuilder();
            $this->adapterMock->addServer($this->srvrBldr->build())->willReturn(true);
        });
        it('should return true', function () {
            $actual = $this->srvrMgr->add(new ServerCollection());
            expect($actual)->to->be->false();
        });
    });
    describe('->remove($servers)', function () {
        beforeEach(function () {
            $servers = new ServerCollection();
            $servers->add($this->srvrBldr->build());
            $servers->add($this->srvrBldr->build());
            $this->srvrBldr = new ServerBuilder();
            $this->adapterMock->servers()->willReturn(new ServerCollection());
            $this->adapterMock->delServer($this->srvrBldr->build())->willReturn(true);
        });
        it('should return ServerCollection of count 2', function () {
            /** @var \Emris\Cli\Scaler\Domain\ServerCollection $actual */
            $actual = $this->srvrMgr->remove(2);
            expect($actual->count())->to->equal(0);
        });
    });
});
Exemple #11
0
     $collector->stop();
     $metrics = $collector->metrics();
     $actual = $metrics->get('Kahlan\\Spec\\Fixture\\Reporter\\Coverage\\ImplementsCoverage')->data();
     $files = $actual['files'];
     unset($actual['files']);
     expect($actual)->toBe(['loc' => 6, 'nlloc' => 5, 'lloc' => 1, 'cloc' => 1, 'coverage' => 1, 'methods' => 1, 'cmethods' => 1, 'percent' => 100]);
     $path = realpath('spec/Fixture/Reporter/Coverage/ImplementsCoverage.php');
     expect(isset($files[$path]))->toBe(true);
     expect($metrics->get('Kahlan\\Spec\\Fixture\\Reporter\\Coverage\\ImplementsCoverageInterface'))->toBe(null);
     expect($collector->export())->toBe([str_replace('/', DS, 'spec/Fixture/Reporter/Coverage/ImplementsCoverage.php') => [7 => 1]]);
 });
 describe("->children()", function () {
     beforeEach(function () {
         $code = new ExtraEmptyLine();
         $this->collector->start();
         $code->shallNotPass();
         $this->collector->stop();
         $this->metrics = $this->collector->metrics();
     });
     it("returns root's children", function () {
         $children = $this->metrics->children();
         expect(is_array($children))->toBe(true);
         expect(isset($children['Kahlan\\']))->toBe(true);
     });
     it("returns specified child", function () {
         $children = $this->metrics->children('Kahlan\\');
         expect(is_array($children))->toBe(true);
         expect(isset($children['Spec\\']))->toBe(true);
         $children = $this->metrics->children('Kahlan\\Spec\\');
         expect(is_array($children))->toBe(true);
         expect(isset($children['Fixture\\']))->toBe(true);
         $worker->run('some path');
         expect($this->pool->isWorking())->to->be->true;
     });
     it('should return true if there are not running workers and some pending tests', function () {
         $this->pool->setPending(['spec.php']);
         expect($this->pool->isWorking())->to->be->true;
     });
 });
 context('when a message end event is emitted on the message broker', function () {
     beforeEach(function () {
         $this->worker = new Worker('bin', $this->emitter, new TmpfileOpen());
         $this->pool->attach($this->worker);
         $message = new Message($this->worker->getOutputStream());
         $this->broker->addMessage($message);
         $theWorker = null;
         $this->emitter->on('peridot.concurrency.worker.completed', function ($w) use(&$theWorker) {
             $theWorker = $w;
         });
         $this->worker->run('some path');
         $message->emit('end', [$message]);
         $this->completed = $theWorker;
     });
     it('should emit a peridot.concurrency.worker.completed event for the worker that has the message resource', function () {
         expect($this->completed)->to->equal($this->worker);
     });
     it('should set the total job time elapsed', function () {
         $info = $this->completed->getJobInfo();
         expect($info->end)->to->not->be->null;
     });
 });
 context('when peridot.concurrency.worker.completed event is emitted', function () {
<?php

namespace Lead\Resource\Spec\Suite\Router;

use stdClass;
use Lead\Router\Router;
use Lead\Resource\Router\ResourceStrategy;
describe("ResourceStrategy", function () {
    beforeEach(function () {
        $this->router = new Router();
        $this->router->strategy('resource', new ResourceStrategy());
    });
    it("dispatches resources urls", function () {
        $r = $this->router;
        $r->resource('RoutingTest', ['namespace' => 'Lead\\Resource\\Spec\\Mock']);
        $response = new stdClass();
        $route = $r->route('routing-test', 'GET');
        $route->dispatch($response);
        expect($route->request->params())->toBe(['relation' => null, 'rid' => null, 'resource' => 'routing-test', 'id' => null, 'action' => null]);
        expect($route->request->method())->toBe('GET');
        expect($route->response)->toBe($response);
        $route = $r->route('routing-test/123', 'GET');
        $route = $route->dispatch($response);
        expect($route->request->params())->toBe(['relation' => null, 'rid' => null, 'resource' => 'routing-test', 'id' => '123', 'action' => null]);
        expect($route->request->method())->toBe('GET');
        expect($route->response)->toBe($response);
        $route = $r->route('routing-test/:create', 'GET');
        $route = $route->dispatch($response);
        expect($route->request->params())->toBe(['relation' => null, 'rid' => null, 'resource' => 'routing-test', 'id' => null, 'action' => 'create']);
        expect($route->request->method())->toBe('GET');
        expect($route->response)->toBe($response);
Exemple #14
0
     it('should walk a hierarchy', function () {
         $childSuite = new Suite('child suite');
         $grandChildTest = new Test(' grand child');
         $childSuite->addChildNode($grandChildTest);
         $this->node->addChildNode($childSuite);
         $joined = '';
         $this->node->walk(function (TestInterface $test) use(&$joined) {
             $joined .= $test->getDescription();
         });
         assert($joined === 'child suite grand child');
     });
 });
 describe('->filter()', function () {
     beforeEach(function () {
         $this->fast = new Test('should run @fast');
         $this->slow1 = new Test('should run @slow');
         $this->slow2 = new Test('should also be @slow');
         $this->node->setChildNodes([$this->fast, $this->slow1, $this->slow2]);
     });
     it('should return a filtered node based on the given predicate', function () {
         $filtered = $this->node->filter(function (TestInterface $test) {
             return (bool) preg_match('/@slow/', $test->getDescription());
         });
         $children = $filtered->getChildNodes();
         assert(count($children) === 2, 'should have filtered out 1 child');
         assert($children[0] === $this->slow1);
         assert($children[1] === $this->slow2);
     });
     it('should allow inversion of the predicate condition', function () {
         $filtered = $this->node->filter(function (TestInterface $test) {
             return (bool) preg_match('/@slow/', $test->getDescription());
         }, true);
             $sample2 = $this->dogmatist->sample('unlimited');
             expect($sample1)->toBeA('object');
             expect($sample2)->toBeA('object');
             expect($sample1)->not->toBe($sample2);
         });
         it("should create samples using the samples() method", function () {
             $samples = $this->dogmatist->samples('unlimited', 2);
             expect($samples)->toBeA('array');
             expect($samples)->toHaveLength(2);
             expect($samples[0])->not->toBe($samples[1]);
         });
     });
 });
 describe("Sampling from non-saved builders", function () {
     beforeEach(function () {
         $this->builder = $this->dogmatist->create('object')->fake('num', 'randomNumber');
     });
     it("should create a sample from a non-saved builder", function () {
         $sample = $this->dogmatist->sample($this->builder);
         expect($sample)->toBeAnInstanceOf('stdClass');
         expect($sample->num)->toBeA('integer');
     });
     it("should create multiple samples from a non-saved builder", function () {
         $samples = $this->dogmatist->samples($this->builder, 2);
         expect($samples)->toBeA('array');
         expect($samples)->toHaveLength(2);
         expect($samples[0])->toBeAnInstanceOf('stdClass');
         expect($samples[1])->toBeAnInstanceOf('stdClass');
     });
     it("should create a sample from a non-saved builder using the fresh method", function () {
         $sample = $this->dogmatist->freshSample($this->builder);
Exemple #16
0
         expect($backtrace)->toBeA('string');
         $backtrace = explode("\n", $backtrace);
         expect(empty($backtrace))->toBe(false);
     });
     it("returns a trace from eval'd code", function () {
         $trace = debug_backtrace();
         $trace[1]['file'] = "eval()'d code";
         $backtrace = Debugger::trace(['trace' => $trace]);
         expect($backtrace)->toBeA('string');
         $trace = current(explode("\n", $backtrace));
         expect($trace)->toMatch('~kahlan[/|\\\\]src[/|\\\\]Specification.php~');
     });
     describe("::_line()", function () {
         beforeEach(function () {
             $this->debugger = Stub::classname(['extends' => 'Kahlan\\Analysis\\Debugger', 'methods' => ['::line']]);
             Stub::on($this->debugger)->method('::line', function ($trace) {
                 return static::_line($trace);
             });
         });
         it("returns `null` with non-existing files", function () {
             $debugger = $this->debugger;
             $trace = ['file' => DS . 'some' . DS . 'none' . DS . 'existant' . DS . 'path' . DS . 'file.php', 'line' => null];
             expect($debugger::line($trace))->toBe(null);
         });
         it("returns `null` when a line can't be found", function () {
             $debugger = $this->debugger;
             $nbline = count(file('spec' . DS . 'Suite' . DS . 'Analysis' . DS . 'DebuggerSpec.php')) + 1;
             $trace = ['file' => 'spec' . DS . 'Suite' . DS . 'Analysis' . DS . 'DebuggerSpec.php', 'line' => $nbline + 1];
             expect($debugger::line($trace))->toBe(null);
         });
     });
 });
Exemple #17
0
     });
     it("throws an exception on undefined variables", function () {
         $closure = function () {
             $a = $this->unexisting;
         };
         expect($closure)->toThrow(new Exception('Undefined variable `unexisting`.'));
     });
     it("throws properly message on expect() usage inside of describe()", function () {
         $closure = function () {
             $this->expect;
         };
         expect($closure)->toThrow(new Exception("You can't use expect() inside of describe()"));
     });
     context("when nested", function () {
         beforeEach(function () {
             $this->bar = 1;
         });
         it("can access variable from the parent scope", function () {
             expect($this->bar)->toBe(1);
         });
     });
 });
 describe("skipIf", function () {
     it("returns none if provided false/null", function () {
         expect(skipIf(false))->toBe(null);
     });
     $executed = 0;
     context("when used in a scope", function () use(&$executed) {
         before(function () {
             skipIf(true);
         });
<?php

use holyshared\fixture\container\FixtureContainer;
describe(FixtureContainer::class, function () {
    beforeEach(function () {
        $this->container = new FixtureContainer(['foo' => 'bar']);
    });
    describe('#get', function () {
        it('return content', function () {
            expect($this->container->get('foo'))->toEqual('bar');
        });
    });
    describe('#has', function () {
        context('when key not exists', function () {
            it('return false', function () {
                expect($this->container->has('bar'))->toBeFalse();
            });
        });
        context('when key exists', function () {
            it('return true', function () {
                expect($this->container->has('foo'))->toBeTrue();
            });
        });
    });
});
Exemple #19
0
<?php

namespace Kahlan\Spec\Suite\Filter;

use Kahlan\Plugin\Stub;
use Kahlan\Filter\Chain;
describe("Chain", function () {
    beforeEach(function () {
        $method = 'message';
        $filters = ['filter1' => function ($chain, $message) {
            $message = "My {$message}";
            return $chain->next($message);
        }, 'filter2' => function ($chain, $message) {
            return $message;
        }];
        $params = ['World!'];
        $this->chain = new Chain(compact('filters', 'method', 'params'));
    });
    describe("->params()", function () {
        it("gets the params", function () {
            expect($this->chain->params())->toBe(['World!']);
        });
    });
    describe("->method()", function () {
        it("gets the methods", function () {
            expect($this->chain->method())->toBe('message');
        });
    });
    describe("Iterator", function () {
        it("iterate throw the chain", function () {
            expect($this->chain->current())->toBeAnInstanceOf('Closure');
             $this->configuration->disableColors();
             $text = $this->reporter->color('color', 'hello world');
             assert($text == "hello world", "disabled colors should contain color sequences");
         });
     });
 });
 describe('->footer()', function () {
     beforeEach(function () {
         $this->configuration->disableColors();
         $exception = null;
         try {
             throw new Exception("ooops" . PHP_EOL . "nextline");
         } catch (Exception $e) {
             $exception = $e;
         }
         $this->exception = $exception;
         $this->emitter->emit('test.passed', [new Test('passing test', function () {
         })]);
         $this->emitter->emit('test.failed', [new Test('failing test', function () {
         }), $this->exception]);
         $this->emitter->emit('test.pending', [new Test('pending test', function () {
         })]);
         $this->footer = $this->reporter->footer();
         $this->contents = $this->output->fetch();
     });
     it('should output success text', function () {
         assert(strstr($this->contents, '1 passing') !== false, 'should contain passing text');
     });
     it('should output time', function () {
         $time = PHP_Timer::secondsToTimeString($this->reporter->getTime());
         assert(strstr($this->contents, $time) !== false, 'should contain time text');
     });
Exemple #21
0
<?php

namespace Kahlan\Spec\Suite;

use stdClass;
use Exception;
use Kahlan\Specification;
use Kahlan\Matcher;
use Kahlan\Plugin\Stub;
describe("Specification", function () {
    beforeEach(function () {
        $this->spec = new Specification(['closure' => function () {
        }]);
    });
    describe("->__construct()", function () {
        it("throws an exception with invalid closure", function () {
            $closure = function () {
                $this->spec = new Specification(['closure' => null]);
            };
            expect($closure)->toThrow(new Exception('Error, invalid closure.'));
        });
    });
    describe("->expect()", function () {
        it("returns the matcher instance", function () {
            $matcher = $this->spec->expect('actual');
            expect($matcher)->toBeAnInstanceOf('Kahlan\\Expectation');
        });
    });
    describe("->waitsFor()", function () {
        it("returns the matcher instance setted with the correct timeout", function () {
            $matcher = $this->spec->waitsFor(function () {
<?php

use CleanPhp\Invoicer\Domain\Entity\Customer;
use CleanPhp\Invoicer\Domain\Entity\Order;
use CleanPhp\Invoicer\Persistence\Hydrator\OrderHydrator;
use Zend\Stdlib\Hydrator\ClassMethods;
describe('Persistence\\Hydrator\\OrderHydrator', function () {
    beforeEach(function () {
        $this->repository = $this->getProphet()->prophesize('CleanPhp\\Invoicer\\Domain\\Repository\\CustomerRepositoryInterface');
        $this->hydrator = new OrderHydrator(new ClassMethods(), $this->repository->reveal());
    });
    describe('->hydrate()', function () {
        it('should perform basic hydration of attributes', function () {
            $data = ['id' => 100, 'order_number' => '20150101-019', 'description' => 'simple order', 'total' => 5000];
            $order = new Order();
            $this->hydrator->hydrate($data, $order);
            expect($order->getId())->to->equal(100);
            expect($order->getOrderNumber())->to->equal('20150101-019');
            expect($order->getDescription())->to->equal('simple order');
            expect($order->getTotal())->to->equal(5000);
        });
        it('should hydrate the embedded customer data', function () {
            $data = ['customer' => ['id' => 20]];
            $order = new Order();
            $this->repository->getById(20)->willReturn((new Customer())->setId(20));
            $this->hydrator->hydrate($data, $order);
            assert($data['customer']['id'] === $order->getCustomer()->getId(), 'id does not match');
        });
        it('should unset a null "customer"', function () {
            $data = ['customer' => null];
            $order = new Order();
Exemple #23
0
<?php

namespace Kahlan\Spec\Jit\Suite;

use Exception;
use Kahlan\Jit\TokenStream;
describe("TokenStream", function () {
    beforeEach(function () {
        $this->code = <<<EOD
<?php
class HelloWorld
{
    public function hello() {
        \$echo = function(\$msg) { echo \$msg };
        \$echo('Hello World');
    }
}
?>
EOD;
        $this->stream = new TokenStream(['source' => $this->code]);
        $this->len = count(token_get_all($this->code));
    });
    describe("->load", function () {
        it("wraps passed code with PHP tags when the `'wrap'` option is used", function () {
            $stream = new TokenStream(['source' => 'class HelloWorld {}', 'wrap' => true]);
            $actual = $stream->current();
            expect($actual)->toBe("class");
        });
    });
    describe("->current()", function () {
        it("gets the current token value", function () {
Exemple #24
0
<?php

use Mockery as m;
use Tusk\Expectation;
describe('Expectation', function () {
    afterEach(function () {
        m::close();
    });
    describe('__call()', function () {
        beforeEach(function () {
            $this->matcher = m::mock('Tusk\\Matcher', ['getMessageFormat' => 'failed']);
            $this->prettyPrinter = m::mock('Tusk\\PrettyPrinter');
            $this->expectation = new Expectation(12, ['toBe' => $this->matcher], $this->prettyPrinter);
        });
        it('should invoke a matcher object with the expectation value', function () {
            $this->matcher->shouldReceive('match')->with(12, [13, 14])->andReturn(true);
            $this->expectation->toBe(13, 14);
        });
        it('should throw an exception if the comparison returns false', function () {
            $this->matcher->shouldReceive('match')->with(12, [15, 16])->andReturn(false);
            $this->prettyPrinter->shouldReceive('format')->with('failed', 12, [15, 16], false)->andReturn('foo')->once();
            expect(function () {
                $this->expectation->toBe(15, 16);
            })->toThrow('Tusk\\ExpectationException', 'foo');
        });
        it('should reverse the above behaviour if matcher name is preceded by "not"', function () {
            $this->matcher->shouldReceive('match')->with(12, [13, 14])->andReturn(false);
            $this->expectation->notToBe(13, 14);
            $this->matcher->shouldReceive('match')->with(12, [15, 16])->andReturn(true);
            $this->prettyPrinter->shouldReceive('format')->with('failed', 12, [15, 16], true)->andReturn('bar')->once();
            expect(function () {
Exemple #25
0
<?php

namespace Kahlan\Spec\Suite\Jit\Patcher;

use Kahlan\Jit\Parser;
use Kahlan\Jit\Patcher\Rebase;
describe("Rebase", function () {
    beforeEach(function () {
        $this->path = 'spec/Fixture/Jit/Patcher/Rebase';
        $this->patcher = new Rebase();
    });
    describe("->process()", function () {
        it("patches class's methods", function () {
            $nodes = Parser::parse(file_get_contents($this->path . '/Rebase.php'));
            $expected = file_get_contents($this->path . '/RebaseProcessed.php');
            $actual = Parser::unparse($this->patcher->process($nodes, '/the/original/path/Rebase.php'));
            expect($actual)->toBe($expected);
        });
    });
    describe("->patchable()", function () {
        it("return `true`", function () {
            expect($this->patcher->patchable('SomeClass'))->toBe(true);
        });
    });
});
<?php

use Peridot\Leo\Matcher\LessThanMatcher;
describe('LessThanMatcher', function () {
    beforeEach(function () {
        $this->matcher = new LessThanMatcher(5);
    });
    it('should return true if actual value is less than expected', function () {
        $match = $this->matcher->match(4);
        expect($match->isMatch())->to->be->true;
    });
    it('should return false if actual value is greater than expected', function () {
        $match = $this->matcher->match(6);
        expect($match->isMatch())->to->be->false;
    });
    context('when negated', function () {
        it('should return false if actual value is below expected', function () {
            $match = $this->matcher->invert()->match(4);
            expect($match->isMatch())->to->be->false;
        });
    });
});
Exemple #27
0
         }));
         $parent->addTest($child);
         $child->addTest($grandchild);
         $runner = new Runner($parent, new Configuration(), new EventEmitter());
         $runner->run($this->result);
         assert('3 run, 1 failed' == $this->result->getSummary(), 'result summary should show 3/1');
     });
 });
 describe("->run()", function () {
     beforeEach(function () {
         $this->suite = new Suite("runner test suite", function () {
         });
         $this->passingTest = new Test("passing spec", function () {
         });
         $this->failingTest = new Test("failing spec", function () {
             throw new \Exception("fail");
         });
         $this->suite->addTest($this->passingTest);
         $this->suite->addTest($this->failingTest);
         $this->eventEmitter = new EventEmitter();
         $this->runner = new Runner($this->suite, new Configuration(), $this->eventEmitter);
     });
     it("should emit a start event when the runner starts", function () {
         $emitted = false;
         $this->eventEmitter->on('runner.start', function () use(&$emitted) {
             $emitted = true;
         });
         $this->runner->run(new TestResult($this->eventEmitter));
         assert($emitted, 'start event should have been emitted');
     });
     it("should emit an end event when the runner ends", function () {
     $dataTables->setBuilder($this->builder);
     $dataTables->setParser(new ParamsParser(10));
     $response = $dataTables->getResponse();
     expect($dataTables->getParser())->toBeA('object');
     expect(array_keys($response))->toBe(['draw', 'recordsTotal', 'recordsFiltered', 'data']);
     expect($response['recordsTotal'])->toBe(100);
     expect($response['recordsFiltered'])->toBe(100);
     expect(count($response['data']))->toBe(10);
     foreach ($response['data'] as $data) {
         expect(array_keys($data))->toBe(['id', 'name', 'email', 'balance', 'DT_RowId']);
         expect($data['DT_RowId'])->toBe($data['id']);
     }
 });
 describe("Limit&Offset", function () {
     beforeEach(function () {
         $_GET = ['start' => 2, 'length' => 1];
     });
     it("should work with start&length", function () {
         $dataTables = new QueryBuilder(20);
         $dataTables->setBuilder($this->builder);
         $dataTables->setParser(new ParamsParser(10));
         $response = $dataTables->getResponse();
         expect(count($response['data']))->toBe(1);
         $dataOne = $response['data'];
         $_GET['start'] = 3;
         $dataTables = new QueryBuilder(20);
         $dataTables->setBuilder($this->builder);
         $dataTables->setParser(new ParamsParser(10));
         $response = $dataTables->getResponse();
         expect(count($response['data']))->toBe(1);
         expect($response['data'])->not->toBe($dataOne);
Exemple #29
0
         expect($actual['repo_token'])->toBe('ABC');
         $coverage = $actual['source_files'][0];
         expect($coverage['name'])->toBe($path);
         expect($coverage['source'])->toBe(file_get_contents($path));
         expect($coverage['coverage'])->toHaveLength(16);
         expect(array_filter($coverage['coverage'], function ($value) {
             return $value === 0;
         }))->toHaveLength(2);
         expect(array_filter($coverage['coverage'], function ($value) {
             return $value === null;
         }))->toHaveLength(12);
     });
 });
 describe("::write()", function () {
     beforeEach(function () {
         $this->output = tempnam("/tmp", "KAHLAN");
     });
     afterEach(function () {
         unlink($this->output);
     });
     it("writes the coverage to a file", function () {
         $path = 'spec' . DS . 'Fixture' . DS . 'Reporter' . DS . 'Coverage' . DS . 'ExtraEmptyLine.php';
         $collector = new Collector(['driver' => $this->driver, 'path' => $path]);
         $code = new ExtraEmptyLine();
         $collector->start();
         $code->shallNotPass();
         $collector->stop();
         $success = Coveralls::write(['collector' => $collector, 'file' => $this->output, 'service_name' => 'kahlan-ci', 'service_job_id' => '123', 'repo_token' => 'ABC']);
         expect($success)->toBe(585);
         $json = file_get_contents($this->output);
         $actual = json_decode($json, true);
<?php

/**
 * Created by PhpStorm.
 * User: basil
 * Date: 11/24/15
 * Time: 6:08 PM
 */
use Notes\Db\Adapter\PdoAdapter;
use Notes\Domain\ValueObject\Uuid;
use Notes\Domain\Entity\User;
describe('Notes\\Db\\Adapter\\PdoAdapter', function () {
    beforeEach(function () {
        $this->dsn = 'mysql:dbname=testdb;host=127.0.0.1';
        $this->username = '******';
        $this->password = '******';
        $this->pdo = new PdoAdapter($this->dsn, $this->username, $this->password);
    });
    describe('->__construct()', function () {
        it('should return a PdoAdapter object', function () {
            $actual = $this->pdo;
            //new PdoAdapter($this->dsn, $this->username, $this->password);
            expect($actual)->to->be->instanceof('Notes\\Db\\Adapter\\PdoAdapter');
        });
    });
    describe('->connect()', function () {
        it('should connect to the database', function () {
            $actual = $this->pdo->connect();
            expect($actual)->to->be->true;
        });
    });