public function test_get_header() { $property = new ClassGenProperty('name'); $expected = ClassGenGenerator::$indentation . 'public $name = NULL;' . PHP_EOL; $this->assertEquals($expected, $property->get_header(), "empty properties should be null"); $property->set_value('value'); $expected = ClassGenGenerator::$indentation . 'public $name = \'value\';' . PHP_EOL; $this->assertEquals($expected, $property->get_header(), "property values should be assigned"); $property->set_static(); $expected = ClassGenGenerator::$indentation . 'public static $name = \'value\';' . PHP_EOL; $this->assertEquals($expected, $property->get_header(), "property should be static"); $property->set_const(); $expected = ClassGenGenerator::$indentation . 'const NAME = \'value\';' . PHP_EOL; $this->assertEquals($expected, $property->get_header(), "constants should be uppercased"); $property = new ClassGenProperty('name'); $property->set_value(['key' => 'value']); $expected = ClassGenGenerator::$indentation . 'public $name = ' . PHP_EOL . ClassGenGenerator::$indentation . ClassGenGenerator::$indentation . 'array (' . PHP_EOL . ClassGenGenerator::$indentation . ClassGenGenerator::$indentation . " 'key' => 'value'," . PHP_EOL . ClassGenGenerator::$indentation . ClassGenGenerator::$indentation . ");" . PHP_EOL; $this->assertEquals($expected, $property->get_header(), "arrays should be formatted properly"); }
public function test_add_property() { $generator = new ClassGenGenerator($this->class, '/tmp/testClass.php'); $property = new ClassGenProperty('p1'); $property->set_public(); $generator->add_property($property); $property = new ClassGenProperty('p2'); $property->set_protected(); $generator->add_property($property); $property = new ClassGenProperty('p3'); $property->set_private(); $generator->add_property($property); $property = new ClassGenProperty('p4'); $property->set_const(); $generator->add_property($property); $property = new ClassGenProperty('p5'); $property->set_static(true); $generator->add_property($property); $property = new ClassGenProperty('p6'); $property->visibility = 'super private'; $generator->add_property($property); $fileContents = $generator->get_file_contents(); $expectedContents = '<?php class test { const P4 = NULL; public static $p5 = NULL; public $p1 = NULL; protected $p2 = NULL; private $p3 = NULL; } ?>'; $this->assertEquals($expectedContents, $fileContents, "class properties should be included and sorted correctly"); }