Вход Регистрация
Файл: gapps/vendor/phpdocumentor/reflection-docblock/tests/unit/DocBlock/DescriptionFactoryTest.php
Строк: 245
<?php
/**
 * This file is part of phpDocumentor.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright 2010-2015 Mike van Riel<mike@phpdoc.org>
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
 * @link      http://phpdoc.org
 */

namespace phpDocumentorReflectionDocBlock;

use 
Mockery as m;
use 
phpDocumentorReflectionDocBlockTagsLink;
use 
phpDocumentorReflectionTypesContext;

/**
 * @coversDefaultClass phpDocumentorReflectionDocBlockDescriptionFactory
 * @covers ::<private>
 */
class DescriptionFactoryTest extends PHPUnit_Framework_TestCase
{
    
/**
     * @covers ::__construct
     * @covers ::create
     * @uses         phpDocumentorReflectionDocBlockDescription
     * @dataProvider provideSimpleExampleDescriptions
     */
    
public function testDescriptionCanParseASimpleString($contents)
    {
        
$tagFactory m::mock(TagFactory::class);
        
$tagFactory->shouldReceive('create')->never();

        
$factory     = new DescriptionFactory($tagFactory);
        
$description $factory->create($contents, new Context(''));

        
$this->assertSame($contents$description->render());
    }

    
/**
     * @covers ::__construct
     * @covers ::create
     * @uses         phpDocumentorReflectionDocBlockDescription
     * @dataProvider provideEscapeSequences
     */
    
public function testEscapeSequences($contents$expected)
    {
        
$tagFactory m::mock(TagFactory::class);
        
$tagFactory->shouldReceive('create')->never();

        
$factory     = new DescriptionFactory($tagFactory);
        
$description $factory->create($contents, new Context(''));

        
$this->assertSame($expected$description->render());
    }

    
/**
     * @covers ::__construct
     * @covers ::create
     * @uses   phpDocumentorReflectionDocBlockDescription
     * @uses   phpDocumentorReflectionDocBlockTagsLink
     * @uses   phpDocumentorReflectionDocBlockTagsBaseTag
     * @uses   phpDocumentorReflectionDocBlockTagsFormatterPassthroughFormatter
     * @uses   phpDocumentorReflectionTypesContext
     */
    
public function testDescriptionCanParseAStringWithInlineTag()
    {
        
$contents   'This is text for a {@link http://phpdoc.org/ description} that uses an inline tag.';
        
$context    = new Context('');
        
$tagFactory m::mock(TagFactory::class);
        
$tagFactory->shouldReceive('create')
            ->
once()
            ->
with('@link http://phpdoc.org/ description'$context)
            ->
andReturn(new Link('http://phpdoc.org/', new Description('description')))
        ;

        
$factory     = new DescriptionFactory($tagFactory);
        
$description $factory->create($contents$context);

        
$this->assertSame($contents$description->render());
    }

    
/**
     * @covers ::__construct
     * @covers ::create
     * @uses   phpDocumentorReflectionDocBlockDescription
     * @uses   phpDocumentorReflectionDocBlockTagsLink
     * @uses   phpDocumentorReflectionDocBlockTagsBaseTag
     * @uses   phpDocumentorReflectionDocBlockTagsFormatterPassthroughFormatter
     * @uses   phpDocumentorReflectionTypesContext
     */
    
public function testDescriptionCanParseAStringStartingWithInlineTag()
    {
        
$contents   '{@link http://phpdoc.org/ This} is text for a description that starts with an inline tag.';
        
$context    = new Context('');
        
$tagFactory m::mock(TagFactory::class);
        
$tagFactory->shouldReceive('create')
            ->
once()
            ->
with('@link http://phpdoc.org/ This'$context)
            ->
andReturn(new Link('http://phpdoc.org/', new Description('This')))
        ;

        
$factory     = new DescriptionFactory($tagFactory);
        
$description $factory->create($contents$context);

        
$this->assertSame($contents$description->render());
    }

    
/**
     * @covers ::__construct
     * @covers ::create
     * @uses   phpDocumentorReflectionDocBlockDescription
     */
    
public function testIfSuperfluousStartingSpacesAreRemoved()
    {
        
$factory         = new DescriptionFactory(m::mock(TagFactory::class));
        
$descriptionText = <<<DESCRIPTION
This is a multiline
  description that you commonly
  see with tags.

      It does have a multiline code sample
      that should align, no matter what

  All spaces superfluous spaces on the
  second and later lines should be
  removed but the code sample should
  still be indented.
DESCRIPTION;

        
$expectedDescription = <<<DESCRIPTION
This is a multiline
description that you commonly
see with tags.

    It does have a multiline code sample
    that should align, no matter what

All spaces superfluous spaces on the
second and later lines should be
removed but the code sample should
still be indented.
DESCRIPTION;

        
$description $factory->create($descriptionText, new Context(''));

        
$this->assertSame($expectedDescription$description->render());
    }

    
/**
     * Provides a series of example strings that the parser should correctly interpret and return.
     *
     * @return string[][]
     */
    
public function provideSimpleExampleDescriptions()
    {
        return [
            [
'This is text for a description.'],
            [
'This is text for a description containing { that is literal.'],
            [
'This is text for a description containing } that is literal.'],
            [
'This is text for a description with {just a text} that is not a tag.'],
        ];
    }

    public function 
provideEscapeSequences()
    {
        return [
            [
'This is text for a description with a {@}.''This is text for a description with a @.'],
            [
'This is text for a description with a {}.''This is text for a description with a }.'],
        ];
    }
}
Онлайн: 0
Реклама