File: tests/Element/PhpFileTest.php

Recommend this page to a friend!
  Classes of WsdlToPhp  >  PHP Code Generator  >  tests/Element/PhpFileTest.php  >  Download  
File: tests/Element/PhpFileTest.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,466 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace
WsdlToPhp\PhpGenerator\Tests\Element;

use
WsdlToPhp\PhpGenerator\Element\PhpClass;
use
WsdlToPhp\PhpGenerator\Element\PhpFunction;
use
WsdlToPhp\PhpGenerator\Element\PhpVariable;
use
WsdlToPhp\PhpGenerator\Element\PhpMethod;
use
WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock;
use
WsdlToPhp\PhpGenerator\Element\PhpConstant;
use
WsdlToPhp\PhpGenerator\Element\PhpFile;
use
WsdlToPhp\PhpGenerator\Tests\TestCase;

class
PhpFileTest extends TestCase
{
   
/**
     * @expectedException InvalidArgumentException
     */
   
public function testException()
    {
       
$file = new PhpFile('foo');

       
$file->addChild(new PhpMethod('Foo'));
    }

    public function
testVariableToString()
    {
       
$file = new PhpFile('foo');

       
$file->addChild(new PhpVariable('foo', 1));

       
$this->assertSame("<?php\n\$foo = 1;\n", $file->toString());
    }

    public function
testConstantToString()
    {
       
$file = new PhpFile('foo');

       
$file->addChild(new PhpConstant('foo', 1));

       
$this->assertSame("<?php\ndefine('foo', 1);\n", $file->toString());
    }

    public function
testFunctionToString()
    {
       
$file = new PhpFile('foo');

       
$file->addChild(new PhpFunction('foo', [
           
'foo',
           
'sample',
           
'demo',
        ]));

       
$this->assertSame("<?php\nfunction foo(\$foo, \$sample, \$demo)\n{\n}\n", $file->toString());
    }

    public function
testAnnotationBlockToString()
    {
       
$file = new PhpFile('foo');

       
$file->addChild(new PhpAnnotationBlock([
           
'date is the key',
           
'time is the core key',
        ]));

       
$this->assertSame("<?php\n/**\n * date is the key\n * time is the core key\n */\n", $file->toString());
    }

    public function
testAnnotationClassMethodBlockToString()
    {
       
$file = new PhpFile('foo');

       
$file->addChild(new PhpAnnotationBlock([
           
'date is the key',
           
'time is the core key',
        ]));

       
$class = new PhpClass('Foo');
       
$class->addChild(new PhpMethod('Bar'));
       
$file->addChild($class);

       
$this->assertSame("<?php\n/**\n * date is the key\n * time is the core key\n */\nclass Foo\n{\n public function Bar()\n {\n }\n}\n", $file->toString());
    }

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


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