Skip to content

Commit c0b2934

Browse files
committed
added tests
1 parent 846028e commit c0b2934

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/**
4+
* Test: empty namespaces.
5+
*/
6+
7+
use Nette\PhpGenerator\ClassType;
8+
use Nette\PhpGenerator\PhpNamespace;
9+
use Tester\Assert;
10+
11+
require __DIR__ . '/../bootstrap.php';
12+
13+
14+
// no namespace
15+
$class = new ClassType('Example');
16+
$class
17+
->setExtends('\ParentClass')
18+
->addImplement('One')
19+
->addImplement('\Two')
20+
->addTrait('Three')
21+
->addTrait('\Four');
22+
23+
$class->addMethod('one')
24+
->setReturnType('One');
25+
26+
$method = $class->addMethod('two')
27+
->setReturnType('\Two');
28+
29+
$method->addParameter('one')
30+
->setTypeHint('One');
31+
32+
$method->addParameter('two')
33+
->setTypeHint('\Two');
34+
35+
Assert::matchFile(__DIR__ . '/PhpNamespace.fqn1.expect', (string) $class);
36+
37+
38+
// global namespace
39+
$class = new ClassType('Example', new PhpNamespace);
40+
$class
41+
->setExtends('\ParentClass')
42+
->addImplement('One')
43+
->addImplement('\Two')
44+
->addTrait('Three')
45+
->addTrait('\Four');
46+
47+
$class->addMethod('one')
48+
->setReturnType('One');
49+
50+
$method = $class->addMethod('two')
51+
->setReturnType('\Two');
52+
53+
$method->addParameter('one')
54+
->setTypeHint('One');
55+
56+
$method->addParameter('two')
57+
->setTypeHint('\Two');
58+
59+
Assert::matchFile(__DIR__ . '/PhpNamespace.fqn2.expect', (string) $class);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Example extends ParentClass implements One, Two
2+
{
3+
use Three;
4+
use Four;
5+
6+
7+
public function one(): One
8+
{
9+
}
10+
11+
12+
public function two(One $one, Two $two): Two
13+
{
14+
}
15+
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Example extends ParentClass implements One, Two
2+
{
3+
use Three;
4+
use Four;
5+
6+
7+
public function one(): One
8+
{
9+
}
10+
11+
12+
public function two(One $one, Two $two): Two
13+
{
14+
}
15+
16+
}

tests/PhpGenerator/PhpNamespace.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ foreach (array('String', 'string', 'int', 'float', 'bool', 'array', 'callable',
2828

2929
$namespace = new PhpNamespace('Foo');
3030

31+
Assert::same('\A', $namespace->unresolveName('\A'));
3132
Assert::same('\A', $namespace->unresolveName('A'));
3233
Assert::same('A', $namespace->unresolveName('foo\A'));
3334

3435
$namespace->addUse('Bar\C');
3536

3637
Assert::same('\Bar', $namespace->unresolveName('Bar'));
38+
Assert::same('C', $namespace->unresolveName('\bar\C'));
3739
Assert::same('C', $namespace->unresolveName('bar\C'));
3840
Assert::same('C\D', $namespace->unresolveName('Bar\C\D'));
3941

0 commit comments

Comments
 (0)