Skip to content

Commit fbd1e66

Browse files
committed
tests: improved
1 parent a2e6a0c commit fbd1e66

File tree

5 files changed

+183
-0
lines changed

5 files changed

+183
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Nette\PhpGenerator\Extractor;
6+
use Nette\PhpGenerator\PhpNamespace;
7+
use Nette\PhpGenerator\Printer;
8+
9+
require __DIR__ . '/../bootstrap.php';
10+
11+
12+
$file = (new Extractor(file_get_contents(__DIR__ . '/fixtures/bodies.php')))->extractAll();
13+
$classes = $file->getClasses();
14+
15+
$namespace = new PhpNamespace('Nette');
16+
$namespace->addUse('Abc\a\FOO'); // must not be confused with constant
17+
$namespace->addUse('Abc\a\func'); // must not be confused with func
18+
$namespace->add(reset($classes));
19+
20+
$printer = new Printer;
21+
sameFile(__DIR__ . '/expected/Factory.fromCode.bodies.resolving.expect', $printer->printNamespace($namespace));

tests/PhpGenerator/expected/ClassType.from.bodies.expect

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ abstract class Class7
3737
}
3838

3939

40+
public function resolving($a = Abc\a\FOO, self $b = null, $c = self::FOO)
41+
{
42+
echo FOO;
43+
echo \FOO;
44+
echo \Abc\a\FOO;
45+
echo \Nette\FOO;
46+
47+
// functions
48+
func();
49+
\func();
50+
\Abc\a\func();
51+
\Nette\func();
52+
53+
// classes
54+
$x = new \Abc\MyClass;
55+
$y = new \stdClass;
56+
$z = \Nette\Utils\ArrayHash::class;
57+
}
58+
59+
4060
public function complex()
4161
{
4262
echo 1;

tests/PhpGenerator/expected/Factory.fromCode.bodies.expect

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ abstract class Class7
4545
}
4646

4747

48+
public function resolving($a = \Abc\a\FOO, self $b = null, $c = self::FOO)
49+
{
50+
echo FOO;
51+
echo \FOO;
52+
echo \Abc\a\FOO;
53+
echo \Nette\FOO;
54+
55+
// functions
56+
func();
57+
\func();
58+
\Abc\a\func();
59+
\Nette\func();
60+
61+
// classes
62+
$x = new \Abc\MyClass;
63+
$y = new \stdClass;
64+
$z = \Nette\Utils\ArrayHash::class;
65+
}
66+
67+
4868
public function complex()
4969
{
5070
echo 1;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
namespace Nette;
2+
3+
use Abc\a\FOO;
4+
use Abc\a\func;
5+
6+
abstract class Class7
7+
{
8+
abstract public function abstractFun();
9+
10+
11+
public function emptyFun()
12+
{
13+
}
14+
15+
16+
public function emptyFun2()
17+
{
18+
}
19+
20+
21+
public function simple()
22+
{
23+
return 1;
24+
}
25+
26+
27+
public function simple2()
28+
{
29+
return 1;
30+
}
31+
32+
33+
public function long()
34+
{
35+
if ($member instanceof \Abc\Method) {
36+
$s = [1, 2, 3];
37+
}
38+
/*
39+
$this->methods[$member->getName()] = $member;
40+
*/
41+
throw new \Nette\InvalidArgumentException('Argument must be Method|Property|Constant.');
42+
}
43+
44+
45+
public function resolving($a = \Abc\a\FOO, self $b = null, $c = self::FOO)
46+
{
47+
echo FOO;
48+
echo \FOO;
49+
echo \Abc\a\FOO;
50+
echo \Nette\FOO;
51+
52+
// functions
53+
func();
54+
\func();
55+
\Abc\a\func();
56+
\Nette\func();
57+
58+
// classes
59+
$x = new \Abc\MyClass;
60+
$y = new \stdClass;
61+
$z = \Nette\Utils\ArrayHash::class;
62+
}
63+
64+
65+
public function complex()
66+
{
67+
echo 1;
68+
// single line comment
69+
70+
// spaces - indent
71+
// spaces - indent
72+
73+
/* multi
74+
line
75+
comment */
76+
if (
77+
$a
78+
&& $b + $c)
79+
{}
80+
81+
/** multi
82+
line
83+
comment */
84+
// Alias Method will not be resolved in comment
85+
if ($member instanceof \Abc\Method) {
86+
$s1 = "\na\n\tb\n\t\tc\n";
87+
$s2 = "\na\n\t{$b}\n\t\t$c\n";
88+
89+
$s3 = "a\n\t{$b}\n\t\t$c"
90+
;
91+
$s3 = "a\n\tb\n\t\tc"
92+
;
93+
// inline HTML is not supported
94+
?>
95+
a
96+
b
97+
c
98+
<?php
99+
}
100+
throw new \Nette\InvalidArgumentException();
101+
}
102+
}

tests/PhpGenerator/fixtures/bodies.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ function long()
3434
throw new Nette\InvalidArgumentException('Argument must be Method|Property|Constant.');
3535
}
3636

37+
function resolving($a = a\FOO, self $b = null, $c = self::FOO)
38+
{
39+
// constants
40+
echo FOO;
41+
echo \FOO;
42+
echo a\FOO;
43+
echo \Nette\FOO;
44+
45+
// functions
46+
func();
47+
\func();
48+
a\func();
49+
\Nette\func();
50+
51+
// classes
52+
$x = new MyClass;
53+
$y = new \stdClass;
54+
$z = Nette\Utils\ArrayHash::class;
55+
}
56+
3757
function complex()
3858
{
3959
echo 1;

0 commit comments

Comments
 (0)