File: tests/Element/PhpInterfaceTest.php

Recommend this page to a friend!
  Classes of WsdlToPhp  >  PHP Code Generator  >  tests/Element/PhpInterfaceTest.php  >  Download  
File: tests/Element/PhpInterfaceTest.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: 26 days ago
Size: 2,843 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace
WsdlToPhp\PhpGenerator\Tests\Element;

use
InvalidArgumentException;
use
TypeError;
use
WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock;
use
WsdlToPhp\PhpGenerator\Element\PhpConstant;
use
WsdlToPhp\PhpGenerator\Element\PhpMethod;
use
WsdlToPhp\PhpGenerator\Element\PhpProperty;
use
WsdlToPhp\PhpGenerator\Element\PhpInterface;
use
WsdlToPhp\PhpGenerator\Tests\TestCase;

class
PhpInterfaceTest extends TestCase
{
    public function
testSimpleInterface()
    {
       
$interface = new PhpInterface('Foo');

       
$this->assertSame('interface Foo', $interface->getPhpDeclaration());
    }

    public function
testSimpleInterfaceNotAbstract()
    {
       
$interface = new PhpInterface('Foo', true);

       
$this->assertSame('interface Foo', $interface->getPhpDeclaration());
    }

    public function
testSimpleInterfaceExtendsStringBar()
    {
       
$interface = new PhpInterface('Foo', false, 'Bar');

       
$this->assertSame('interface Foo', $interface->getPhpDeclaration());
    }

    public function
testSimpleInterfaceExtendsBarImplementsStringDemo()
    {
       
$interface = new PhpInterface('Foo', false, 'Bar', [
           
'Demo',
        ]);

       
$this->assertSame('interface Foo extends Demo', $interface->getPhpDeclaration());
    }

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

       
$interface = new PhpInterface('Foo');

       
$interface->addChild(new PhpProperty('Bar'));
    }

    public function
testAddChildMethod()
    {
       
$interface = new PhpInterface('Foo');

       
$interface->addChild(new PhpMethod('Bar'));

       
$this->assertCount(1, $interface->getChildren());
    }

    public function
testAddChildConstant()
    {
       
$interface = new PhpInterface('Foo');

       
$interface->addChild(new PhpConstant('Bar'));

       
$this->assertCount(1, $interface->getChildren());
    }

    public function
testAddChildAnnotationBlock()
    {
       
$interface = new PhpInterface('Foo');

       
$interface->addChild(new PhpAnnotationBlock([
           
'Bar',
        ]));

       
$this->assertCount(1, $interface->getChildren());
    }

    public function
testAddChildString()
    {
       
$interface = new PhpInterface('Foo');

       
$interface->addChild("\n");

       
$this->assertCount(1, $interface->getChildren());
    }

    public function
testSimpleIntefaceEmptyPublicMethodToString()
    {
       
$interface = new PhpInterface('Foo');

       
$interface->addChild(new PhpMethod('bar'));

       
$this->assertSame("interface Foo\n{\n public function bar();\n}", $interface->toString());
    }

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

        new
PhpInterface(0);
    }
}


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