|
| 1 | +<?php |
| 2 | + |
| 3 | +use Parser\CommentParser; |
| 4 | +use Parser\UseParser; |
| 5 | +use Entity\Node\Comment; |
| 6 | +use Entity\Node\Uses; |
| 7 | +use Entity\FQCN; |
| 8 | + |
| 9 | +describe('CommentParser', function(){ |
| 10 | + beforeEach(function(){ |
| 11 | + $this->useParser = new UseParser; |
| 12 | + $this->useParser->setUses( |
| 13 | + new Uses( |
| 14 | + $this->useParser->parseFQCN('Entity\Node') |
| 15 | + ) |
| 16 | + ); |
| 17 | + $this->parser = new CommentParser($this->useParser); |
| 18 | + $this->simpleDoc = <<<'DOCBLOCK' |
| 19 | +/** |
| 20 | + * This is a short description |
| 21 | + * |
| 22 | + * This is a long description |
| 23 | + * |
| 24 | + * @param MethodParam $myParamName A test param |
| 25 | + * @param Comment $anotherParam |
| 26 | + * @throws \Exception |
| 27 | + * @return Comment |
| 28 | + */ |
| 29 | +DOCBLOCK; |
| 30 | + $this->comment = $this->parser->parse($this->simpleDoc); |
| 31 | + }); |
| 32 | + describe('parse()', function(){ |
| 33 | + it('returns Comment', function(){ |
| 34 | + $result = $this->comment; |
| 35 | + expect($result)->to->be->an->instanceof(Comment::class); |
| 36 | + }); |
| 37 | + it('creates vars for all params', function(){ |
| 38 | + $comment = $this->comment; |
| 39 | + expect(count($comment->getVars()))->to->equal(2); |
| 40 | + }); |
| 41 | + it('creates return FQCN', function(){ |
| 42 | + $comment = $this->comment; |
| 43 | + expect($comment->getReturn())->to->be->an->instanceof(FQCN::class); |
| 44 | + expect($comment->getReturn()->toString())->to->equal('Entity\Node\Comment'); |
| 45 | + }); |
| 46 | + }); |
| 47 | + describe('createMethodParam()', function(){ |
| 48 | + it('sets var name', function(){ |
| 49 | + $comment = $this->comment; |
| 50 | + $var = array_shift($comment->getVars()); |
| 51 | + expect($var->getName())->to->equal('myParamName'); |
| 52 | + }); |
| 53 | + it('sets var type', function(){ |
| 54 | + $comment = $this->comment; |
| 55 | + $var = array_pop($comment->getVars()); |
| 56 | + expect($var->getType())->to->be->an->instanceof(FQCN::class); |
| 57 | + expect($var->getType()->toString())->to->equal( |
| 58 | + 'Entity\Node\Comment' |
| 59 | + ); |
| 60 | + }); |
| 61 | + }); |
| 62 | + describe('trimComment()', function(){ |
| 63 | + it('removes * and spaces', function(){ |
| 64 | + $result = $this->comment; |
| 65 | + $trimmedDoc = <<<'DOCBLOCK' |
| 66 | +
|
| 67 | +This is a short description |
| 68 | +
|
| 69 | +This is a long description |
| 70 | +
|
| 71 | +@param MethodParam $myParamName A test param |
| 72 | +@param Comment $anotherParam |
| 73 | +@throws \Exception |
| 74 | +@return Comment |
| 75 | + |
| 76 | +DOCBLOCK; |
| 77 | + expect($result->getDoc())->to->equal($trimmedDoc); |
| 78 | + }); |
| 79 | + }); |
| 80 | +}); |
0 commit comments