1+ <?php 
2+ 
3+ namespace  Swaggest \PhpCodeBuilder \Tests \PHPUnit \Issues ;
4+ 
5+ use  Swaggest \JsonSchema \Exception \ConstException ;
6+ use  Swaggest \JsonSchema \Exception \ObjectException ;
7+ use  Swaggest \JsonSchema \Schema ;
8+ use  Swaggest \PhpCodeBuilder \App \PhpApp ;
9+ use  Swaggest \PhpCodeBuilder \JsonSchema \ClassHookCallback ;
10+ use  Swaggest \PhpCodeBuilder \JsonSchema \PhpBuilder ;
11+ use  Swaggest \PhpCodeBuilder \PhpClass ;
12+ use  Swaggest \PhpCodeBuilder \Tests \Tmp \Issue59 \Sample ;
13+ 
14+ /** 
15+  * @see https://github.com/swaggest/php-code-builder/issues/59 
16+  */ 
17+ class  Issue59Test extends  \PHPUnit_Framework_TestCase
18+ {
19+     function  testIssue59 ()
20+     {
21+         $ schemaJson
22+ { 
23+   "type": "object", 
24+   "description": "Description with $dollar sign", 
25+   "properties": { 
26+     "foo": { 
27+       "type": "string" 
28+     } 
29+   } 
30+ } 
31+ JSON;
32+ 
33+         $ appPathrealpath (__DIR__  . '/../../Tmp ' ) . '/Issue59 ' ;
34+         $ appNs'Swaggest\PhpCodeBuilder\Tests\Tmp \\Issue59 ' ;
35+ 
36+         $ appnew  PhpApp ();
37+         $ appsetNamespaceRoot ($ appNs'. ' );
38+ 
39+         $ schemaimport (json_decode ($ schemaJson
40+         $ buildernew  PhpBuilder ();
41+         $ builderbuildSetters  = false ;
42+         $ buildermakeEnumConstants  = true ;
43+         $ builderskipSchemaDescriptions  = false ;
44+ 
45+         $ builderclassCreatedHook  = new  ClassHookCallback (
46+             function  (PhpClass $ class$ path$ schemause  ($ app$ appNs
47+                 $ classsetNamespace ($ appNs
48+                 if  ('# '  === $ path
49+                     $ classsetName ('Sample ' ); // Class name for root schema 
50+                 }
51+                 $ appaddClass ($ class
52+             }
53+         );
54+ 
55+ 
56+         $ buildergetType ($ schema
57+ 
58+         $ appclearOldFiles ($ appPath
59+         $ appstore ($ appPath
60+ 
61+         exec ('git diff  '  . $ appPath$ out
62+         $ outimplode ("\n" , $ out
63+         $ this assertSame ('' , $ out"Generated files changed " );
64+     }
65+ 
66+ 
67+     function  testGeneratedValid ()
68+     {
69+         Sample::import ((object )array ('foo '  => 'abc ' ));
70+     }
71+ 
72+ }
0 commit comments