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: upgrade source in order to use most of PHP 7.2 features
refactor sources and tests
add feature to PHP CS settings
Date: 1 year ago
Size: 2,801 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace
WsdlToPhp\PhpGenerator\Tests\Element;

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());
    }

   
/**
     * @expectedException InvalidArgumentException
     */
   
public function testAddChildWithException()
    {
       
$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());
    }

   
/**
     * @expectedException \TypeError
     */
   
public function testExceptionMessageOnName()
    {
        new
PhpInterface(0);
    }
}


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