PHP Classes

File: tests/Element/PhpAnnotationTest.php

Recommend this page to a friend!
  Packages 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: Refactor docker container to be able to run any PHP version from 7.4 (#14)

Thanks AI for 😄:
- update Dockerfile
- update docker-compose
- create Makefile

Update code with:
- CS Fixer
- Rector

#Refactor docker container to be able to run any PHP version from 7.4
Date: 5 months ago
Size: 3,563 bytes
 

 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace WsdlToPhp\PhpGenerator\Tests\Element;

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, '');
    }
}