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 = <<<'JSON'
22+ {
23+ "type": "object",
24+ "description": "Description with $dollar sign",
25+ "properties": {
26+ "foo": {
27+ "type": "string"
28+ }
29+ }
30+ }
31+ JSON;
32+
33+ $ appPath = realpath (__DIR__ . '/../../Tmp ' ) . '/Issue59 ' ;
34+ $ appNs = 'Swaggest\PhpCodeBuilder\Tests\Tmp \\Issue59 ' ;
35+
36+ $ app = new PhpApp ();
37+ $ app ->setNamespaceRoot ($ appNs , '. ' );
38+
39+ $ schema = Schema::import (json_decode ($ schemaJson ));
40+ $ builder = new PhpBuilder ();
41+ $ builder ->buildSetters = false ;
42+ $ builder ->makeEnumConstants = true ;
43+ $ builder ->skipSchemaDescriptions = false ;
44+
45+ $ builder ->classCreatedHook = new ClassHookCallback (
46+ function (PhpClass $ class , $ path , $ schema ) use ($ app , $ appNs ) {
47+ $ class ->setNamespace ($ appNs );
48+ if ('# ' === $ path ) {
49+ $ class ->setName ('Sample ' ); // Class name for root schema
50+ }
51+ $ app ->addClass ($ class );
52+ }
53+ );
54+
55+
56+ $ builder ->getType ($ schema );
57+
58+ $ app ->clearOldFiles ($ appPath );
59+ $ app ->store ($ appPath );
60+
61+ exec ('git diff ' . $ appPath , $ out );
62+ $ out = implode ("\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