1
+ <?php
2
+
3
+ namespace Swaggest \JsonSchema \Tests \PHPUnit \Suite ;
4
+
5
+
6
+ use Swaggest \JsonSchema \Context ;
7
+ use Swaggest \JsonSchema \InvalidValue ;
8
+ use Swaggest \JsonSchema \RemoteRef \Preloaded ;
9
+ use Swaggest \JsonSchema \Schema ;
10
+
11
+ class Issue35Test extends \PHPUnit_Framework_TestCase
12
+ {
13
+ public function testOne ()
14
+ {
15
+ $ options = new Context ();
16
+ $ provider = new Preloaded ();
17
+ $ provider ->setSchemaData ('https://some-domain/Baz/Bar# ' , (object )['type ' => 'integer ' ]);
18
+ $ options ->setRemoteRefProvider ($ provider );
19
+ $ schemaData = (object )[
20
+ 'id ' => 'https://some-domain/Foo/Bar# ' ,
21
+ 'oneOf ' => [
22
+ (object )['$ref ' => '/Baz/Bar# ' ]
23
+ ]
24
+ ];
25
+ $ schema = Schema::import ($ schemaData , $ options );
26
+ $ schema ->in (1 );
27
+
28
+ $ this ->assertSame ('{"id":"https://some-domain/Foo/Bar#","oneOf":[{"type":"integer"}]} ' , json_encode ($ schema , JSON_UNESCAPED_SLASHES ));
29
+
30
+ $ this ->setExpectedException (get_class (new InvalidValue ()));
31
+ $ schema ->in ("not integer " );
32
+ }
33
+
34
+ public function testTwo ()
35
+ {
36
+ $ options = new Context ();
37
+ $ provider = new Preloaded ();
38
+ $ provider ->setSchemaData ('https://some-domain/Baz/Bar ' , (object )['type ' => 'integer ' ]);
39
+ $ options ->setRemoteRefProvider ($ provider );
40
+ $ schemaData = (object )[
41
+ 'id ' => 'https://some-domain/Foo/Bar# ' ,
42
+ 'oneOf ' => [
43
+ (object )['$ref ' => '/Baz/Bar# ' ]
44
+ ]
45
+ ];
46
+ $ schema = Schema::import ($ schemaData , $ options );
47
+ $ schema ->in (1 );
48
+
49
+ $ this ->assertSame ('{"id":"https://some-domain/Foo/Bar#","oneOf":[{"type":"integer"}]} ' , json_encode ($ schema , JSON_UNESCAPED_SLASHES ));
50
+
51
+ $ this ->setExpectedException (get_class (new InvalidValue ()));
52
+ $ schema ->in ("not integer " );
53
+ }
54
+
55
+ public function testThree ()
56
+ {
57
+ $ options = new Context ();
58
+ $ provider = new Preloaded ();
59
+ $ provider ->setSchemaData ('https://some-domain/Baz/Bar ' , (object )['type ' => 'integer ' ]);
60
+ $ options ->setRemoteRefProvider ($ provider );
61
+ $ schemaData = (object )[
62
+ 'id ' => 'https://some-domain/Foo/Bar# ' ,
63
+ 'oneOf ' => [
64
+ (object )['$ref ' => '/Baz/Bar ' ]
65
+ ]
66
+ ];
67
+ $ schema = Schema::import ($ schemaData , $ options );
68
+ $ schema ->in (1 );
69
+
70
+ $ this ->assertSame ('{"id":"https://some-domain/Foo/Bar#","oneOf":[{"type":"integer"}]} ' , json_encode ($ schema , JSON_UNESCAPED_SLASHES ));
71
+
72
+ $ this ->setExpectedException (get_class (new InvalidValue ()));
73
+ $ schema ->in ("not integer " );
74
+ }
75
+
76
+ public function testFour ()
77
+ {
78
+ $ options = new Context ();
79
+ $ provider = new Preloaded ();
80
+ $ provider ->setSchemaData ('https://some-domain/Baz/Bar# ' , (object )['type ' => 'integer ' ]);
81
+ $ options ->setRemoteRefProvider ($ provider );
82
+ $ schemaData = (object )[
83
+ 'id ' => 'https://some-domain/Foo/Bar# ' ,
84
+ 'oneOf ' => [
85
+ (object )['$ref ' => '/Baz/Bar ' ]
86
+ ]
87
+ ];
88
+ $ schema = Schema::import ($ schemaData , $ options );
89
+ $ schema ->in (1 );
90
+
91
+ $ this ->assertSame ('{"id":"https://some-domain/Foo/Bar#","oneOf":[{"type":"integer"}]} ' , json_encode ($ schema , JSON_UNESCAPED_SLASHES ));
92
+
93
+ $ this ->setExpectedException (get_class (new InvalidValue ()));
94
+ $ schema ->in ("not integer " );
95
+ }
96
+
97
+ }
0 commit comments