PHP Classes
elePHPant
Icontem

File: tests/Element/PhpVariableTest.php

Recommend this page to a friend!
  Classes of WsdlToPhp  >  PHP Code Generator  >  tests/Element/PhpVariableTest.php  >  Download  
File: tests/Element/PhpVariableTest.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: 1 year ago
Size: 3,678 bytes
 

Contents

Class file image Download
<?php

namespace WsdlToPhp\PhpGenerator\Tests\Element;

use
WsdlToPhp\PhpGenerator\Element\PhpVariable;
use
WsdlToPhp\PhpGenerator\Tests\TestCase;

class
PhpVariableTest extends TestCase
{
    public function
testGetPhpDeclarationNullValue()
    {
       
$variable = new PhpVariable('foo');

       
$this->assertSame('$foo = null;', $variable->getPhpDeclaration());
    }

    public function
testGetPhpDeclarationTrueValue()
    {
       
$variable = new PhpVariable('foo', true);

       
$this->assertSame('$foo = true;', $variable->getPhpDeclaration());
    }

    public function
testGetPhpDeclarationFalseValue()
    {
       
$variable = new PhpVariable('foo', false);

       
$this->assertSame('$foo = false;', $variable->getPhpDeclaration());
    }

    public function
testGetPhpDeclarationStringOneValue()
    {
       
$variable = new PhpVariable('foo', '1');

       
$this->assertSame('$foo = \'1\';', $variable->getPhpDeclaration());
    }

    public function
testGetPhpDeclarationNumberOneValue()
    {
       
$variable = new PhpVariable('foo', 1);

       
$this->assertSame('$foo = 1;', $variable->getPhpDeclaration());
    }

    public function
testGetPhpDeclarationArray()
    {
       
$variable = new PhpVariable('foo', array(
           
'0',
           
1,
        ));

       
$this->assertSame("\$foo = array (\n 0 => '0',\n 1 => 1,\n);", $variable->getPhpDeclaration());
    }

    public function
testGetPhpDeclarationNewInstance()
    {
       
$variable = new PhpVariable('foo', 'new DOMDocument(\'1.0\', \'utf-8\')');

       
$this->assertSame("\$foo = new DOMDocument('1.0', 'utf-8');", $variable->getPhpDeclaration());
    }

    public function
testGetPhpDeclarationFunctoin()
    {
       
$variable = new PhpVariable('foo', 'is_array(1)');

       
$this->assertSame("\$foo = is_array(1);", $variable->getPhpDeclaration());
    }

    public function
testGetPhpDeclarationClassConstant()
    {
       
$variable = new PhpVariable('foo', 'stdClass::BAR');

       
$this->assertSame("\$foo = stdClass::BAR;", $variable->getPhpDeclaration());
    }

    public function
testGetPhpDeclarationConstant()
    {
       
$variable = new PhpVariable('foo', '::XML_ELEMENT_NODE');

       
$this->assertSame("\$foo = XML_ELEMENT_NODE;", $variable->getPhpDeclaration());
    }

   
/**
     * @expectedException InvalidArgumentException
     */
   
public function testAddChild()
    {
       
$variable = new PhpVariable('Foo', 'bar');

       
$variable->addChild(new PhpVariable('Bar', 'foo'));
    }

    public function
testToStringNullValue()
    {
       
$variable = new PhpVariable('foo');

       
$this->assertSame('$foo = null;', $variable->toString());
    }

    public function
testToStringStringNewsValue()
    {
       
$variable = new PhpVariable('foo', 'news');

       
$this->assertSame('$foo = \'news\';', $variable->toString());
    }

    public function
testToStringFloatValue()
    {
       
$variable = new PhpVariable('foo', 0.4);

       
$this->assertSame('$foo = 0.4;', $variable->toString());
    }

    public function
testCyrillic()
    {
       
$variable = new PhpVariable('????????????????????', 0.4);

       
$this->assertSame('$???????????????????? = 0.4;', $variable->toString());
    }

    public function
test้()
    {
       
$้ = 4;
       
$this->assertEquals(4, $้);
    }

    public function
testExceptionMessageOnName()
    {
        try {
            new
PhpVariable(0);
        } catch (\
InvalidArgumentException $e) {
           
$this->assertSame('Name "0" is invalid when instantiating PhpVariable object', $e->getMessage());
        }
    }
}