Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion peridot.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
use Evenement\EventEmitterInterface;
use Peridot\Plugin\Prophecy\ProphecyPlugin;

return function (EventEmitterInterface $emitter) {
return function(EventEmitterInterface $emitter) {
new ProphecyPlugin($emitter);
};
12 changes: 6 additions & 6 deletions specs/application/http/router.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
use Command\ErrorCommand;
use Application\HTTP\Router;

describe('Router', function () {
beforeEach(function () {
describe('Router', function() {
beforeEach(function() {
$this->router = new Router;
});
describe('->getCommand()', function () {
it('should return GenerateCommand when generate name is passed', function () {
describe('->getCommand()', function() {
it('should return GenerateCommand when generate name is passed', function() {
expect($this->router->getCommand('generate'))
->to->be->an->instanceof(GenerateCommand::class);
});
it('should return CompleteCommand when complete name is passed', function () {
it('should return CompleteCommand when complete name is passed', function() {
expect($this->router->getCommand('complete'))
->to->be->an->instanceof(CompleteCommand::class);
});
it('should return ErrorCommand when unknown name is passed', function () {
it('should return ErrorCommand when unknown name is passed', function() {
expect($this->router->getCommand('someUknownName'))
->to->be->an->instanceof(ErrorCommand::class);
});
Expand Down
50 changes: 25 additions & 25 deletions specs/completer/resolver/ContextResolver.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Monolog\Handler\NullHandler;
use Symfony\Component\EventDispatcher\EventDispatcher;

describe('ContextResolver', function(){
beforeEach(function(){
describe('ContextResolver', function() {
beforeEach(function() {
$logger = new Logger('spec');
$logger->pushHandler(new NullHandler);
$this->index = new Index;
Expand All @@ -21,84 +21,84 @@
$this->resolver = new ContextResolver($this->parser, $this->typeResolver, $logger);
$this->dummyLine = '$obj->getMethod()->';
});
describe('->getContext()', function(){
it('throws exception on empty line', function(){
describe('->getContext()', function() {
it('throws exception on empty line', function() {
expect([$this->resolver, 'getContext'])
->with('', $this->index)->to->throw('Exception');
});
it('returns Context instance', function(){
it('returns Context instance', function() {
$result = $this->resolver->getContext($this->dummyLine);
expect($result)->to->be->an->instanceof(Context::class);
});
describe('Namespace', function(){
it('has type namespace after namespace symbol', function(){
describe('Namespace', function() {
it('has type namespace after namespace symbol', function() {
$context = $this->resolver->getContext('namespace ');
expect($context->isNamespace())->to->be->true;
});
it('has type namespace after namespace symbol with TString', function(){
it('has type namespace after namespace symbol with TString', function() {
$context = $this->resolver->getContext('namespace SomeName');
expect($context->isNamespace())->to->be->true;
});
it('has type namespace after namespace symbol with TString and separator', function(){
it('has type namespace after namespace symbol with TString and separator', function() {
$context = $this->resolver->getContext('namespace SomeName\AndOther\Name');
expect($context->isNamespace())->to->be->true;
});
it('hasn\'t type namespace after ;', function(){
it('hasn\'t type namespace after ;', function() {
$context = $this->resolver->getContext('namespace SomeName\AndOther\Name;');
expect($context->isNamespace())->to->be->false;
});
});
describe('Use', function(){
it('has type use after use symbol', function(){
describe('Use', function() {
it('has type use after use symbol', function() {
$context = $this->resolver->getContext('use ');
expect($context->isUse())->to->be->true;
});
it('has type use after use symbol with TString', function(){
it('has type use after use symbol with TString', function() {
$context = $this->resolver->getContext('use SomeName');
expect($context->isUse())->to->be->true;
});
it('has type use after use symbol with TString and separator', function(){
it('has type use after use symbol with TString and separator', function() {
$context = $this->resolver->getContext('use SomeName\AndOther\Name');
expect($context->isUse())->to->be->true;
});
it('hasn\'t type use after ;', function(){
it('hasn\'t type use after ;', function() {
$context = $this->resolver->getContext('use SomeName\AndOther\Name;');
expect($context->isUse())->to->be->false;
});
});
describe('Object', function(){
it('has type object after object operator', function(){
describe('Object', function() {
it('has type object after object operator', function() {
$context = $this->resolver->getContext('$var->');
expect($context->isObject())->to->be->true;
});
it('has type object after object operator and $this', function(){
it('has type object after object operator and $this', function() {
$context = $this->resolver->getContext('$this->');
expect($context->isObject())->to->be->true;
});
it('has type object after object operator with complex prefix', function(){
it('has type object after object operator with complex prefix', function() {
$context = $this->resolver->getContext('$var->getMethod()->param->');
expect($context->isObject())->to->be->true;
});
it('has type object after object operator with TString', function(){
it('has type object after object operator with TString', function() {
$context = $this->resolver->getContext('$var->param');
expect($context->isObject())->to->be->true;
});
it('hasn\'t type object after object operator with TString and separator', function(){
it('hasn\'t type object after object operator with TString and separator', function() {
$context = $this->resolver->getContext('$var->param;');
expect($context->isObject())->to->be->false;
});
it('hasn\'t type object after object operator with (', function(){
it('hasn\'t type object after object operator with (', function() {
$context = $this->resolver->getContext('$var->param(');
expect($context->isObject())->to->be->false;
});
it('hasn\'t type object after object operator with TString and space', function(){
it('hasn\'t type object after object operator with TString and space', function() {
/** @var Context $context */
$context = $this->resolver->getContext('$var->param ');
expect($context->isObject())->to->be->false;
});
});
describe("Method call", function () {
it('has type method call after (', function () {
describe("Method call", function() {
it('has type method call after (', function() {
$context = $this->resolver->getContext('$var->method(');
expect($context->isMethodCall())->to->be->true;
});
Expand Down
32 changes: 16 additions & 16 deletions specs/completer/resolver/NodeTypeResolver.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Monolog\Handler\NullHandler;
use Symfony\Component\EventDispatcher\EventDispatcher;

function createClass($classFQN, $fqcn){
function createClass($classFQN, $fqcn) {
$class = new ClassData($classFQN, 'dummy/path/class.php');
$method = new MethodData('method2');
$method->setType(ClassData::MODIFIER_PUBLIC);
Expand All @@ -28,8 +28,8 @@ function createClass($classFQN, $fqcn){
return $class;
}

describe('NodeTypeResolver', function(){
beforeEach(function(){
describe('NodeTypeResolver', function() {
beforeEach(function() {
$logger = new Logger('spec');
$logger->pushHandler(new NullHandler);
$this->resolver = new NodeTypeResolver($logger, new UseParser, new EventDispatcher);
Expand All @@ -46,49 +46,49 @@ function createClass($classFQN, $fqcn){
$this->index->addClass($class);
$this->index->addClass($class2);
});
describe('->getType()', function(){
it('returns variable type from scope', function(){
describe('->getType()', function() {
it('returns variable type from scope', function() {
$node = new NodeVar;
$node->name = $this->var->getName();
expect($this->resolver->getLastChainNodeType($node, $this->index, $this->scope))
->to->equal($this->var->getType());
});
describe('Properties', function(){
beforeEach(function(){
describe('Properties', function() {
beforeEach(function() {
$this->node = new PropertyFetch;
$this->node->var = new NodeVar;
$this->node->var->name = $this->var->getName();
});
it('returns null for unknown property', function(){
it('returns null for unknown property', function() {
$this->node->name = 'param';
expect($this->resolver->getLastChainNodeType($this->node, $this->index, $this->scope))
->to->be->null;
});
it('returns type for known property', function(){
it('returns type for known property', function() {
$this->node->name = 'param2';
expect($this->resolver->getLastChainNodeType($this->node, $this->index, $this->scope))
->to->equal($this->anotherFQCN);
});
});
describe('Method', function(){
beforeEach(function(){
describe('Method', function() {
beforeEach(function() {
$this->node = new MethodCall;
$this->node->var = new NodeVar;
$this->node->var->name = $this->var->getName();
});
it('returns null for unknown method', function(){
it('returns null for unknown method', function() {
$this->node->name = 'method';
expect($this->resolver->getLastChainNodeType($this->node, $this->index, $this->scope))
->to->be->null;
});
it('returns type for known method', function(){
it('returns type for known method', function() {
$this->node->name = 'method2';
expect($this->resolver->getLastChainNodeType($this->node, $this->index, $this->scope))
->to->equal($this->anotherFQCN);
});
});
describe('Complex', function(){
beforeEach(function(){
describe('Complex', function() {
beforeEach(function() {
$this->node = new MethodCall;
$this->node->name = 'method2';
$this->node->var = new PropertyFetch;
Expand All @@ -98,7 +98,7 @@ function createClass($classFQN, $fqcn){
$this->node->var->var->var = new NodeVar;
$this->node->var->var->var->name = $this->var->getName();
});
it('returns type for known property in complex chain', function(){
it('returns type for known property in complex chain', function() {
$node = new PropertyFetch;
$node->var = $this->node;
$node->name = 'param2';
Expand Down
20 changes: 10 additions & 10 deletions specs/entity/FQCN.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use Entity\FQCN;
use Entity\FQN;

describe('FQCN', function(){
describe('__construct()', function(){
it('creates parts from string with class', function(){
describe('FQCN', function() {
describe('__construct()', function() {
it('creates parts from string with class', function() {
$fqn = new FQCN('SomeClassName', 'Some\\Long\\Parts\\To\\Name');
expect($fqn->getParts())->to->equal([
'Some',
Expand All @@ -16,19 +16,19 @@
'SomeClassName'
]);
});
it('creates parts from array', function(){
it('creates parts from array', function() {
$parts = ['Some', 'Long', 'Parts'];
$fqn = new FQCN('ClassName', $parts);
$parts[] = 'ClassName';
expect($fqn->getParts())->to->equal($parts);
});
it('FQCN with class name only', function(){
it('FQCN with class name only', function() {
$fqn = new FQN('ClassName');
expect($fqn->getParts())->to->equal(['ClassName']);
});
});
describe('->join()', function(){
it('joins another FQCN', function(){
describe('->join()', function() {
it('joins another FQCN', function() {
$fqn = new FQCN('ClassName', 'Some\\Long\\Path');
$join = new FQCN('AnotherName', 'Another\\Long\\Name');
expect($fqn->join($join)->getParts())->to->equal([
Expand All @@ -42,7 +42,7 @@
'AnotherName'
]);
});
it('joins FQN', function(){
it('joins FQN', function() {
$fqn = new FQCN('ClassName', 'Some\\Long\\Path\\Another');
$join = new FQN('Another\\Long\\Name');
expect($fqn->join($join)->getParts())->to->equal([
Expand All @@ -57,8 +57,8 @@
]);
});
});
describe('->toString()', function(){
it('returns valid string', function(){
describe('->toString()', function() {
it('returns valid string', function() {
$str = 'Some\\Long\\Path\\To\\Name';
$fqn = new FQCN('ClassName', $str);
expect($fqn->toString())->to->equal($str . '\\ClassName');
Expand Down
20 changes: 10 additions & 10 deletions specs/entity/FQN.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use Entity\FQN;

describe('FQN', function(){
describe('__construct()', function(){
it('creates parts from string', function(){
describe('FQN', function() {
describe('__construct()', function() {
it('creates parts from string', function() {
$fqn = new FQN('Some\\Long\\Parts\\To\\Name');
expect($fqn->getParts())->to->equal([
'Some',
Expand All @@ -14,18 +14,18 @@
'Name'
]);
});
it('creates parts from array', function(){
it('creates parts from array', function() {
$parts = ['Some', 'Long', 'Parts'];
$fqn = new FQN($parts);
expect($fqn->getParts())->to->equal($parts);
});
it('creates empty parts on empty call', function(){
it('creates empty parts on empty call', function() {
$fqn = new FQN;
expect($fqn->getParts())->to->equal([]);
});
});
describe('->join()', function(){
it('joins another FQN', function(){
describe('->join()', function() {
it('joins another FQN', function() {
$fqn = new FQN('Some\\Long\\Path');
$join = new FQN('Another\\Long\\Name');
expect($fqn->join($join)->getParts())->to->equal([
Expand All @@ -37,7 +37,7 @@
'Name'
]);
});
it('joins child FQN', function(){
it('joins child FQN', function() {
$fqn = new FQN('Some\\Long\\Path\\Another');
$join = new FQN('Another\\Long\\Name');
expect($fqn->join($join)->getParts())->to->equal([
Expand All @@ -50,8 +50,8 @@
]);
});
});
describe('->toString()', function(){
it('returns valid string', function(){
describe('->toString()', function() {
it('returns valid string', function() {
$str = 'Some\\Long\\Path\\To\\Name';
$fqn = new FQN($str);
expect($fqn->toString())->to->equal($str);
Expand Down
10 changes: 5 additions & 5 deletions specs/generator/filesfinder.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Entity\Index;
use Prophecy\Argument;

describe('FilesFinder', function () {
beforeEach(function () {
describe('FilesFinder', function() {
beforeEach(function() {
$this->mock = $this->getProphet()->prophesize(PathResolver::class);
$this->mock->getDirFilesRecursive(Argument::any())->willReturn([
'/test/TestClass.php',
Expand All @@ -16,14 +16,14 @@
'/composer.json',
'/peridot.php'
]);
$this->mock->relative(Argument::any(), Argument::any())->will(function ($args) {
$this->mock->relative(Argument::any(), Argument::any())->will(function($args) {
return $args[1];
});
$this->files = new FilesFinder($this->mock->reveal());
$this->project = new Project(new Index, "/project");
});
describe('->getProjectFiles()', function () {
it('returns all php files from project', function () {
describe('->getProjectFiles()', function() {
it('returns all php files from project', function() {
expect($this->files->getProjectFiles($this->project))->to->be->equal([
'/test/TestClass.php',
'/some/AnotherFile.php',
Expand Down
Loading