@@ -13,13 +13,19 @@ require __DIR__ . '/../bootstrap.php';
13
13
14
14
15
15
$ class = new ClassType ('Example ' );
16
+
17
+ Assert::false ($ class ->isFinal ());
18
+ Assert::false ($ class ->isAbstract ());
19
+ Assert::same ([], $ class ->getExtends ());
20
+ Assert::same ([], $ class ->getTraits ());
21
+
16
22
$ class
17
23
->setAbstract (TRUE )
18
24
->setFinal (TRUE )
19
25
->setExtends ('ParentClass ' )
20
26
->addImplement ('IExample ' )
21
27
->addImplement ('IOne ' )
22
- ->addTrait ( 'ObjectTrait ' )
28
+ ->setTraits ([ 'ObjectTrait ' ] )
23
29
->addTrait ('AnotherTrait ' , ['sayHello as protected ' ])
24
30
->addComment ("Description of class. \nThis is example \n" )
25
31
->addComment ('@property-read Nette\Forms\Form $form ' )
@@ -28,6 +34,13 @@ $class
28
34
29
35
Assert::same (['ROLE ' => 'admin ' , 'ACTIVE ' => FALSE ], $ class ->getConsts ());
30
36
37
+ Assert::true ($ class ->isFinal ());
38
+ Assert::true ($ class ->isAbstract ());
39
+ Assert::same ('ParentClass ' , $ class ->getExtends ());
40
+ Assert::same (['ObjectTrait ' , 'AnotherTrait ' ], $ class ->getTraits ());
41
+ Assert::count (2 , $ class ->getConstants ());
42
+ Assert::type (Nette \PhpGenerator \Constant::class, $ class ->getConstants ()['ROLE ' ]);
43
+
31
44
$ class ->addConstant ('FORCE_ARRAY ' , new PhpLiteral ('Nette\Utils\Json::FORCE_ARRAY ' ))
32
45
->setVisibility ('private ' )
33
46
->addComment ('Commented ' );
@@ -43,6 +56,8 @@ $p = $class->addProperty('sections', ['first' => TRUE])
43
56
->setStatic (TRUE );
44
57
45
58
Assert::same ($ p , $ class ->getProperty ('sections ' ));
59
+ Assert::true ($ p ->isStatic ());
60
+ Assert::null ($ p ->getVisibility ());
46
61
47
62
$ m = $ class ->addMethod ('getHandle ' )
48
63
->addComment ('Returns file handle. ' )
@@ -51,14 +66,27 @@ $m = $class->addMethod('getHandle')
51
66
->setBody ('return $this->?; ' , ['handle ' ]);
52
67
53
68
Assert::same ($ m , $ class ->getMethod ('getHandle ' ));
54
-
55
- $ class ->addMethod ('getSections ' )
69
+ Assert::true ($ m ->isFinal ());
70
+ Assert::false ($ m ->isStatic ());
71
+ Assert::false ($ m ->isAbstract ());
72
+ Assert::false ($ m ->getReturnReference ());
73
+ Assert::same ('public ' , $ m ->getVisibility ());
74
+ Assert::same ('return $this->handle; ' , $ m ->getBody ());
75
+
76
+ $ m = $ class ->addMethod ('getSections ' )
56
77
->setStatic (TRUE )
57
78
->setVisibility ('protected ' )
58
79
->setReturnReference (TRUE )
59
80
->addBody ('$mode = ?; ' , [123 ])
60
- ->addBody ('return self::$sections; ' )
61
- ->addParameter ('mode ' , new PhpLiteral ('self::ORDER ' ));
81
+ ->addBody ('return self::$sections; ' );
82
+ $ m ->addParameter ('mode ' , new PhpLiteral ('self::ORDER ' ));
83
+
84
+ Assert::false ($ m ->isFinal ());
85
+ Assert::true ($ m ->isStatic ());
86
+ Assert::true ($ m ->getReturnReference ());
87
+ Assert::false ($ m ->getReturnNullable ());
88
+ Assert::null ($ m ->getReturnType ());
89
+ Assert::same ('protected ' , $ m ->getVisibility ());
62
90
63
91
$ method = $ class ->addMethod ('show ' )
64
92
->setAbstract (TRUE );
@@ -87,3 +115,9 @@ $parameters = $method->getParameters();
87
115
Assert::count (2 , $ parameters );
88
116
$ method ->setParameters (array_values ($ parameters ));
89
117
Assert::same ($ parameters , $ method ->getParameters ());
118
+
119
+
120
+ Assert::exception (function () {
121
+ $ class = new ClassType ;
122
+ $ class ->addMethod ('method ' )->setVisibility ('unknown ' );
123
+ }, Nette \InvalidArgumentException::class, 'Argument must be public|protected|private. ' );
0 commit comments