Skip to content

Commit

Permalink
Merge pull request #24 from getyoti/release-1.2.0
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
davidgrayston authored Jun 18, 2020
2 parents fed64a4 + 1e0d7c8 commit ed04c6f
Show file tree
Hide file tree
Showing 24 changed files with 704 additions and 23 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ jobs:
php: "7.2"
- <<: *compatibility
php: "7.3"
- <<: *test
stage: Analyze
name: Sonarcloud
dist: trusty
addons:
sonarcloud:
organization: "getyoti"
if: type == pull_request OR branch = master
script:
- composer coverage-clover
- sonar-scanner
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Yoti PHP Sandbox SDK

[![Build Status](https://travis-ci.com/getyoti/yoti-php-sdk-sandbox.svg?branch=master)](https://travis-ci.com/getyoti/yoti-php-sdk-sandbox)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Aphp-sandbox&metric=coverage)](https://sonarcloud.io/dashboard?id=getyoti%3Aphp-sandbox)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Aphp-sandbox&metric=bugs)](https://sonarcloud.io/dashboard?id=getyoti%3Aphp-sandbox)
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Aphp-sandbox&metric=code_smells)](https://sonarcloud.io/dashboard?id=getyoti%3Aphp-sandbox)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Aphp-sandbox&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=getyoti%3Aphp-sandbox)

This repository contains the tools you need to test your Yoti integration.

## Installing the Sandbox
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "yoti/yoti-php-sdk-sandbox",
"description": "Yoti PHP SDK Sandbox",
"version": "1.1.0",
"version": "1.2.0",
"keywords": [
"yoti",
"sdk"
Expand All @@ -12,7 +12,7 @@
"yoti/yoti-php-sdk": "^3.1"
},
"require-dev": {
"phpunit/phpunit": "^7.5 || ^8.5",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.2",
"squizlabs/php_codesniffer": "^3.4",
"friendsofphp/php-cs-fixer": "^2.15",
"brainmaestro/composer-git-hooks": "^2.8",
Expand Down
25 changes: 25 additions & 0 deletions examples/profile/tests/ProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
use Yoti\Sandbox\Profile\Request\Attribute\SandboxAgeVerification;
use Yoti\Sandbox\Profile\Request\Attribute\SandboxAnchor;
use Yoti\Sandbox\Profile\Request\ExtraData\SandboxExtraDataBuilder;
use Yoti\Sandbox\Profile\Request\ExtraData\ThirdParty\SandboxAttributeIssuanceDetailsBuilder;
use Yoti\Sandbox\Profile\Request\TokenRequestBuilder;
use Yoti\Sandbox\Profile\SandboxClient;
use Yoti\YotiClient;
Expand Down Expand Up @@ -54,6 +56,17 @@ public function shouldReturnUserProfile()
new \DateTime('1980-01-01')
);

$expiryDate = new \DateTime('+1 day');
$extraData = (new SandboxExtraDataBuilder())
->withDataEntry(
(new SandboxAttributeIssuanceDetailsBuilder())
->withDefinition('some-definition')
->withExpiryDate($expiryDate)
->withIssuanceToken('some-token')
->build()
)
->build();

$tokenRequest = (new TokenRequestBuilder())
->setRememberMeId('Some Remember Me ID')
->setGivenNames('Some Given Names', $anchors)
Expand All @@ -71,6 +84,7 @@ public function shouldReturnUserProfile()
'building_number' => 1,
'address_line1' => 'Some Address',
]))
->setExtraData($extraData)
->build();

$token = $this->sandboxClient->setupSharingProfile($tokenRequest);
Expand Down Expand Up @@ -104,5 +118,16 @@ public function shouldReturnUserProfile()

$this->assertEquals('PASSPORT', $profile->getGivenNames()->getSources()[0]->getValue());
$this->assertEquals('YOTI_ADMIN', $profile->getGivenNames()->getVerifiers()[0]->getValue());

$attributeIssuanceDetails = $activityDetails->getExtraData()->getAttributeIssuanceDetails();
$this->assertEquals(base64_encode('some-token'), $attributeIssuanceDetails->getToken());
$this->assertEquals(
$expiryDate->format(DATE_RFC3339),
$attributeIssuanceDetails->getExpiryDate()->format(DATE_RFC3339)
);
$this->assertEquals(
'some-definition',
$attributeIssuanceDetails->getIssuingAttributes()[0]->getName()
);
}
}
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sonar.organization = getyoti

sonar.projectKey = getyoti:php-sandbox
sonar.projectName = PHP SDK Sandbox
sonar.projectVersion = 1.1.0
sonar.projectVersion = 1.2.0

sonar.language = php
sonar.sources=src
Expand Down
39 changes: 39 additions & 0 deletions src/Profile/Request/ExtraData/SandboxDataEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Yoti\Sandbox\Profile\Request\ExtraData;

abstract class SandboxDataEntry implements \JsonSerializable
{
/**
* @var string
*/
private $type;

/**
* @var \JsonSerializable
*/
private $value;

/**
* @param string $type
* @param \JsonSerializable $value
*/
public function __construct(string $type, \JsonSerializable $value)
{
$this->type = $type;
$this->value = $value;
}

/**
* @return \stdClass
*/
public function jsonSerialize(): \stdClass
{
return (object) [
'type' => $this->type,
'value' => $this->value,
];
}
}
34 changes: 34 additions & 0 deletions src/Profile/Request/ExtraData/SandboxExtraData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Yoti\Sandbox\Profile\Request\ExtraData;

use Yoti\Util\Validation;

class SandboxExtraData implements \JsonSerializable
{
/**
* @var SandboxDataEntry[]
*/
private $dataEntries;

/**
* @param SandboxDataEntry[] $dataEntries
*/
public function __construct(array $dataEntries)
{
Validation::isArrayOfType($dataEntries, [SandboxDataEntry::class], 'dataEntries');
$this->dataEntries = $dataEntries;
}

/**
* @return \stdClass
*/
public function jsonSerialize(): \stdClass
{
return (object) [
'data_entry' => $this->dataEntries,
];
}
}
32 changes: 32 additions & 0 deletions src/Profile/Request/ExtraData/SandboxExtraDataBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Yoti\Sandbox\Profile\Request\ExtraData;

class SandboxExtraDataBuilder
{
/**
* @var SandboxDataEntry[]
*/
private $dataEntries = [];

/**
* @param SandboxDataEntry $dataEntry
*
* @return $this
*/
public function withDataEntry(SandboxDataEntry $dataEntry): self
{
$this->dataEntries[] = $dataEntry;
return $this;
}

/**
* @return SandboxExtraData
*/
public function build(): SandboxExtraData
{
return new SandboxExtraData($this->dataEntries);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Yoti\Sandbox\Profile\Request\ExtraData\ThirdParty;

use Yoti\Sandbox\Profile\Request\ExtraData\SandboxDataEntry;

class SandboxAttributeIssuanceDetails extends SandboxDataEntry
{
private const TYPE = 'THIRD_PARTY_ATTRIBUTE';

/**
* @param SandboxAttributeIssuanceDetailsValue $value
*/
public function __construct(SandboxAttributeIssuanceDetailsValue $value)
{
parent::__construct(self::TYPE, $value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

namespace Yoti\Sandbox\Profile\Request\ExtraData\ThirdParty;

use Yoti\Util\Validation;

class SandboxAttributeIssuanceDetailsBuilder
{
/**
* @var string
*/
private $issuanceToken;

/**
* @var \DateTime
*/
private $expiryDate;

/**
* @var SandboxDefinition[]
*/
private $definitions;

/**
* @param string $issuanceToken
*
* @return $this
*/
public function withIssuanceToken(string $issuanceToken): self
{
Validation::notEmptyString($issuanceToken, 'issuanceToken');
$this->issuanceToken = $issuanceToken;
return $this;
}

/**
* @param \DateTime $expiryDate
*
* @return $this
*/
public function withExpiryDate(\DateTime $expiryDate): self
{
$this->expiryDate = $expiryDate;
return $this;
}

/**
* @param string $definition
*
* @return self
*/
public function withDefinition(string $definition): self
{
Validation::notEmptyString($definition, 'definition');
$this->definitions[] = new SandboxDefinition($definition);
return $this;
}

/**
* @return SandboxAttributeIssuanceDetails
*/
public function build(): SandboxAttributeIssuanceDetails
{
$value = new SandboxAttributeIssuanceDetailsValue(
$this->issuanceToken,
new SandboxIssuingAttributes($this->expiryDate, $this->definitions)
);
return new SandboxAttributeIssuanceDetails($value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Yoti\Sandbox\Profile\Request\ExtraData\ThirdParty;

class SandboxAttributeIssuanceDetailsValue implements \JsonSerializable
{
/**
* @var string
*/
private $issuanceToken;

/**
* @var SandboxIssuingAttributes
*/
private $issuingAttributes;

/**
* @param string $issuanceToken
* @param SandboxIssuingAttributes $issuingAttributes
*/
public function __construct(string $issuanceToken, SandboxIssuingAttributes $issuingAttributes)
{
$this->issuanceToken = $issuanceToken;
$this->issuingAttributes = $issuingAttributes;
}

/**
* @return \stdClass
*/
public function jsonSerialize(): \stdClass
{
return (object) [
'issuance_token' => $this->issuanceToken,
'issuing_attributes' => $this->issuingAttributes,
];
}
}
34 changes: 34 additions & 0 deletions src/Profile/Request/ExtraData/ThirdParty/SandboxDefinition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Yoti\Sandbox\Profile\Request\ExtraData\ThirdParty;

use Yoti\Util\Validation;

class SandboxDefinition implements \JsonSerializable
{
/**
* @var string
*/
private $name;

/**
* @param string $name
*/
public function __construct(string $name)
{
Validation::notEmptyString($name, 'name');
$this->name = $name;
}

/**
* @return \stdClass
*/
public function jsonSerialize(): \stdClass
{
return (object) [
'name' => $this->name,
];
}
}
Loading

0 comments on commit ed04c6f

Please sign in to comment.