PHP Classes

File: tests/Element/PhpAnnotationTest.php

Recommend this page to a friend!
  Classes of WsdlToPhp  >  PHP Code Generator  >  tests/Element/PhpAnnotationTest.php  >  Download  
File: tests/Element/PhpAnnotationTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: PHP Code Generator
Generate PHP code elements programatically
Author: By
Last change: issue #11 - implement type hinted class property,
refactor type hinted elements,
refactor assigned value elements,
refactor access restricted elements,
refactor AbstractComponent and inherited classes
format source code using PHP CS fixer @PhpCsFixer rule
Date: 8 months ago
Size: 3,603 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace
WsdlToPhp\PhpGenerator\Tests\Element;

use
InvalidArgumentException;
use
TypeError;
use
WsdlToPhp\PhpGenerator\Element\PhpAnnotation;
use
WsdlToPhp\PhpGenerator\Tests\TestCase;

/**
 * @internal
 * @coversDefaultClass
 */
class PhpAnnotationTest extends TestCase
{
    public function
testGetOneLinePhpDeclaration()
    {
       
$annotation = new PhpAnnotation(PhpAnnotation::NO_NAME, 'This sample annotation is on one line');

       
$this->assertSame(' * This sample annotation is on one line', $annotation->getPhpDeclaration());
    }

    public function
testGetOneLinePhpDeclarationWithName()
    {
       
$annotation = new PhpAnnotation('author', 'PhpTeam');

       
$this->assertSame(' * @author PhpTeam', $annotation->getPhpDeclaration());
    }

    public function
testGetSeveralLinesPhpDeclaration()
    {
       
$annotation = new PhpAnnotation(PhpAnnotation::NO_NAME, str_repeat('This sample annotation is on one line ', 7));

       
$this->assertSame(" * This sample annotation is on one line This sample annotation is on one line This\n".
                         
" * sample annotation is on one line This sample annotation is on one line This\n".
                         
" * sample annotation is on one line This sample annotation is on one line This\n".
                         
' * sample annotation is on one line', $annotation->getPhpDeclaration());
    }

    public function
testGetSeveralLinesWithNamePhpDeclaration()
    {
       
$annotation = new PhpAnnotation('description', str_repeat('This sample annotation is on one line ', 7));

       
$this->assertSame(' * @description This sample annotation is on one line This sample annotation is on one line This sample annotation is on one line This sample annotation is on one line This sample annotation is on one line This sample annotation is on one line This sample annotation is on one line', $annotation->getPhpDeclaration());
    }

    public function
testGetSeveralLinesLargerWithNamePhpDeclaration()
    {
       
$annotation = new PhpAnnotation('description', str_repeat('This sample annotation is on one line ', 7));

       
$this->assertSame(' * @description This sample annotation is on one line This sample annotation is on one line This sample annotation is on one line This sample annotation is on one line This sample annotation is on one line This sample annotation is on one line This sample annotation is on one line', $annotation->getPhpDeclaration());
    }

    public function
testAddChildWithException()
    {
       
$this->expectException(InvalidArgumentException::class);

       
$annotation = new PhpAnnotation('date', '2015-06-02');

       
$annotation->addChild($annotation);
    }

    public function
testToString()
    {
       
$annotation = new PhpAnnotation(PhpAnnotation::NO_NAME, 'This sample annotation is on one line');

       
$this->assertSame(' * This sample annotation is on one line', $annotation->toString());
    }

    public function
testToStringMatchesStringCasting()
    {
       
$annotation = new PhpAnnotation(PhpAnnotation::NO_NAME, 'This sample annotation is on one line');

       
$this->assertSame((string) $annotation, $annotation->toString());
    }

    public function
testHasContent()
    {
       
$annotation = new PhpAnnotation(PhpAnnotation::NO_NAME, 'This sample annotation is on one line');

       
$this->assertTrue($annotation->hasContent());
    }

    public function
testExceptionMessageOnName()
    {
       
$this->expectException(TypeError::class);

        new
PhpAnnotation(0, '');
    }
}

For more information send a message to info at phpclasses dot org.