Compare commits

...

20 commits

Author SHA1 Message Date
Markus Klein d5207ef3b5 [TASK] Fix API url for organisation statistics 2023-07-06 18:41:31 +02:00
Markus Klein a7e0532d06 [TASK] Throw exception if required API key is missing 2023-07-06 18:30:20 +02:00
Lizardl fee06f0fa1
Merge pull request #14 from SkillDisplay/organisation
Added new Entities (Organisation, MemberSkills and SkillSetProgress)
2023-07-06 15:17:50 +02:00
lisam a6756cc2b8 Merge branch 'php8-migration' into organisation 2023-07-06 15:13:25 +02:00
lisam b4dbb508db Changed Tests 2023-07-06 15:12:00 +02:00
julianzangl 4af9c1c656 test changes 2023-07-06 15:10:44 +02:00
lisam b3bd17d10a Merge branch 'master' into organisation 2023-07-06 15:05:08 +02:00
julianzangl f28d2af8e0 Merge branch 'master' of https://github.com/SkillDisplay/api-php into php8-migration 2023-07-06 14:53:14 +02:00
Markus Klein d4bc19dd20
Merge pull request #13 from SkillDisplay/fix-guzzle-mocking
[BUGFIX] Guzzle mocking for response body
2023-07-06 14:50:58 +02:00
lisam ae0c838722 Added Member and Organisation Statistic with Test 2023-07-06 14:48:23 +02:00
Markus Klein eb066e224d [BUGFIX] Guzzle mocking for response body 2023-07-06 14:47:47 +02:00
Markus Klein a5db2bd729 [!!!][TASK] Raise guzzle requirement 2023-07-06 14:37:02 +02:00
julianzangl 9a335a7486 added SkillSetProgress with Tests 2023-07-06 14:24:24 +02:00
Weissheiten Wien 0f4263663b
Merge pull request #12 from SkillDisplay/PHPUnitUpgrade
Php unit upgrade
2023-07-06 14:01:24 +02:00
Florian Weiss 3e2f86f1a2 [TASK] Add composer.lock to gitignore to prevent CI tests lock for testing multiple versions 2023-07-06 14:00:00 +02:00
Florian Weiss 76a1f5fcb7 [TASK] Remove composer lock 2023-07-06 13:57:46 +02:00
Florian Weiss 6a74da49a3 [TASK] match PHP version for CI 2023-07-06 13:53:06 +02:00
Florian Weiss ffd07689c6 [TASK] Update Unit Tests for new version of PHPUnit, drop Unit Tests that match a specific SVG 2023-07-06 12:47:42 +02:00
lisam 55ced21f7d Added property types to link 2023-07-06 10:11:32 +02:00
lisam d6d9c293f5 Added property types 2023-07-06 10:09:41 +02:00
33 changed files with 1097 additions and 3217 deletions

View file

@ -9,7 +9,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.2
- name: Validate composer.json
run: composer validate
@ -19,9 +19,9 @@ jobs:
strategy:
matrix:
php-version:
- 7.2
- 7.3
- 7.4
- 8.1
- 8.2
steps:
- name: Checkout
uses: actions/checkout@v2
@ -42,7 +42,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.2
- name: Get Composer Cache Directory
id: composer-cache
@ -70,7 +70,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.2
- name: Get Composer Cache Directory
id: composer-cache

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
/.idea/
/vendor/
.phpunit.result.cache
composer.lock

View file

@ -11,7 +11,7 @@
],
"require": {
"ext-json": "*",
"guzzlehttp/guzzle": "^6.5",
"guzzlehttp/guzzle": "^7.7",
"php": "7.4.* || 8.1.* || 8.2.*"
},
"autoload": {
@ -29,5 +29,10 @@
"phpunit/phpunit": "^9.3",
"phpspec/prophecy-phpunit": "^2.0",
"squizlabs/php_codesniffer": "^3.5"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
}
}

2894
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -26,20 +26,15 @@ namespace SkillDisplay\PHPToolKit\Api;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Psr7\Request;
use InvalidArgumentException;
use SkillDisplay\PHPToolKit\Configuration\Settings;
use SkillDisplay\PHPToolKit\Entity\Campaign;
class Campaigns
{
/**
* @var Settings
*/
protected $settings;
protected Settings $settings;
/**
* @var Client
*/
protected $client;
protected Client $client;
public function __construct(
Settings $settings,
@ -51,6 +46,9 @@ class Campaigns
public function getForUser(): array
{
if (!$this->settings->getApiKey()) {
throw new InvalidArgumentException('Missing API key', 1688660942);
}
$url = $this->settings->getAPIUrl() . '/api/v1/campaigns';
try {
$result = $this->client->send(new Request(

70
src/Api/MemberSkills.php Normal file
View file

@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace SkillDisplay\PHPToolKit\Api;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use InvalidArgumentException;
use SkillDisplay\PHPToolKit\Configuration\Settings;
use GuzzleHttp\Psr7\Request;
use SkillDisplay\PHPToolKit\Entity\MemberSkill as Entity;
class MemberSkills
{
protected Settings $settings;
protected Client $client;
public function __construct(
Settings $settings,
Client $client
) {
$this->settings = $settings;
$this->client = $client;
}
public function getMemberSkillsById(int $id)
{
if ($id <= 0) {
throw new \Exception('ID of Organisation has to be a positive integer.');
}
if (!$this->settings->getApiKey()) {
throw new InvalidArgumentException('Missing API key', 1688660942);
}
$url = $this->settings->getAPIUrl() . '/api/v1/organisation/' . $id . '/listVerifications/json';
try {
$result = $this->client->send(new Request(
'GET',
$url,
[
'Content-Type' => 'application/json',
'x-api-key' => $this->settings->getApiKey()
]
));
} catch (ClientException $e) {
if ($e->getCode() === 404) {
throw new \InvalidArgumentException('Given Organisation with id "' . $id . '" not available.', 1601881616);
}
throw $e;
}
if ($result->getStatusCode() !== 200) {
throw new \Exception('Did not get proper response for Organisation.', 1600693562);
}
$body = (string) $result->getBody();
if (strpos($body, 'Oops, an error occurred') !== false) {
throw new \Exception('Did not get proper response for Organisation. Organisation with id "' . $id . '" does probably not exist.', 1600694312);
}
$body = json_decode((string) $result->getBody(), true);
$skills = [];
foreach ($body as $skill) {
$skills[] = Entity::createFromJson(json_encode($skill), $this->settings);
}
return $skills;
}
}

64
src/Api/Organisation.php Normal file
View file

@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace SkillDisplay\PHPToolKit\Api;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use InvalidArgumentException;
use SkillDisplay\PHPToolKit\Configuration\Settings;
use GuzzleHttp\Psr7\Request;
use SkillDisplay\PHPToolKit\Entity\Organisation as Entity;
class Organisation
{
protected Settings $settings;
protected Client $client;
public function __construct(
Settings $settings,
Client $client
) {
$this->settings = $settings;
$this->client = $client;
}
public function getStatisticById(int $id)
{
if ($id <= 0) {
throw new \Exception('ID of Organisation has to be a positive integer.');
}
if (!$this->settings->getApiKey()) {
throw new InvalidArgumentException('Missing API key', 1688660942);
}
$url = $this->settings->getAPIUrl() . '/api/v1/organisation/' . $id . '/statistics';
try {
$result = $this->client->send(new Request(
'GET',
$url,
[
'Content-Type' => 'application/json',
'x-api-key' => $this->settings->getApiKey()
]
));
} catch (ClientException $e) {
if ($e->getCode() === 404) {
throw new \InvalidArgumentException('Given Organisation with id "' . $id . '" not available.', 1601881616);
}
throw $e;
}
if ($result->getStatusCode() !== 200) {
throw new \Exception('Did not get proper response for Organisation.', 1600693562);
}
$body = (string) $result->getBody();
if (strpos($body, 'Oops, an error occurred') !== false) {
throw new \Exception('Did not get proper response for Organisation. Organisation with id "' . $id . '" does probably not exist.', 1600694312);
}
return Entity::createFromJson($body, $this->settings);
}
}

View file

@ -31,15 +31,9 @@ use SkillDisplay\PHPToolKit\Entity\Skill as Entity;
class Skill
{
/**
* @var Settings
*/
protected $settings;
protected Settings $settings;
/**
* @var Client
*/
protected $client;
protected Client $client;
public function __construct(
Settings $settings,

View file

@ -31,15 +31,9 @@ use SkillDisplay\PHPToolKit\Entity\SkillSet as Entity;
class SkillSet
{
/**
* @var Settings
*/
protected $settings;
protected Settings $settings;
/**
* @var Client
*/
protected $client;
protected Client $client;
public function __construct(
Settings $settings,

View file

@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace SkillDisplay\PHPToolKit\Api;
/*
* Copyright (C) 2023 Julian Zangl <julian.zangl@outlook.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Psr7\Request;
use InvalidArgumentException;
use SkillDisplay\PHPToolKit\Configuration\Settings;
use SkillDisplay\PHPToolKit\Entity\SkillSetProgress as Entity;
class SkillSetProgress
{
protected Settings $settings;
protected Client $client;
public function __construct(
Settings $settings,
Client $client
) {
$this->settings = $settings;
$this->client = $client;
}
public function getById(int $id): Entity
{
if ($id <= 0) {
throw new \Exception('ID of SkillSet has to be a positive integer.', 1688639724754);
}
if (!$this->settings->getApiKey()) {
throw new InvalidArgumentException('Missing API key', 1688660942);
}
$url = $this->settings->getAPIUrl() . '/api/v1/skillset/' . $id . '/progress';
try {
$result = $this->client->send(new Request(
'GET',
$url,
[
'Content-Type' => 'application/json',
'x-api-key' => $this->settings->getApiKey()
]
));
} catch (ClientException $e) {
if ($e->getCode() === 404) {
throw new InvalidArgumentException('Given SkillSet with id "' . $id . '" not available.', 1688639748718);
}
throw $e;
}
if ($result->getStatusCode() !== 200) {
throw new \Exception('Did not get proper response for SkillSetProgress.', 1688639840720);
}
$body = (string) $result->getBody();
if (strpos($body, 'Oops, an error occurred') !== false) {
throw new \Exception('Did not get proper response for SkillSetProgress. SkillSet with id "' . $id . '" does probably not exist.', 1688639873065);
}
return Entity::createFromJson($body, $this->settings);
}
}

View file

@ -6,30 +6,15 @@ namespace SkillDisplay\PHPToolKit\Configuration;
class Settings
{
/**
* @var string
*/
private $user_secret = '';
private string $user_secret = '';
/**
* @var string
*/
private $apiKey = '';
private string $apiKey = '';
/**
* @var int
*/
private $verifierID = 0;
private int $verifierID = 0;
/**
* @var string
*/
private $APIUrl = '';
private string $APIUrl = '';
/**
* @var string
*/
private $mySkillDisplayUrl = '';
private string $mySkillDisplayUrl = '';
public function getVerifierID(): int
{

View file

@ -27,15 +27,9 @@ use SkillDisplay\PHPToolKit\Configuration\Settings;
class Brand
{
/**
* @var array
*/
private $data;
private array $data;
/**
* @var Settings
*/
private $settings;
private Settings $settings;
private function __construct(array $data, Settings $settings)
{

View file

@ -27,15 +27,9 @@ use SkillDisplay\PHPToolKit\Configuration\Settings;
class Campaign
{
/**
* @var array
*/
private $data;
private array $data;
/**
* @var Settings
*/
private $settings;
private Settings $settings;
public function __construct(array $data, Settings $settings)
{

179
src/Entity/MemberSkill.php Normal file
View file

@ -0,0 +1,179 @@
<?php
declare(strict_types=1);
namespace SkillDisplay\PHPToolKit\Entity;
class MemberSkill
{
private int $id = 0;
private string $created = '';
private string $granted = '';
private int $skillUid = 0;
private string $skillUUid = '';
private string $skill = '';
private string $domainTag = '';
private string $level = '';
private string $user = '';
private string $firstName = '';
private string $lastName = '';
private string $certifier = '';
private string $organisation = '';
private string $campaign = '';
private int $skillSetUid = 0;
private string $skillSetName = '';
public static function createFromJson(string $json_encode, \SkillDisplay\PHPToolKit\Configuration\Settings $settings)
{
$json = json_decode($json_encode, true);
$entity = new self();
$entity->id = $json['uid'] ?? 0;
$entity->created = $json['created'] ?? '';
$entity->granted = $json['granted'] ?? '';
$entity->skillUid = $json['skillUid'] ?? 0;
$entity->skillUUid = $json['skillUUid'] ?? '';
$entity->skill = $json['skill'] ?? '';
$entity->domainTag = $json['domainTag'] ?? '';
$entity->level = $json['level'] ?? '';
$entity->user = $json['user'] ?? '';
$entity->firstName = $json['firstName'] ?? '';
$entity->lastName = $json['lastName'] ?? '';
$entity->certifier = $json['certifier'] ?? '';
$entity->organisation = $json['organisation'] ?? '';
$entity->campaign = $json['campaign'] ?? '';
$entity->skillSetUid = $json['skillSetUid'] ?? 0;
$entity->skillSetName = $json['skillSetName'] ?? '';
return $entity;
}
/**
* @return string
*/
public function getCreated(): string
{
return $this->created;
}
/**
* @return string
*/
public function getGranted(): string
{
return $this->granted;
}
/**
* @return int
*/
public function getSkillUid(): int
{
return $this->skillUid;
}
/**
* @return string
*/
public function getSkillUUid(): string
{
return $this->skillUUid;
}
/**
* @return string
*/
public function getSkill(): string
{
return $this->skill;
}
/**
* @return string
*/
public function getDomainTag(): string
{
return $this->domainTag;
}
/**
* @return string
*/
public function getLevel(): string
{
return $this->level;
}
/**
* @return string
*/
public function getUser(): string
{
return $this->user;
}
/**
* @return string
*/
public function getFirstName(): string
{
return $this->firstName;
}
/**
* @return string
*/
public function getLastName(): string
{
return $this->lastName;
}
/**
* @return string
*/
public function getCertifier(): string
{
return $this->certifier;
}
/**
* @return string
*/
public function getOrganisation(): string
{
return $this->organisation;
}
/**
* @return string
*/
public function getCampaign(): string
{
return $this->campaign;
}
/**
* @return int
*/
public function getSkillSetUid(): int
{
return $this->skillSetUid;
}
/**
* @return string
*/
public function getSkillSetName(): string
{
return $this->skillSetName;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
}

133
src/Entity/Organisation.php Normal file
View file

@ -0,0 +1,133 @@
<?php
declare(strict_types=1);
namespace SkillDisplay\PHPToolKit\Entity;
use SkillDisplay\PHPToolKit\Configuration\Settings;
class Organisation
{
private array $data = [];
private Settings $settings;
private ?Brand $brand = null;
private function __construct(array $data, Settings $settings)
{
$this->data = $data;
$this->settings = $settings;
}
public function getId(): int
{
return $this->data['uid'];
}
public function getName(): string
{
return $this->data['name'] ?? '';
}
public function getBrand(): Brand
{
if ($this->brand instanceof Brand) {
return $this->brand;
}
$this->brand = Brand::createFromJson(json_encode($this->data['brand']), $this->settings);
return $this->brand;
}
public function getComposition(): string
{
return $this->data['composition'] ?? '';
}
public function getCurrentMonthIssued(): int
{
return $this->data['currentMonthIssued'] ?? 0;
}
public function getCurrentMonthUsers(): int
{
return $this->data['currentMonthUsers'] ?? 0;
}
public function getCurrentMonthVerifications(): int
{
return $this->data['currentMonthVerifications'] ?? 0;
}
public function getInterestSets(): array
{
return $this->data['interestSets'] ?? [];
}
public function getLastMonthIssued(): int
{
return $this->data['lastMonthIssued'] ?? 0;
}
public function getLastMonthUsers(): int
{
return $this->data['lastMonthUsers'] ?? 0;
}
public function getLastMonthVerifications(): int
{
return $this->data['lastMonthVerifications'] ?? 0;
}
public function getMonthlyScores(): array
{
return $this->data['monthlyScores'] ?? [];
}
public function getPotential(): array
{
return $this->data['potential'] ?? [];
}
public function getSumIssued(): int
{
return $this->data['sumSkills'] ?? 0;
}
public function getSumSkills(): int
{
return $this->data['sumSkills'] ?? 0;
}
public function getSumSupportedSkills(): int
{
return $this->data['sumSupportedSkills'] ?? 0;
}
public function getSumVerifications(): int
{
return $this->data['sumVerifications'] ?? 0;
}
public function getTotalScore(): int
{
return $this->data['totalScore'] ?? 0;
}
public static function createFromJson(string $json, Settings $settings): self
{
return new Organisation(json_decode($json, true), $settings);
}
public function getAsArray(): array
{
return $this->toArray();
}
public function toArray(): array
{
return $this->data;
}
}

View file

@ -27,20 +27,11 @@ use SkillDisplay\PHPToolKit\Configuration\Settings;
class Skill
{
/**
* @var array
*/
private $data;
private array $data;
/**
* @var Settings
*/
private $settings;
private Settings $settings;
/**
* @var array
*/
private $brands = [];
private array $brands = [];
private function __construct(array $data, Settings $settings)
{

View file

@ -27,25 +27,13 @@ use SkillDisplay\PHPToolKit\Configuration\Settings;
class SkillSet
{
/**
* @var array
*/
private $data;
private array $data;
/**
* @var Settings
*/
private $settings;
private Settings $settings;
/**
* @var array
*/
private $skills = [];
private array $skills = [];
/**
* @var Brand|null
*/
private $brand = null;
private ?Brand $brand = null;
private function __construct(array $data, Settings $settings)
{
@ -68,6 +56,11 @@ class SkillSet
return $this->data['description'] ?? '';
}
public function getProgressPercentage(): SkillSetProgress
{
return SkillSetProgress::createFromJson(json_encode($this->data['progressPercentage']), $this->settings);
}
public function getBrand(): Brand
{
if ($this->brand instanceof Brand) {

View file

@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace SkillDisplay\PHPToolKit\Entity;
/*
* Copyright (C) 2023 Julian Zangl <julian.zangl@outlook.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use SkillDisplay\PHPToolKit\Configuration\Settings;
class SkillSetProgress
{
private array $data;
private Settings $settings;
private function __construct(array $data, Settings $settings)
{
$this->data = $data;
$this->settings = $settings;
}
public function getTier1(): float
{
return $this->data['tier1'] ?? 0;
}
public function getTier2(): float
{
return $this->data['tier2'] ?? 0;
}
public function getTier3(): float
{
return $this->data['tier3'] ?? 0;
}
public function getTier4(): float
{
return $this->data['tier4'] ?? 0;
}
public static function createFromJson(string $json, Settings $settings): SkillSetProgress
{
return new SkillSetProgress(json_decode($json, true), $settings);
}
}

View file

@ -14,4 +14,4 @@ use SkillDisplay\PHPToolKit\Verification\Issuer;
// In order to grant an Educational Verification you just need to exchange the constant to VERIFICATION_EDUCATIONAL
// (your Verifier Account needs the according permissions)
$myVerificationTool = new Issuer($mySettings);
$myVerificationTool->outputResponse($myVerificationTool->issueVerification(193, '--skilldisplay-user-email--', VERIFICATION_BUSINESS, 567));
$myVerificationTool->outputResponse($myVerificationTool->issueVerification(175, '--skilldisplay-user-email--', VERIFICATION_BUSINESS, false, 567, true));

View file

@ -10,15 +10,9 @@ use SkillDisplay\PHPToolKit\Configuration\Settings;
class Issuer
{
/**
* @var Settings
*/
private $settings;
private Settings $settings;
/**
* @var string
*/
private $apislug = '/api/v1/verification/create';
private string $apislug = '/api/v1/verification/create';
/**
* @param int $ID ID of the Skill or SkillSet
@ -26,7 +20,7 @@ class Issuer
* @param string $vtype one of VERIFICATION_SELF, VERIFICATION_EDUCATIONAL, VERIFICATION_BUSINESS, VERIFICATION_CERTIFICATION
* @param bool $isSkillSet
* @param int $campaignId
*
* @param bool $autoConfirm
* @return array
*/
private function generateSignedRequestData(

File diff suppressed because one or more lines are too long

View file

@ -26,6 +26,7 @@ namespace SkillDisplay\PHPToolKit\Tests\Unit\Api;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Utils;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use SkillDisplay\PHPToolKit\Api\Campaigns;
@ -75,7 +76,7 @@ class CampaignsTest extends TestCase
}))->willReturn($response->reveal());
$response->getStatusCode()->willReturn(200);
$response->getBody()->willReturn('{"Version": "1.0","ErrorMessage": "","Campaigns": [{"uid": 1},{"uid": 2}]}');
$response->getBody()->willReturn(Utils::streamFor('{"Version": "1.0","ErrorMessage": "","Campaigns": [{"uid": 1},{"uid": 2}]}'));
$subject = new Campaigns(
$settings->reveal(),

View file

@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace SkillDisplay\PHPToolKit\Tests\Unit\Api;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Utils;
use Prophecy\Argument;
use SkillDisplay\PHPToolKit\Api\MemberSkills;
use SkillDisplay\PHPToolKit\Configuration\Settings;
use SkillDisplay\PHPToolKit\Entity\MemberSkill;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
/**
* @covers SkillDisplay\PHPToolKit\Api\MemberSkills
*/
class MemberSkillsTest extends TestCase
{
use ProphecyTrait;
/**
* @test
*/
public function instanceCanBeCreated()
{
$settings = $this->prophesize(Settings::class);
$client = $this->prophesize(Client::class);
$subject = new MemberSkills($settings->reveal(), $client->reveal());
static::assertInstanceOf(MemberSkills::class, $subject);
}
/**
* @test
*/
public function fetchedEntityFromApi()
{
$settings = $this->prophesize(Settings::class);
$client = $this->prophesize(Client::class);
$response = $this->prophesize(Response::class);
$settings->getAPIUrl()->willReturn('https://example.com');
$settings->getApiKey()->willReturn('none');
$client->send(Argument::that(function (Request $request) {
return (string) $request->getUri() === 'https://example.com/api/v1/organisation/10/listVerifications/json'
&& $request->getHeader('x-api-key') === ['none']
&& $request->getHeader('Content-Type') === ['application/json']
&& $request->getMethod() === 'GET';
}))->willReturn($response->reveal());
$response->getStatusCode()->willReturn(200);
$response->getBody()->willReturn(Utils::streamFor('[{"uid": 1},{"uid": 2}]'));
$subject = new MemberSkills($settings->reveal(), $client->reveal());
$skills = $subject->getMemberSkillsById(10);
static::assertInstanceOf(MemberSkill::class, $skills[0]);
static::assertEquals(1, $skills[0]->getId());
}
}

View file

@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
namespace SkillDisplay\PHPToolKit\Tests\Unit\Api;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Utils;
use Prophecy\Argument;
use SkillDisplay\PHPToolKit\Api\Organisation;
use SkillDisplay\PHPToolKit\Api\SkillSet;
use SkillDisplay\PHPToolKit\Configuration\Settings;
use GuzzleHttp\Client;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use GuzzleHttp\Psr7\Response;
use SkillDisplay\PHPToolKit\Entity\Organisation as Entity;
/**
* @covers SkillDisplay\PHPToolKit\Api\Organisation
*/
class OrganisationTest extends TestCase
{
use ProphecyTrait;
/**
* @test
*/
public function instanceCanBeCreated()
{
$settings = $this->prophesize(Settings::class);
$client = $this->prophesize(Client::class);
$subject = new Organisation($settings->reveal(), $client->reveal());
static::assertInstanceOf(Organisation::class, $subject);
}
/**
* @test
*/
public function fetchOrganisationStatistic()
{
$settings = $this->prophesize(Settings::class);
$client = $this->prophesize(Client::class);
$response = $this->prophesize(Response::class);
$settings->getAPIUrl()->willReturn('https://example.com');
$settings->getApiKey()->willReturn('none');
$client->send(Argument::that(function (Request $request) {
return (string)$request->getUri() === 'https://example.com/api/v1/organisation/10/statistics'
&& $request->getHeader('x-api-key') === ['none']
&& $request->getHeader('Content-Type') === ['application/json']
&& $request->getMethod() === 'GET';
}))->willReturn($response->reveal());
$response->getStatusCode()->willReturn(200);
$response->getBody()->willReturn(Utils::streamFor('{"uid":10}'));
$subject = new Organisation(
$settings->reveal(),
$client->reveal()
);
$result = $subject->getStatisticById(10);
static::assertInstanceOf(Entity::class, $result);
}
}

View file

@ -0,0 +1,148 @@
<?php
declare(strict_types=1);
namespace SkillDisplay\PHPToolKit\Tests\Unit\Api;
/*
* Copyright (C) 2023 Julian Zangl <julian.zangl@outlook.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Utils;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use SkillDisplay\PHPToolKit\Api\SkillSetProgress;
use PHPUnit\Framework\TestCase;
use SkillDisplay\PHPToolKit\Configuration\Settings;
use SkillDisplay\PHPToolKit\Entity\SkillSetProgress as Entity;
/**
* @covers SkillDisplay\PHPToolKit\Api\SkillSetProgress
*/
class SkillSetProgressTest extends TestCase
{
use ProphecyTrait;
/**
* @test
*/
public function instanceCanBeCreated()
{
$settings = $this->prophesize(Settings::class);
$client = $this->prophesize(Client::class);
$subject = new SkillSetProgress(
$settings->reveal(),
$client->reveal()
);
static::assertInstanceOf(SkillSetProgress::class, $subject);
}
/**
* @test
*/
public function fetchedEntityFromApi()
{
$settings = $this->prophesize(Settings::class);
$client = $this->prophesize(Client::class);
$response = $this->prophesize(Response::class);
$settings->getAPIUrl()->willReturn('https://example.com');
$settings->getApiKey()->willReturn('none');
$client->send(Argument::that(function (Request $request) {
return (string) $request->getUri() === 'https://example.com/api/v1/skillset/10/progress'
&& $request->getHeader('x-api-key') === ['none']
&& $request->getHeader('Content-Type') === ['application/json']
&& $request->getMethod() === 'GET';
}))->willReturn($response->reveal());
$response->getStatusCode()->willReturn(200);
$response->getBody()->willReturn(Utils::streamFor('{"tier3":44.44444444444444,"tier2":40.74074074074074,"tier1":0,"tier4":0}'));
$progress = new SkillSetProgress(
$settings->reveal(),
$client->reveal()
);
$result = $progress->getById(10);
static::assertInstanceOf(Entity::class, $result);
}
/**
* @test
*/
public function throwsExceptionIfStatusCodeIsNot200()
{
$settings = $this->prophesize(Settings::class);
$client = $this->prophesize(Client::class);
$response = $this->prophesize(Response::class);
$settings->getAPIUrl()->willReturn('https://example.com');
$settings->getApiKey()->willReturn('none');
$client->send(Argument::any())->willReturn($response->reveal());
$response->getStatusCode()->willReturn(500);
$progress = new SkillSetProgress(
$settings->reveal(),
$client->reveal()
);
$this->expectExceptionMessage('Did not get proper response for SkillSetProgress.');
$this->expectExceptionCode(1688639840720);
$progress->getById(10);
}
/**
* @test
* @dataProvider nonePositiveIds
*/
public function throwsExceptionIfSkillSetIdIsNotPositive(int $skillId)
{
$settings = $this->prophesize(Settings::class);
$client = $this->prophesize(Client::class);
$progress = new SkillSetProgress(
$settings->reveal(),
$client->reveal()
);
$this->expectExceptionMessage('ID of SkillSet has to be a positive integer.');
$this->expectExceptionCode(1688639724754);
$progress->getById($skillId);
}
public function nonePositiveIds(): array
{
return [
'zero' => [
'skillId' => 0,
],
'negative' => [
'skillId' => -1,
],
];
}
}

View file

@ -26,6 +26,7 @@ namespace SkillDisplay\PHPToolKit\Tests\Unit\Api;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Utils;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use SkillDisplay\PHPToolKit\Api\SkillSet;
@ -77,7 +78,7 @@ class SkillSetTest extends TestCase
}))->willReturn($response->reveal());
$response->getStatusCode()->willReturn(200);
$response->getBody()->willReturn('{"uid":10}');
$response->getBody()->willReturn(Utils::streamFor('{"uid":10}'));
$subject = new SkillSet(
$settings->reveal(),

View file

@ -26,6 +26,7 @@ namespace SkillDisplay\PHPToolKit\Tests\Unit\Api;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Utils;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use SkillDisplay\PHPToolKit\Api\Skill;
@ -77,7 +78,7 @@ class SkillTest extends TestCase
}))->willReturn($response->reveal());
$response->getStatusCode()->willReturn(200);
$response->getBody()->willReturn('{"uid":10}');
$response->getBody()->willReturn(Utils::streamFor('{"uid":10}'));
$subject = new Skill(
$settings->reveal(),

View file

@ -40,7 +40,7 @@ class BrandTest extends TestCase
*/
public function instanceCanNotBeCreatedViaConstructor()
{
$this->expectErrorMessage('Call to private SkillDisplay\PHPToolKit\Entity\Brand::__construct() from context \'SkillDisplay\PHPToolKit\Tests\Unit\Entity\BrandTest\'');
$this->expectExceptionMessage('Call to private SkillDisplay\PHPToolKit\Entity\Brand::__construct() from scope SkillDisplay\PHPToolKit\Tests\Unit\Entity\BrandTest');
new Brand();
}

View file

@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
namespace SkillDisplay\PHPToolKit\Tests\Unit\Entity;
use SkillDisplay\PHPToolKit\Configuration\Settings;
use SkillDisplay\PHPToolKit\Entity\Brand;
use SkillDisplay\PHPToolKit\Entity\Organisation;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
/**
* @covers SkillDisplay\PHPToolKit\Entity\Organisation
*/
class OrganisationTest extends TestCase
{
use ProphecyTrait;
/**
* @test
*/
public function instanceCanBeCreatedFromJson()
{
$settings = $this->prophesize(Settings::class);
$subject = Organisation::createFromJson('{}', $settings->reveal());
static::assertInstanceOf(Organisation::class, $subject);
}
/**
* @test
*/
public function instanceReturnsId()
{
$settings = $this->prophesize(Settings::class);
$subject = Organisation::createFromJson('{"uid":90}', $settings->reveal());
static::assertSame(90, $subject->getId());
}
/**
* @test
*/
public function instanceReturnsName()
{
$settings = $this->prophesize(Settings::class);
$subject = Organisation::createFromJson('{"name":"Example name"}', $settings->reveal());
static::assertSame('Example name', $subject->getName());
}
/**
* @test
*/
public function canBeConvertedToArray()
{
$settings = $this->prophesize(Settings::class);
$subject = Organisation::createFromJson('{"uid":90,"name":"Example name"}', $settings->reveal());
static::assertSame(['uid' => 90, 'name' => 'Example name'], $subject->toArray());
}
}

View file

@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
namespace SkillDisplay\PHPToolKit\Tests\Unit\Entity;
/*
* Copyright (C) 2023 Julian Zangl <julian.zangl@outlook.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use Prophecy\PhpUnit\ProphecyTrait;
use PHPUnit\Framework\TestCase;
use SkillDisplay\PHPToolKit\Configuration\Settings;
use SkillDisplay\PHPToolKit\Entity\SkillSetProgress;
/**
* @covers SkillDisplay\PHPToolKit\Entity\SkillSetProgress
*/
class SkillSetProgressTest extends TestCase
{
use ProphecyTrait;
/**
* @test
*/
public function instanceCanBeCreatedFromJson()
{
$settings = $this->prophesize(Settings::class);
$progress = SkillSetProgress::createFromJson('{}', $settings->reveal());
static::assertInstanceOf(SkillSetProgress::class, $progress);
}
/**
* @test
*/
public function instanceReturnsTier1()
{
$settings = $this->prophesize(Settings::class);
$progress = SkillSetProgress::createFromJson('{"tier1": 44.444444}', $settings->reveal());
static::assertSame(44.444444, $progress->getTier1());
}
/**
* @test
*/
public function instanceReturnsTier2()
{
$settings = $this->prophesize(Settings::class);
$progress = SkillSetProgress::createFromJson('{"tier2": 44.444444}', $settings->reveal());
static::assertSame(44.444444, $progress->getTier2());
}
/**
* @test
*/
public function instanceReturnsTier3()
{
$settings = $this->prophesize(Settings::class);
$progress = SkillSetProgress::createFromJson('{"tier3": 44}', $settings->reveal());
static::assertSame(44.0, $progress->getTier3());
}
/**
* @test
*/
public function instanceReturnsTier4()
{
$settings = $this->prophesize(Settings::class);
$progress = SkillSetProgress::createFromJson('{"tier4": 0}', $settings->reveal());
static::assertSame(0.0, $progress->getTier4());
}
}

View file

@ -41,7 +41,7 @@ class SkillSetTest extends TestCase
*/
public function instanceCanNotBeCreatedViaConstructor()
{
$this->expectErrorMessage('Call to private SkillDisplay\PHPToolKit\Entity\SkillSet::__construct() from context \'SkillDisplay\PHPToolKit\Tests\Unit\Entity\SkillSetTest\'');
$this->expectExceptionMessage('Call to private SkillDisplay\PHPToolKit\Entity\SkillSet::__construct() from scope SkillDisplay\PHPToolKit\Tests\Unit\Entity\SkillSetTest');
new SkillSet();
}
@ -85,6 +85,21 @@ class SkillSetTest extends TestCase
static::assertSame('<p>Example description</p>', $subject->getDescription());
}
/**
* @test
*/
public function instanceReturnsProgressPercentage()
{
$settings = $this->prophesize(Settings::class);
$subject = SkillSet::createFromJson('{"progressPercentage":{"tier3":44.44444444444444,"tier2":40.74074074074074,"tier1":0,"tier4":23}}', $settings->reveal());
$progress = \SkillDisplay\PHPToolKit\Entity\SkillSetProgress::createFromJson('{"tier3":44.44444444444444,"tier2":40.74074074074074,"tier1":0,"tier4":23}', $settings->reveal());
static::assertEquals($progress, $subject->getProgressPercentage());
static::assertSame(0.0, $subject->getProgressPercentage()->getTier1());
static::assertSame(40.74074074074074, $subject->getProgressPercentage()->getTier2());
static::assertSame(44.44444444444444, $subject->getProgressPercentage()->getTier3());
static::assertSame(23.0, $subject->getProgressPercentage()->getTier4());
}
/**
* @test
*/

View file

@ -41,7 +41,7 @@ class SkillTest extends TestCase
*/
public function instanceCanNotBeCreatedViaConstructor()
{
$this->expectErrorMessage('Call to private SkillDisplay\PHPToolKit\Entity\Skill::__construct() from context \'SkillDisplay\PHPToolKit\Tests\Unit\Entity\SkillTest\'');
$this->expectExceptionMessage('Call to private SkillDisplay\PHPToolKit\Entity\Skill::__construct() from scope SkillDisplay\PHPToolKit\Tests\Unit\Entity\SkillTest');
new Skill();
}

File diff suppressed because one or more lines are too long