|
12 | 12 | use ArrayAccess;
|
13 | 13 | use ArrayObject as SplArrayObject;
|
14 | 14 | use Zend\Code\Exception\InvalidArgumentException;
|
| 15 | +use Zend\Code\Generator\PropertyGenerator; |
| 16 | +use Zend\Code\Generator\PropertyValueGenerator; |
15 | 17 | use Zend\Stdlib\ArrayObject as StdlibArrayObject;
|
16 | 18 | use Zend\Code\Generator\ValueGenerator;
|
17 | 19 |
|
@@ -64,6 +66,38 @@ public function constantsTypeProvider()
|
64 | 66 | ];
|
65 | 67 | }
|
66 | 68 |
|
| 69 | + /** |
| 70 | + * @group #94 |
| 71 | + * @dataProvider validConstantTypesProvider |
| 72 | + */ |
| 73 | + public function testValidConstantTypes($generator, $expectedOutput) |
| 74 | + { |
| 75 | + $propertyGenerator = new PropertyGenerator('FOO', $generator); |
| 76 | + $propertyGenerator->setConst(true); |
| 77 | + $this->assertSame($expectedOutput, $propertyGenerator->generate()); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * @return array |
| 82 | + */ |
| 83 | + public function validConstantTypesProvider() |
| 84 | + { |
| 85 | + return [ |
| 86 | + [new PropertyValueGenerator([], PropertyValueGenerator::TYPE_ARRAY, ValueGenerator::OUTPUT_SINGLE_LINE), " const FOO = array();"], |
| 87 | + [new PropertyValueGenerator([], PropertyValueGenerator::TYPE_ARRAY_LONG, ValueGenerator::OUTPUT_SINGLE_LINE), " const FOO = array();"], |
| 88 | + [new PropertyValueGenerator([], PropertyValueGenerator::TYPE_ARRAY_SHORT, ValueGenerator::OUTPUT_SINGLE_LINE), " const FOO = [];"], |
| 89 | + [new PropertyValueGenerator(true, PropertyValueGenerator::TYPE_BOOL), " const FOO = true;"], |
| 90 | + [new PropertyValueGenerator(true, PropertyValueGenerator::TYPE_BOOLEAN), " const FOO = true;"], |
| 91 | + [new PropertyValueGenerator(1, PropertyValueGenerator::TYPE_INT), " const FOO = 1;"], |
| 92 | + [new PropertyValueGenerator(1, PropertyValueGenerator::TYPE_INTEGER), " const FOO = 1;"], |
| 93 | + [new PropertyValueGenerator(0.1, PropertyValueGenerator::TYPE_DOUBLE), " const FOO = 0.1;"], |
| 94 | + [new PropertyValueGenerator(0.1, PropertyValueGenerator::TYPE_FLOAT), " const FOO = 0.1;"], |
| 95 | + [new PropertyValueGenerator('bar', PropertyValueGenerator::TYPE_STRING), " const FOO = 'bar';"], |
| 96 | + [new PropertyValueGenerator(null, PropertyValueGenerator::TYPE_NULL), " const FOO = null;"], |
| 97 | + [new PropertyValueGenerator('PHP_EOL', PropertyValueGenerator::TYPE_CONSTANT), " const FOO = PHP_EOL;"], |
| 98 | + ]; |
| 99 | + } |
| 100 | + |
67 | 101 | /**
|
68 | 102 | * @return array
|
69 | 103 | */
|
|
0 commit comments