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: Implement declare statement,
Code requires PHP 7.4,
Code cleaning and various tests
Date: 1 month ago
Size: 3,313 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;

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
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.