Skip to content

Commit d041c9b

Browse files
committed
add ListResponse and more tests
1 parent cf2cc1c commit d041c9b

32 files changed

+397
-161
lines changed

src/Accessor/PropertyAccessor.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/Builder/SchemaBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function setSchemasEndpointUrl($schemasEndpointUrl)
3939
/**
4040
* @param string $schemaId
4141
*
42-
* @return Schema
42+
* @return \Tmilos\ScimSchema\Model\v1\Schema|\Tmilos\ScimSchema\Model\v2\Schema|Schema
4343
*/
4444
public function get($schemaId)
4545
{

src/Builder/SchemaBuilderV1.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,11 @@ class SchemaBuilderV1 extends SchemaBuilder
20662066
),
20672067
);
20682068

2069+
public function __construct($schemasEndpointUrl = null)
2070+
{
2071+
parent::__construct($schemasEndpointUrl ?: 'http://localhost/'.ScimConstantsV1::ENDPOINT_SCHEMAS);
2072+
}
2073+
20692074
protected function getSchemaClass()
20702075
{
20712076
return Schema::class;

src/Model/ListResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getResources()
7474
public function serializeObject()
7575
{
7676
$result = [
77-
'schemas' => [Schema::LIST_RESPONSE],
77+
'schemas' => $this->getSchemas(),
7878
'totalResults' => $this->totalResults,
7979
'Resources' => [],
8080
];

src/Model/Resource.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ protected static function deserializeCommonAttributes(array $data)
150150
if (isset($arr['externalId'])) {
151151
$result->externalId = $data['externalId'];
152152
}
153-
foreach ($data['schemas'] as $schemaId) {
154-
if ($schemaId != $result->getSchemaId()) {
155-
$result->extensions[$schemaId] = isset($data[$schemaId]) ? $data[$schemaId] : null;
153+
if (isset($data['schemas'])) {
154+
foreach ($data['schemas'] as $schemaId) {
155+
if ($schemaId != $result->getSchemaId()) {
156+
$result->extensions[$schemaId] = isset($data[$schemaId]) ? $data[$schemaId] : null;
157+
}
156158
}
157159
}
158160

src/Model/ServiceProviderConfig.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public function getAuthenticationSchemes()
139139
public function serializeObject()
140140
{
141141
$result = parent::serializeObject();
142+
unset($result['id']);
142143

143144
if ($this->documentationUri) {
144145
$result['documentationUri'] = $this->documentationUri;

src/Model/v1/ListResponse.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Tmilos\ScimSchema\Model\v1;
4+
5+
use Tmilos\ScimSchema\ScimConstantsV1;
6+
7+
class ListResponse extends \Tmilos\ScimSchema\Model\ListResponse
8+
{
9+
public function getSchemaId()
10+
{
11+
return ScimConstantsV1::MESSAGE_LIST_RESPONSE;
12+
}
13+
}

src/Model/v1/Schema.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,23 @@ public function getSchemaId()
1919
{
2020
return ScimConstantsV1::SCHEMA_SCHEMA;
2121
}
22+
23+
public function serializeObject()
24+
{
25+
$parentValue = parent::serializeObject();
26+
27+
$result = [
28+
'id' => $parentValue['id'],
29+
'schema' => ScimConstantsV1::CORE,
30+
];
31+
32+
unset($parentValue['id']);
33+
unset($parentValue['schemas']);
34+
35+
foreach ($parentValue as $k=>$v) {
36+
$result[$k] = $v;
37+
}
38+
39+
return $result;
40+
}
2241
}

src/Model/v1/ServiceProviderConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ class ServiceProviderConfig extends \Tmilos\ScimSchema\Model\ServiceProviderConf
1717
{
1818
public function getSchemaId()
1919
{
20-
return ScimConstantsV1::SCHEMA_SERVICE_PROVIDER_CONFIG;
20+
return ScimConstantsV1::CORE;
2121
}
2222
}

src/Model/v2/ListResponse.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Tmilos\ScimSchema\Model\v2;
4+
5+
use Tmilos\ScimSchema\ScimConstantsV2;
6+
7+
class ListResponse extends \Tmilos\ScimSchema\Model\ListResponse
8+
{
9+
public function getSchemaId()
10+
{
11+
return ScimConstantsV2::MESSAGE_LIST_RESPONSE;
12+
}
13+
}

src/ScimConstantsV1.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313

1414
abstract class ScimConstantsV1
1515
{
16-
const SCHEMA_USER = 'urn:scim:schemas:core:1.0';
16+
const CORE = 'urn:scim:schemas:core:1.0';
17+
const SCHEMA_USER = 'urn:scim:schemas:core:1.0:User';
1718
const SCHEMA_ENTERPRISE_USER = 'urn:scim:schemas:extension:enterprise:1.0';
18-
const SCHEMA_GROUP = 'urn:scim:schemas:core:1.0';
19-
const SCHEMA_SERVICE_PROVIDER_CONFIG = 'urn:scim:schemas:core:1.0';
20-
const SCHEMA_SCHEMA = 'urn:scim:schemas:core:1.0';
19+
const SCHEMA_GROUP = 'urn:scim:schemas:core:1.0:Group';
20+
const SCHEMA_SERVICE_PROVIDER_CONFIG = 'urn:scim:schemas:core:1.0:Service Provider Configuration';
21+
const SCHEMA_SCHEMA = 'urn:scim:schemas:core:1.0:Schema';
2122

2223
const MESSAGE_LIST_RESPONSE = 'urn:scim:schemas:core:1.0';
2324
const MESSAGE_SEARCH_REQUEST = 'urn:ietf:params:scim:api:messages:2.0:SearchRequest';

tests/Builder/ResourceTypeBuilderTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Tests\Tmilos\ScimSchema\Builder;
44

5+
use Tests\Tmilos\ScimSchema\TestHelper;
56
use Tmilos\ScimSchema\Builder\ResourceTypeBuilder;
67
use Tmilos\ScimSchema\ScimConstants;
78

@@ -17,16 +18,6 @@ public function test_group()
1718
$resourceTypes[] = $builder->build(ScimConstants::RESOURCE_TYPE_SCHEMA)->serializeObject();
1819
$resourceTypes[] = $builder->build(ScimConstants::RESOURCE_TYPE_RESOURCE_TYPE)->serializeObject();
1920

20-
$this->assertEquals($this->getExpected(), $resourceTypes);
21-
}
22-
23-
/**
24-
* @return \stdClass
25-
*/
26-
private function getExpected()
27-
{
28-
$json = file_get_contents(__DIR__.'/resource_type.all.json');
29-
30-
return json_decode($json, true);
21+
$this->assertEquals(TestHelper::getExpected('v2.resource_type.all.json'), $resourceTypes);
3122
}
3223
}

tests/Builder/SchemaBuilderV1Test.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Tests\Tmilos\ScimSchema\Builder;
4+
5+
use Tests\Tmilos\ScimSchema\TestHelper;
6+
use Tmilos\ScimSchema\Builder\SchemaBuilderV1;
7+
8+
class SchemaBuilderV1Test extends \PHPUnit_Framework_TestCase
9+
{
10+
public function test_group()
11+
{
12+
$builder = new SchemaBuilderV1();
13+
$schema = $builder->getGroup()->serializeObject();
14+
15+
TestHelper::compare(TestHelper::getExpected('v1.schema.group.json'), $schema, $this);
16+
}
17+
}

tests/Builder/SchemaBuilderV2Test.php

Lines changed: 7 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Tests\Tmilos\ScimSchema\Builder;
44

5+
use Tests\Tmilos\ScimSchema\TestHelper;
56
use Tmilos\ScimSchema\Builder\SchemaBuilderV2;
67

78
class SchemaBuilderV2Test extends \PHPUnit_Framework_TestCase
@@ -11,130 +12,46 @@ public function test_group()
1112
$builder = new SchemaBuilderV2();
1213
$schema = $builder->getGroup()->serializeObject();
1314

14-
$this->compare($this->getExpectedGroup(), $schema);
15+
TestHelper::compare(TestHelper::getExpected('v2.schema.group.json'), $schema, $this);
1516
}
1617

1718
public function test_user()
1819
{
1920
$builder = new SchemaBuilderV2();
2021
$schema = $builder->getUser()->serializeObject();
2122

22-
$this->compare($this->getExpectedUser(), $schema);
23+
TestHelper::compare(TestHelper::getExpected('v2.schema.user.json'), $schema, $this);
2324
}
2425

2526
public function test_schema()
2627
{
2728
$builder = new SchemaBuilderV2();
2829
$schema = $builder->getSchema()->serializeObject();
2930

30-
$this->compare($this->getExpectedSchema(), $schema);
31+
TestHelper::compare(TestHelper::getExpected('v2.schema.schema.json'), $schema, $this);
3132
}
3233

3334
public function test_resource_type()
3435
{
3536
$builder = new SchemaBuilderV2();
3637
$schema = $builder->getResourceType()->serializeObject();
3738

38-
$this->compare($this->getExpectedResourceType(), $schema);
39+
TestHelper::compare(TestHelper::getExpected('v2.schema.resource_type.json'), $schema, $this);
3940
}
4041

4142
public function test_service_provider_config()
4243
{
4344
$builder = new SchemaBuilderV2();
4445
$schema = $builder->getServiceProviderConfig()->serializeObject();
4546

46-
$this->compare($this->getExpectedServiceProviderConfig(), $schema);
47+
TestHelper::compare(TestHelper::getExpected('v2.schema.service_provider_config.json'), $schema, $this);
4748
}
4849

4950
public function test_enterprise_user()
5051
{
5152
$builder = new SchemaBuilderV2();
5253
$schema = $builder->getEnterpriseUser()->serializeObject();
5354

54-
$this->compare($this->getExpectedEnterpriseUser(), $schema);
55-
}
56-
57-
private function compare($expected, $actual)
58-
{
59-
$expectedArr = explode("\n", str_replace("\r", '', json_encode($expected, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)));
60-
$actualArr = explode("\n", str_replace("\r", '', json_encode($actual, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)));
61-
62-
$minSize = min(count($expectedArr), count($actualArr));
63-
for ($i=0; $i<$minSize; $i++) {
64-
if ($expectedArr[$i] != $actualArr[$i]) {
65-
$expectedArr[$i] = '!'.$expectedArr[$i];
66-
$actualArr[$i] = '!'.$actualArr[$i];
67-
print "\nMismatch at line $i:\n";
68-
$start = $i - 10;
69-
if ($start < 0) { $start = 0; }
70-
$expectedBuffer = implode("\n", array_slice($expectedArr, $start, 20));
71-
$actualBuffer = implode("\n", array_slice($actualArr, $start, 20));
72-
73-
print "Expected:\n$expectedBuffer\n\nbut got:\n$actualBuffer\n";
74-
75-
$this->fail();
76-
}
77-
}
78-
79-
$this->assertEquals($expected, $actual);
80-
}
81-
82-
private function getExpected($filename)
83-
{
84-
$json = trim(file_get_contents(__DIR__.'/'.$filename));
85-
$result = json_decode($json, true);
86-
if (!$result) {
87-
$this->fail("Error json decoding file '$filename': ".json_last_error_msg());
88-
}
89-
90-
return $result;
91-
}
92-
93-
/**
94-
* @return \stdClass
95-
*/
96-
private function getExpectedGroup()
97-
{
98-
return $this->getExpected('schema.group.json');
99-
}
100-
101-
/**
102-
* @return \stdClass
103-
*/
104-
private function getExpectedUser()
105-
{
106-
return $this->getExpected('schema.user.json');
107-
}
108-
109-
/**
110-
* @return \stdClass
111-
*/
112-
private function getExpectedSchema()
113-
{
114-
return $this->getExpected('schema.schema.json');
115-
}
116-
117-
/**
118-
* @return \stdClass
119-
*/
120-
private function getExpectedResourceType()
121-
{
122-
return $this->getExpected('schema.resource_type.json');
123-
}
124-
125-
/**
126-
* @return \stdClass
127-
*/
128-
private function getExpectedServiceProviderConfig()
129-
{
130-
return $this->getExpected('schema.service_provider_config.json');
131-
}
132-
133-
/**
134-
* @return \stdClass
135-
*/
136-
private function getExpectedEnterpriseUser()
137-
{
138-
return $this->getExpected('schema.enterprise_user.json');
55+
TestHelper::compare(TestHelper::getExpected('v2.schema.enterprise_user.json'), $schema, $this);
13956
}
14057
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Tests\Tmilos\ScimSchema\Builder;
4+
5+
use Tests\Tmilos\ScimSchema\TestHelper;
6+
use Tmilos\ScimSchema\Builder\ServiceProviderConfigBuilderV1;
7+
8+
class ServiceProviderConfigBuilderV1Test extends \PHPUnit_Framework_TestCase
9+
{
10+
public function test_builds_default_service_provider_config()
11+
{
12+
$builder = new ServiceProviderConfigBuilderV1();
13+
$spc = $builder->buildServiceProviderConfig();
14+
$arr = $spc->serializeObject();
15+
16+
$this->assertEquals(TestHelper::getExpected('v1.service_provider_config.default.json'), $arr);
17+
}
18+
}

0 commit comments

Comments
 (0)