本文整理汇总了PHP中beforeEach函数的典型用法代码示例。如果您正苦于以下问题:PHP beforeEach函数的具体用法?PHP beforeEach怎么用?PHP beforeEach使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了beforeEach函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: describe
<?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'`."));
});
示例2: describe
});
});
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 () {
示例3: describe
<?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');
示例4: describe
});
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']]);
示例5: describe
<?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);
示例6: describe
<?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 */
示例7: describe
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]);
示例8: context
});
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);
示例9: describe
<?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');
});
示例10: expect
$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);
});
});
});
示例11: unset
$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);
示例12: expect
$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 () {
示例13: describe
<?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);
示例14: expect
$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);
示例15: expect
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);
});
});
});