Skip to content

Commit f8d350d

Browse files
authored
Merge pull request #262 from voku/more_tests
Only more tests
2 parents e3324ec + c2889e4 commit f8d350d

File tree

6 files changed

+294
-1
lines changed

6 files changed

+294
-1
lines changed

src/DocBlock/Tags/See.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static function create(
5959
$description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null;
6060

6161
// https://tools.ietf.org/html/rfc2396#section-3
62-
if (preg_match('/\w:\/\/\w/i', $parts[0])) {
62+
if (preg_match('#\w://\w#', $parts[0])) {
6363
return new static(new Url($parts[0]), $description);
6464
}
6565

tests/unit/DocBlock/StandardTagFactoryTest.php

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,30 @@ public function testCreatingAGenericTag() : void
7878
$this->assertSame($expectedDescription, $tag->getDescription());
7979
}
8080

81+
/**
82+
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
83+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic
84+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
85+
* @uses \phpDocumentor\Reflection\DocBlock\Description
86+
*
87+
* @covers ::__construct
88+
* @covers ::create
89+
*/
90+
public function testCreatingAGenericTagWithDescriptionText() : void
91+
{
92+
$expectedTagName = 'unknown-tag';
93+
$expectedDescriptionText = ' foo Bar 123 ';
94+
$context = new Context('');
95+
96+
$tagFactory = new StandardTagFactory(new FqsenResolver());
97+
$tagFactory->addService(new DescriptionFactory($tagFactory), DescriptionFactory::class);
98+
99+
$tag = $tagFactory->create('@' . $expectedTagName . $expectedDescriptionText, $context);
100+
101+
$this->assertInstanceOf(Generic::class, $tag);
102+
$this->assertSame('foo Bar 123', $tag . '');
103+
}
104+
81105
/**
82106
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
83107
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author
@@ -146,6 +170,90 @@ public function testPassingYourOwnSetOfTagHandlers() : void
146170
$this->assertSame('author', $tag->getName());
147171
}
148172

173+
/**
174+
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
175+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author
176+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
177+
*
178+
* @covers ::__construct
179+
* @covers ::create
180+
*/
181+
public function testPassingYourOwnSetOfTagHandlersWithGermanChars() : void
182+
{
183+
$typeResolver = new TypeResolver();
184+
$fqsenResolver = new FqsenResolver();
185+
$tagFactory = new StandardTagFactory($fqsenResolver);
186+
$descriptionFactory = new DescriptionFactory($tagFactory);
187+
$context = new Context('');
188+
189+
$tagFactory = new StandardTagFactory(
190+
$fqsenResolver,
191+
['my-täg' => Author::class]
192+
);
193+
194+
$tag = $tagFactory->create('@my-täg foo bar ', $context);
195+
196+
$this->assertInstanceOf(Author::class, $tag);
197+
$this->assertSame('author', $tag->getName());
198+
$this->assertSame('foo bar', $tag . '');
199+
}
200+
201+
/**
202+
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
203+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author
204+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
205+
*
206+
* @covers ::__construct
207+
* @covers ::create
208+
*/
209+
public function testPassingYourOwnSetOfTagHandlersWithoutComment() : void
210+
{
211+
$typeResolver = new TypeResolver();
212+
$fqsenResolver = new FqsenResolver();
213+
$tagFactory = new StandardTagFactory($fqsenResolver);
214+
$descriptionFactory = new DescriptionFactory($tagFactory);
215+
$context = new Context('');
216+
217+
$tagFactory = new StandardTagFactory(
218+
$fqsenResolver,
219+
['my-täg' => Author::class]
220+
);
221+
222+
$tag = $tagFactory->create('@my-täg', $context);
223+
224+
$this->assertInstanceOf(Author::class, $tag);
225+
$this->assertSame('author', $tag->getName());
226+
}
227+
228+
/**
229+
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
230+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author
231+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
232+
*
233+
* @covers ::__construct
234+
* @covers ::create
235+
*/
236+
public function testPassingYourOwnSetOfTagHandlersWithEmptyComment() : void
237+
{
238+
$this->expectException('InvalidArgumentException');
239+
$this->expectExceptionMessage(
240+
'The tag "@my-täg " does not seem to be wellformed, please check it for errors'
241+
);
242+
243+
$typeResolver = new TypeResolver();
244+
$fqsenResolver = new FqsenResolver();
245+
$tagFactory = new StandardTagFactory($fqsenResolver);
246+
$descriptionFactory = new DescriptionFactory($tagFactory);
247+
$context = new Context('');
248+
249+
$tagFactory = new StandardTagFactory(
250+
$fqsenResolver,
251+
['my-täg' => Author::class]
252+
);
253+
254+
$tag = $tagFactory->create('@my-täg ', $context);
255+
}
256+
149257
/**
150258
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct
151259
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService

tests/unit/DocBlock/Tags/CoversTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Mockery as m;
1717
use phpDocumentor\Reflection\DocBlock\Description;
1818
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
19+
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
1920
use phpDocumentor\Reflection\Fqsen;
2021
use phpDocumentor\Reflection\FqsenResolver;
2122
use phpDocumentor\Reflection\Types\Context;
@@ -174,6 +175,35 @@ public function testStringRepresentationIsReturnedWithoutDescription() : void
174175
$this->assertSame('\DateTime', (string) $fixture);
175176
}
176177

178+
/**
179+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::<public>
180+
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
181+
* @uses \phpDocumentor\Reflection\FqsenResolver
182+
* @uses \phpDocumentor\Reflection\DocBlock\Description
183+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Url
184+
* @uses \phpDocumentor\Reflection\Types\Context
185+
*
186+
* @covers ::create
187+
*/
188+
public function testFactoryMethodWithSpaceBeforeClass() : void
189+
{
190+
$fqsenResolver = new FqsenResolver();
191+
$tagFactory = new StandardTagFactory($fqsenResolver);
192+
$descriptionFactory = new DescriptionFactory($tagFactory);
193+
$context = new Context('');
194+
195+
$fixture = Covers::create(
196+
'Foo My Description ',
197+
$descriptionFactory,
198+
$fqsenResolver,
199+
$context
200+
);
201+
202+
$this->assertSame('\Foo My Description ', (string) $fixture);
203+
$this->assertSame('\Foo', (string) $fixture->getReference());
204+
$this->assertSame('My Description ', $fixture->getDescription() . '');
205+
}
206+
177207
/**
178208
* @covers ::__construct
179209
* @covers ::__toString

tests/unit/DocBlock/Tags/LinkTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Mockery as m;
1717
use phpDocumentor\Reflection\DocBlock\Description;
1818
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
19+
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
20+
use phpDocumentor\Reflection\FqsenResolver;
1921
use phpDocumentor\Reflection\Types\Context;
2022
use PHPUnit\Framework\TestCase;
2123

@@ -163,6 +165,60 @@ public function testFactoryMethod() : void
163165
$this->assertSame($description, $fixture->getDescription());
164166
}
165167

168+
/**
169+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::<public>
170+
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
171+
* @uses \phpDocumentor\Reflection\FqsenResolver
172+
* @uses \phpDocumentor\Reflection\DocBlock\Description
173+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Url
174+
* @uses \phpDocumentor\Reflection\Types\Context
175+
*
176+
* @covers ::create
177+
*/
178+
public function testFactoryMethodWithoutSpaceBeforeUrl() : void
179+
{
180+
$fqsenResolver = new FqsenResolver();
181+
$tagFactory = new StandardTagFactory($fqsenResolver);
182+
$descriptionFactory = new DescriptionFactory($tagFactory);
183+
$context = new Context('');
184+
185+
$fixture = Link::create(
186+
'http://this.is.my/link My Description ',
187+
$descriptionFactory,
188+
$context
189+
);
190+
191+
$this->assertSame('http://this.is.my/link My Description ', (string) $fixture);
192+
$this->assertSame('My Description ', $fixture->getDescription() . '');
193+
}
194+
195+
/**
196+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::<public>
197+
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
198+
* @uses \phpDocumentor\Reflection\FqsenResolver
199+
* @uses \phpDocumentor\Reflection\DocBlock\Description
200+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Url
201+
* @uses \phpDocumentor\Reflection\Types\Context
202+
*
203+
* @covers ::create
204+
*/
205+
public function testFactoryMethodWithSpaceBeforeUrl() : void
206+
{
207+
$fqsenResolver = new FqsenResolver();
208+
$tagFactory = new StandardTagFactory($fqsenResolver);
209+
$descriptionFactory = new DescriptionFactory($tagFactory);
210+
$context = new Context('');
211+
212+
$fixture = Link::create(
213+
' http://this.is.my/link My Description ',
214+
$descriptionFactory,
215+
$context
216+
);
217+
218+
$this->assertSame('http://this.is.my/link My Description ', (string) $fixture);
219+
$this->assertSame('http://this.is.my/link My Description ', $fixture->getDescription() . '');
220+
}
221+
166222
/**
167223
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Link::<public>
168224
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory

tests/unit/DocBlock/Tags/SeeTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
use Mockery as m;
1717
use phpDocumentor\Reflection\DocBlock\Description;
1818
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
19+
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
1920
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen as FqsenRef;
21+
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen as TagsFqsen;
2022
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url as UrlRef;
2123
use phpDocumentor\Reflection\Fqsen;
2224
use phpDocumentor\Reflection\FqsenResolver;
@@ -251,6 +253,36 @@ public function testFactoryMethodWithUrl() : void
251253
$this->assertSame($description, $fixture->getDescription());
252254
}
253255

256+
/**
257+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::<public>
258+
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
259+
* @uses \phpDocumentor\Reflection\FqsenResolver
260+
* @uses \phpDocumentor\Reflection\DocBlock\Description
261+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Url
262+
* @uses \phpDocumentor\Reflection\Types\Context
263+
*
264+
* @covers ::create
265+
*/
266+
public function testFactoryMethodWithoutUrl() : void
267+
{
268+
$fqsenResolver = new FqsenResolver();
269+
$tagFactory = new StandardTagFactory($fqsenResolver);
270+
$descriptionFactory = new DescriptionFactory($tagFactory);
271+
$context = new Context('');
272+
273+
$fixture = See::create(
274+
'Foo My Description ',
275+
$fqsenResolver,
276+
$descriptionFactory,
277+
$context
278+
);
279+
280+
$this->assertSame('\Foo My Description ', (string) $fixture);
281+
$this->assertInstanceOf(TagsFqsen::class, $fixture->getReference());
282+
$this->assertSame('\Foo', (string) $fixture->getReference());
283+
$this->assertSame('My Description ', $fixture->getDescription() . '');
284+
}
285+
254286
/**
255287
* @covers ::create
256288
*/

tests/unit/DocBlock/Tags/UsesTest.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Mockery as m;
1717
use phpDocumentor\Reflection\DocBlock\Description;
1818
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
19+
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
1920
use phpDocumentor\Reflection\Fqsen;
2021
use phpDocumentor\Reflection\FqsenResolver;
2122
use phpDocumentor\Reflection\Types\Context;
@@ -129,6 +130,12 @@ public function testStringRepresentationIsReturned() : void
129130
*/
130131
public function testStringRepresentationIsReturnedWithoutDescription() : void
131132
{
133+
$fixture = new Uses(new Fqsen('\\'));
134+
135+
$this->assertSame('\\', (string) $fixture);
136+
137+
// ---
138+
132139
$fixture = new Uses(new Fqsen('\DateTime'));
133140

134141
$this->assertSame('\DateTime', (string) $fixture);
@@ -170,6 +177,66 @@ public function testFactoryMethod() : void
170177
$this->assertSame($description, $fixture->getDescription());
171178
}
172179

180+
/**
181+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::<public>
182+
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
183+
* @uses \phpDocumentor\Reflection\FqsenResolver
184+
* @uses \phpDocumentor\Reflection\DocBlock\Description
185+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Url
186+
* @uses \phpDocumentor\Reflection\Types\Context
187+
*
188+
* @covers ::create
189+
*/
190+
public function testFactoryMethodWithoutSpaceBeforeClass() : void
191+
{
192+
$fqsenResolver = new FqsenResolver();
193+
$tagFactory = new StandardTagFactory($fqsenResolver);
194+
$descriptionFactory = new DescriptionFactory($tagFactory);
195+
$context = new Context('');
196+
197+
$fixture = Uses::create(
198+
'Foo My Description ',
199+
$fqsenResolver,
200+
$descriptionFactory,
201+
$context
202+
);
203+
204+
$this->assertSame('\Foo My Description ', (string) $fixture);
205+
$this->assertInstanceOf(Fqsen::class, $fixture->getReference());
206+
$this->assertSame('\\Foo', (string) $fixture->getReference());
207+
$this->assertSame('My Description ', $fixture->getDescription() . '');
208+
}
209+
210+
/**
211+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::<public>
212+
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
213+
* @uses \phpDocumentor\Reflection\FqsenResolver
214+
* @uses \phpDocumentor\Reflection\DocBlock\Description
215+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Url
216+
* @uses \phpDocumentor\Reflection\Types\Context
217+
*
218+
* @covers ::create
219+
*/
220+
public function testFactoryMethodWithSpaceBeforeClass() : void
221+
{
222+
$fqsenResolver = new FqsenResolver();
223+
$tagFactory = new StandardTagFactory($fqsenResolver);
224+
$descriptionFactory = new DescriptionFactory($tagFactory);
225+
$context = new Context('');
226+
227+
$fixture = Uses::create(
228+
' Foo My Description ',
229+
$fqsenResolver,
230+
$descriptionFactory,
231+
$context
232+
);
233+
234+
$this->assertSame('\ Foo My Description ', (string) $fixture);
235+
$this->assertInstanceOf(Fqsen::class, $fixture->getReference());
236+
$this->assertSame('\\', (string) $fixture->getReference());
237+
$this->assertSame('Foo My Description ', $fixture->getDescription() . '');
238+
}
239+
173240
/**
174241
* @covers ::create
175242
*/

0 commit comments

Comments
 (0)