PHP Classes
elePHPant
Icontem

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: issue #7 - improve exception messages providing the current class
Date: 9 months ago
Size: 2,920 bytes
 

Contents

Class file image Download
<?php

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', array(
           
'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(array(
           
'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()
    {
        try {
            new
PhpInterface(0);
        } catch (\
InvalidArgumentException $e) {
           
$this->assertSame('Name "0" is invalid when instantiating PhpInterface object', $e->getMessage());
        }
    }
}