Skip to content

Commit 502e69f

Browse files
committed
tests: added tests for multiline body, constant and property
1 parent 657fada commit 502e69f

File tree

7 files changed

+47
-4
lines changed

7 files changed

+47
-4
lines changed

tests/PhpGenerator/Printer.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,22 @@ $class->addConstant('FORCE_ARRAY', new PhpLiteral('Nette\Utils\Json::FORCE_ARRAY
2626
->setVisibility('private')
2727
->addComment('Commented');
2828

29+
$class->addConstant('MULTILINE', ['aaaaaaaaaaaa' => 1, 'bbbbbbbbbbb' => 2, 'cccccccccccccc' => 3, 'dddddddddddd' => 4, 'eeeeeeeeeeee' => 5]);
30+
2931
$class->addProperty('handle')
3032
->setVisibility('private')
3133
->addComment('@var resource orignal file handle');
3234

3335
$class->addProperty('order')
3436
->setValue(new PhpLiteral('RecursiveIteratorIterator::SELF_FIRST'));
3537

38+
$class->addProperty('multiline', ['aaaaaaaaaaaa' => 1, 'bbbbbbbbbbb' => 2, 'cccccccccccccc' => 3, 'dddddddddddd' => 4, 'eeeeeeeeeeee' => 5]);
39+
3640
$class->addMethod('first')
3741
->addComment('@return resource')
3842
->setFinal(true)
3943
->setReturnType('stdClass')
40-
->setBody('return $this->?;', ['handle'])
44+
->setBody("func();\nreturn \$this->?;", ['handle'])
4145
->addParameter('var')
4246
->setTypeHint('stdClass');
4347

@@ -51,7 +55,7 @@ sameFile(__DIR__ . '/expected/Printer.method.expect', $printer->printMethod($cla
5155
$function = new Nette\PhpGenerator\GlobalFunction('func');
5256
$function
5357
->setReturnType('stdClass')
54-
->setBody('return 123;')
58+
->setBody("func();\nreturn 123;")
5559
->addParameter('var')
5660
->setTypeHint('stdClass');
5761

@@ -61,7 +65,7 @@ sameFile(__DIR__ . '/expected/Printer.function.expect', $printer->printFunction(
6165
$closure = new Nette\PhpGenerator\Closure;
6266
$closure
6367
->setReturnType('stdClass')
64-
->setBody('return 123;')
68+
->setBody("func();\nreturn 123;")
6569
->addParameter('var')
6670
->setTypeHint('stdClass');
6771

tests/PhpGenerator/PsrPrinter.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,22 @@ $class->addConstant('FORCE_ARRAY', new PhpLiteral('Nette\Utils\Json::FORCE_ARRAY
2525
->setVisibility('private')
2626
->addComment('Commented');
2727

28+
$class->addConstant('MULTILINE', ['aaaaaaaaaaaa' => 1, 'bbbbbbbbbbb' => 2, 'cccccccccccccc' => 3, 'dddddddddddd' => 4, 'eeeeeeeeeeee' => 5]);
29+
2830
$class->addProperty('handle')
2931
->setVisibility('private')
3032
->addComment('@var resource orignal file handle');
3133

3234
$class->addProperty('order')
3335
->setValue(new PhpLiteral('RecursiveIteratorIterator::SELF_FIRST'));
3436

37+
$class->addProperty('multiline', ['aaaaaaaaaaaa' => 1, 'bbbbbbbbbbb' => 2, 'cccccccccccccc' => 3, 'dddddddddddd' => 4, 'eeeeeeeeeeee' => 5]);
38+
3539
$class->addMethod('first')
3640
->addComment('@return resource')
3741
->setFinal(true)
3842
->setReturnType('stdClass')
39-
->setBody('return $this->?;', ['handle'])
43+
->setBody("func();\nreturn \$this->?;", ['handle'])
4044
->addParameter('var')
4145
->setTypeHint('stdClass');
4246

tests/PhpGenerator/expected/Printer.class.expect

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,34 @@ final class Example extends ParentClass implements IExample
1111

1212
/** Commented */
1313
private const FORCE_ARRAY = Nette\Utils\Json::FORCE_ARRAY;
14+
const MULTILINE = [
15+
'aaaaaaaaaaaa' => 1,
16+
'bbbbbbbbbbb' => 2,
17+
'cccccccccccccc' => 3,
18+
'dddddddddddd' => 4,
19+
'eeeeeeeeeeee' => 5,
20+
];
1421

1522
/** @var resource orignal file handle */
1623
private $handle;
1724

1825
public $order = RecursiveIteratorIterator::SELF_FIRST;
1926

27+
public $multiline = [
28+
'aaaaaaaaaaaa' => 1,
29+
'bbbbbbbbbbb' => 2,
30+
'cccccccccccccc' => 3,
31+
'dddddddddddd' => 4,
32+
'eeeeeeeeeeee' => 5,
33+
];
34+
2035

2136
/**
2237
* @return resource
2338
*/
2439
final public function first(stdClass $var): stdClass
2540
{
41+
func();
2642
return $this->handle;
2743
}
2844

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
function (stdClass $var): stdClass {
2+
func();
23
return 123;
34
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
function func(stdClass $var): stdClass
22
{
3+
func();
34
return 123;
45
}

tests/PhpGenerator/expected/Printer.method.expect

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
*/
44
final public function first(stdClass $var): stdClass
55
{
6+
func();
67
return $this->handle;
78
}

tests/PhpGenerator/expected/PsrPrinter.class.expect

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,33 @@ final class Example extends ParentClass implements IExample
1111

1212
/** Commented */
1313
private const FORCE_ARRAY = Nette\Utils\Json::FORCE_ARRAY;
14+
const MULTILINE = [
15+
'aaaaaaaaaaaa' => 1,
16+
'bbbbbbbbbbb' => 2,
17+
'cccccccccccccc' => 3,
18+
'dddddddddddd' => 4,
19+
'eeeeeeeeeeee' => 5,
20+
];
1421

1522
/** @var resource orignal file handle */
1623
private $handle;
1724

1825
public $order = RecursiveIteratorIterator::SELF_FIRST;
1926

27+
public $multiline = [
28+
'aaaaaaaaaaaa' => 1,
29+
'bbbbbbbbbbb' => 2,
30+
'cccccccccccccc' => 3,
31+
'dddddddddddd' => 4,
32+
'eeeeeeeeeeee' => 5,
33+
];
34+
2035
/**
2136
* @return resource
2237
*/
2338
final public function first(stdClass $var): stdClass
2439
{
40+
func();
2541
return $this->handle;
2642
}
2743

0 commit comments

Comments
 (0)