作者:mawah
项目:tracke
/**
* @param string $locator
* @param integer|null $line
*
* @return Suite
*/
public function load($locator, $line = null)
{
$suite = new Suite();
foreach ($this->manager->locateResources($locator) as $resource) {
if (!class_exists($resource->getSpecClassname()) && is_file($resource->getSpecFilename())) {
require_once $resource->getSpecFilename();
}
if (!class_exists($resource->getSpecClassname())) {
continue;
}
$reflection = new ReflectionClass($resource->getSpecClassname());
if ($reflection->isAbstract()) {
continue;
}
if (!$reflection->implementsInterface('PhpSpec\\SpecificationInterface')) {
continue;
}
$spec = new Node\SpecificationNode($resource->getSrcClassname(), $reflection, $resource);
foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if (!preg_match('/^(it|its)[^a-zA-Z]/', $method->getName())) {
continue;
}
if (null !== $line && !$this->lineIsInsideMethod($line, $method)) {
continue;
}
$example = new Node\ExampleNode(str_replace('_', ' ', $method->getName()), $method);
if ($this->methodIsEmpty($method)) {
$example->markAsPending();
}
$spec->addExample($example);
}
$suite->addSpecification($spec);
}
return $suite;
}
作者:codu
项目:phpspec-prepare-extensio
/**
* @param ExampleNode $example
* @param SpecificationInterface $context
* @param MatcherManager $matchers
* @param CollaboratorManager $collaborators
*/
public function prepare(ExampleNode $example, SpecificationInterface $context, MatcherManager $matchers, CollaboratorManager $collaborators)
{
$spec = $example->getSpecification()->getClassReflection()->newInstance();
$beforeMethod = $example->getSpecification()->getClassReflection()->getMethod($this->beforeMethod);
$this->createMissingCollabolators($collaborators, $beforeMethod);
$beforeMethod->invokeArgs($spec, $collaborators->getArgumentsFor($beforeMethod));
}
作者:phpspe
项目:phpspe
/**
* @param ExampleNode $example
* @param Specification $context
* @param MatcherManager $matchers
* @param CollaboratorManager $collaborators
*/
public function prepare(ExampleNode $example, Specification $context, MatcherManager $matchers, CollaboratorManager $collaborators)
{
$subjectFactory = new Wrapper($matchers, $this->presenter, $this->dispatcher, $example, $this->accessInspector);
$subject = $subjectFactory->wrap(null);
$subject->beAnInstanceOf($example->getSpecification()->getResource()->getSrcClassname());
$context->setSpecificationSubject($subject);
}
作者:ecomde
项目:phpspec-magento-di-adapte
/**
* Generates DI related stuff via parameter validator
*
* @param ExampleNode $example
* @param Specification $context
* @param MatcherManager $matchers
* @param CollaboratorManager $collaborators
*
* @return $this
*/
public function prepare(ExampleNode $example, Specification $context, MatcherManager $matchers, CollaboratorManager $collaborators)
{
if ($example->getSpecification()->getClassReflection()->hasMethod('let')) {
$this->parameterValidator->validate($example->getSpecification()->getClassReflection()->getMethod('let'));
}
$this->parameterValidator->validate($example->getFunctionReflection());
return $this;
}
作者:focuslif
项目:v0.
/**
* @param ExampleNode $example
* @param SpecificationInterface $context
* @param MatcherManager $matchers
* @param CollaboratorManager $collaborators
*/
public function teardown(ExampleNode $example, SpecificationInterface $context, MatcherManager $matchers, CollaboratorManager $collaborators)
{
if (!$example->getSpecification()->getClassReflection()->hasMethod('letgo')) {
return;
}
$reflection = $example->getSpecification()->getClassReflection()->getMethod('letgo');
$reflection->invokeArgs($context, $collaborators->getArgumentsFor($reflection));
}
作者:ProgrammingPete
项目:nba-schedule-ap
/**
* @param ExampleNode $example
* @param SpecificationInterface $context
* @param MatcherManager $matchers
* @param CollaboratorManager $collaborators
*/
public function prepare(ExampleNode $example, SpecificationInterface $context, MatcherManager $matchers, CollaboratorManager $collaborators)
{
$this->prophet = new Prophet(null, $this->unwrapper, null);
$classRefl = $example->getSpecification()->getClassReflection();
if ($classRefl->hasMethod('let')) {
$this->generateCollaborators($collaborators, $classRefl->getMethod('let'));
}
$this->generateCollaborators($collaborators, $example->getFunctionReflection());
}
作者:padrai
项目:phpspec-extension
function it_orders_an_array_of_example_nodes(ExampleNode $a, ExampleNode $b, ExampleNode $c)
{
$a->getTitle()->willReturn('bar1');
$b->getTitle()->willReturn('bar2');
$c->getTitle()->willReturn('bar3');
$nodes = [$a, $b, $c];
$expected = [$c, $b, $a];
$this->setSpecificationTitle('foo');
$this->filter($nodes)->shouldReturn($expected);
}
作者:codu
项目:phpspec-prepare-extensio
function prepareExampleBeforeAnnotation(ExampleNode $exampleNode, \ReflectionMethod $method, SpecificationNode $specificationNode, \ReflectionClass $specClass)
{
$exampleNode->getFunctionReflection()->willReturn($method);
$method->getDocComment()->willReturn(<<<ANNOTATION
/**
* @before prepareMethod
*/
ANNOTATION
);
$exampleNode->getSpecification()->willReturn($specificationNode);
$specificationNode->getClassReflection()->willReturn($specClass);
}
作者:kbulloc
项目:MageSpec_v
function it_prepares_the_subject(ExampleNode $example, ObjectBehavior $context, MatcherManager $matchers, CollaboratorManager $collaborators, SpecificationNode $specification, ResourceInterface $resource, VarienWrapper $wrapper, Subject $subject, $factory)
{
$factory->create(Argument::cetera())->willReturn($wrapper);
$wrapper->wrap(null)->willReturn($subject);
$subject->beAnInstanceOf('\\stdObject');
$subject = $subject->getWrappedObject();
$resource->getSrcClassname()->willReturn('\\stdObject');
$specification->getResource()->willReturn($resource);
$example->getSpecification()->willReturn($specification);
$context->setSpecificationSubject($subject)->shouldBeCalled();
$this->prepare($example, $context, $matchers, $collaborators);
}
作者:ecomde
项目:phpspec-magento-di-adapte
function it_does_pass_regular_example_into_parameter_validator_and_let_method_if_they_are_defined(ExampleNode $example, Specification $context, MatcherManager $matchers, CollaboratorManager $collaborators, SpecificationNode $specificationNode, \ReflectionClass $reflectionClass)
{
$example->getSpecification()->willReturn($specificationNode);
$specificationNode->getClassReflection()->willReturn($reflectionClass);
$reflectionClass->hasMethod('let')->willReturn(true);
$exampleClosureReflection = new \ReflectionFunction(function () {
});
$letClosureReflection = new \ReflectionFunction(function () {
});
$reflectionClass->getMethod('let')->willReturn($letClosureReflection)->shouldBeCalled();
$example->getFunctionReflection()->willReturn($exampleClosureReflection)->shouldBeCalled();
$this->parameterValidator->validate($letClosureReflection)->shouldBeCalled();
$this->parameterValidator->validate($exampleClosureReflection)->shouldBeCalled();
$this->prepare($example, $context, $matchers, $collaborators)->shouldReturn($this);
}
作者:SkysoulDesig
项目:TempAr
function let(Laravel $laravel, ExampleNode $example, SpecificationInterface $context)
{
$this->beConstructedWith($laravel);
$p = new Prophet();
$this->refMethod = $p->prophesize('ReflectionMethod');
$this->refMethod->invokeArgs(Argument::type('PhpSpec\\SpecificationInterface'), Argument::type('array'))->shouldBeCalled();
$refClass = $p->prophesize('ReflectionClass');
$refClass->hasMethod('setLaravel')->willReturn(true);
$refClass->hasMethod('setLaravel')->shouldBeCalled();
$refClass->getMethod('setLaravel')->willReturn($this->refMethod->reveal());
$refClass->getMethod('setLaravel')->shouldBeCalled();
$specNode = $p->prophesize('PhpSpec\\Loader\\Node\\SpecificationNode');
$specNode->getClassReflection()->willReturn($refClass->reveal());
$example->getSpecification()->willReturn($specNode->reveal());
}
作者:docteurklei
项目:event-stor
private function getIterators(ExampleNode $example)
{
$classRefl = $example->getSpecification()->getClassReflection();
if ($classRefl->hasMethod('let')) {
foreach ($classRefl->getMethod('let')->getParameters() as $parameter) {
if ($this->isIterator($parameter->getClass())) {
(yield $parameter->getName() => $parameter->getClass()->getName());
}
}
}
foreach ($example->getFunctionReflection()->getParameters() as $parameter) {
if ($this->isIterator($parameter->getClass())) {
(yield $parameter->getName() => $parameter->getClass()->getName());
}
}
}
作者:burimshal
项目:numbertoword
function it_runs_let_and_letgo_maintainer_before_and_after_each_example_if_the_example_throws_an_exception(ExampleNode $example, SpecificationNode $specification, ReflectionClass $specReflection, $context, ReflectionMethod $exampReflection, LetAndLetgoMaintainer $maintainer, SpecificationInterface $context)
{
$example->isPending()->willReturn(false);
$example->getFunctionReflection()->willReturn($exampReflection);
$example->getSpecification()->willReturn($specification);
$specification->getClassReflection()->willReturn($specReflection);
$specReflection->newInstanceArgs()->willReturn($context);
$exampReflection->getParameters()->willReturn(array());
$exampReflection->invokeArgs($context, array())->willThrow('RuntimeException');
$maintainer->getPriority()->willReturn(1);
$maintainer->supports($example)->willReturn(true);
$maintainer->prepare($example, Argument::cetera())->shouldBeCalled();
$maintainer->teardown($example, Argument::cetera())->shouldBeCalled();
$this->registerMaintainer($maintainer);
$this->run($example);
}
作者:phpspe
项目:phpspe
function it_outputs_exceptions_for_failed_examples(SuiteEvent $event, ExampleEvent $pendingEvent, ConsoleIO $io, StatisticsCollector $stats, SpecificationNode $specification, ExampleNode $example)
{
$example->getLineNumber()->willReturn(37);
$example->getTitle()->willReturn('it tests something');
$pendingEvent->getException()->willReturn(new PendingException());
$pendingEvent->getSpecification()->willReturn($specification);
$pendingEvent->getExample()->willReturn($example);
$stats->getEventsCount()->willReturn(1);
$stats->getFailedEvents()->willReturn(array());
$stats->getBrokenEvents()->willReturn(array());
$stats->getPendingEvents()->willReturn(array($pendingEvent));
$stats->getSkippedEvents()->willReturn(array());
$stats->getTotalSpecs()->willReturn(1);
$stats->getCountsHash()->willReturn(array('passed' => 0, 'pending' => 1, 'skipped' => 0, 'failed' => 0, 'broken' => 0));
$this->afterSuite($event);
$expected = '<lineno> 37</lineno> <pending>- it tests something</pending>';
$io->writeln($expected)->shouldHaveBeenCalled();
}
作者:codu
项目:phpspec-data-provider-extensio
/**
* @param ExampleNode $example
* @return bool|mixed
*/
private function getDataFromProvider(ExampleNode $example)
{
$parser = new Parser();
$dataProviderMethod = $parser->getDataProvider($example->getFunctionReflection());
if (!isset($dataProviderMethod)) {
return array();
}
if (!$example->getSpecification()->getClassReflection()->hasMethod($dataProviderMethod)) {
return array();
}
$subject = $example->getSpecification()->getClassReflection()->newInstance();
$providedData = $example->getSpecification()->getClassReflection()->getMethod($dataProviderMethod)->invoke($subject);
return is_array($providedData) ? $providedData : array();
}
作者:ProgrammingPete
项目:nba-schedule-ap
/**
* @param SpecificationInterface $context
* @param ExampleNode $example
*
* @throws \PhpSpec\Exception\Example\PendingException
* @throws \Exception
*/
protected function executeExample(SpecificationInterface $context, ExampleNode $example)
{
if ($example->isPending()) {
throw new ExampleException\PendingException();
}
$matchers = new MatcherManager($this->presenter);
$collaborators = new CollaboratorManager($this->presenter);
$maintainers = array_filter($this->maintainers, function ($maintainer) use($example) {
return $maintainer->supports($example);
});
// run maintainers prepare
foreach ($maintainers as $maintainer) {
$maintainer->prepare($example, $context, $matchers, $collaborators);
}
// execute example
$reflection = $example->getFunctionReflection();
try {
$reflection->invokeArgs($context, $collaborators->getArgumentsFor($reflection));
} catch (\Exception $e) {
$this->runMaintainersTeardown($this->searchExceptionMaintainers($maintainers), $example, $context, $matchers, $collaborators);
throw $e;
}
$this->runMaintainersTeardown($maintainers, $example, $context, $matchers, $collaborators);
}
作者:pawel-grzon
项目:teamcity-phpspec-extensio
private function exampleEvent(ExampleNode $node, $result = ExampleEvent::PASSED, $time = 0, $exceptionMessage = '')
{
return new ExampleEvent($node->getWrappedObject(), $time, $result, new \Exception($exceptionMessage));
}
作者:josborn
项目:phpspec-lume
/**
* {@inheritdoc}
*/
public function prepare(ExampleNode $example, SpecificationInterface $context, MatcherManager $matchers, CollaboratorManager $collaborators)
{
$reflection = $example->getSpecification()->getClassReflection()->getMethod('setLumen');
$reflection->invokeArgs($context, array($this->lumen));
}
作者:kbulloc
项目:MageSpec_v
public function supports(ExampleNode $example)
{
return $example->getSpecification()->getResource() instanceof ModelResource;
}
作者:ProgrammingPete
项目:nba-schedule-ap
/**
* @param ExampleNode $example
*/
public function addExample(ExampleNode $example)
{
$this->examples[] = $example;
$example->setSpecification($this);
}