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 Issue33Test extends \PHPUnit_Framework_TestCase
12+ {
13+ public function testRef () {
14+ $ schemaJson = <<<'JSON'
15+ {
16+ "id": "https://some-domain/Entity/Foo/Bar/Baz/1.1#",
17+ "$schema": "http://json-schema.org/draft-04/schema#",
18+ "allOf": [
19+ {
20+ "$ref": "/Entity/1.1#"
21+ },
22+ {
23+ "type": "object",
24+ "properties": {
25+ "appId": {
26+ "$ref": "/definition/AppID/1.1#"
27+ },
28+ "date": {
29+ "$ref": "/definition/Date/1.1#"
30+ },
31+ "timestamp": {
32+ "$ref": "/definition/Date/UnixTimestamp/1.1#"
33+ }
34+ }
35+ }
36+ ]
37+ }
38+ JSON;
39+ $ provider = new Preloaded ();
40+ $ provider ->setSchemaData ("https://some-domain/Entity/1.1 " , json_decode ('{} ' ));
41+ $ provider ->setSchemaData ("https://some-domain/definition/AppID/1.1 " , json_decode ('{"type":"integer"} ' ));
42+ $ provider ->setSchemaData ("https://some-domain/definition/Date/1.1 " , json_decode ('{} ' ));
43+ $ provider ->setSchemaData ("https://some-domain/definition/Date/UnixTimestamp/1.1 " , json_decode ('{} ' ));
44+
45+ $ options = new Context ();
46+ $ options ->setRemoteRefProvider ($ provider );
47+ $ schema = Schema::import (json_decode ($ schemaJson ), $ options );
48+ $ schema ->in (json_decode ('{"appId":123} ' ));
49+ $ this ->setExpectedException (get_class (new InvalidValue ()));
50+ $ schema ->in (json_decode ('{"appId":"some-string"} ' ));
51+ }
52+
53+ }
0 commit comments