-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit tests #8
Open
gradinarufelix
wants to merge
25
commits into
master
Choose a base branch
from
switch-to-s2s-oauth-apps-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
59b30a3
WIP
krsriq 90e63a6
TEST
gradinarufelix 3772366
WIP
krsriq ef92eae
WIP
krsriq 8bccc38
WIP
gradinarufelix 808fb7a
Tests
gradinarufelix f92ec6e
Bugfixes and composer
gradinarufelix 5c555cb
Update readme
gradinarufelix ac6fd58
Add exeception code
gradinarufelix 69a074c
CHORE: add gh workflow
krsriq c275b48
CLEANUP: Remove old test file
gradinarufelix b4c8279
TASK: Refactor getAccessToken
gradinarufelix d29f356
Refactor tests
gradinarufelix a498c6a
Refactor code
gradinarufelix 6a456ec
TEST: unsuccessful oauth token request
krsriq 85c48a9
Apply suggestions from krisq code review
gradinarufelix 353588d
TASK: Extract time utility methods and test them automatically
gradinarufelix b484824
Improve other tests
gradinarufelix 5325764
Move time utility test
gradinarufelix 2f3b8af
Bump minimum php version to 8.1, adapt ZoomApiAccessToken constructor…
gradinarufelix ea1ad15
Fix namespace
gradinarufelix 8badf4a
Adapt text matrix, add phpstan
gradinarufelix cc24437
Fix style
gradinarufelix b17e3d6
Catch http errors in own code
gradinarufelix 9fbf997
Adjust exception message
gradinarufelix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: "Code Coverage" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ,"switch-to-s2s-oauth-apps-tests"] | ||
pull_request: | ||
branches: [ "main" ,"switch-to-s2s-oauth-apps-tests"] | ||
|
||
jobs: | ||
code-coverage: | ||
|
||
runs-on: "ubuntu-latest" | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install PHP with extensions | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
coverage: xdebug | ||
php-version: '8.1' | ||
|
||
- name: Install dependencies | ||
run: composer update --ansi --no-interaction --no-progress --optimize-autoloader | ||
|
||
- name: Collect code coverage with PHPUnit | ||
run: Packages/Libraries/phpunit/phpunit/phpunit --bootstrap Tests/UnitTestBootstrap.php --configuration Tests/phpunit.xml --colors=always --coverage-clover=.build/logs/clover.xml | ||
|
||
- name: Upload coverage reports to Codecov with GitHub Action | ||
uses: codecov/codecov-action@v3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: PHPUnit Tests | ||
|
||
on: | ||
push: | ||
branches: [ "main" ,"switch-to-s2s-oauth-apps-tests"] | ||
pull_request: | ||
branches: [ "main" ,"switch-to-s2s-oauth-apps-tests"] | ||
|
||
jobs: | ||
run-tests: | ||
name: "Test (PHP ${{ matrix.php-versions }}, Neos ${{ matrix.neos-versions }})" | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php-versions: [ '8.1' ] | ||
neos-versions: [ '7.3' ] | ||
include: | ||
- php-versions: '8.1' | ||
neos-versions: '8.3' | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: "Checkout code" | ||
uses: actions/checkout@v4 | ||
|
||
- name: "Install PHP with extensions" | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
|
||
- name: Set Neos Version | ||
run: composer require neos/neos ^${{ matrix.neos-versions }} --no-progress --no-interaction | ||
|
||
- name: Install Dependencies | ||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist | ||
|
||
- name: Execute tests via PHPUnit | ||
run: composer test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,8 @@ node_modules | |
*.DS_Store | ||
/.idea | ||
.remote-sync.json | ||
/bin | ||
/Packages | ||
composer.lock | ||
.phpunit.result.cache | ||
Tests/Reports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace CodeQ\ZoomApi\Domain\Model; | ||
|
||
class ZoomApiAccessToken | ||
{ | ||
public function __construct( | ||
public readonly string $accessToken, | ||
public readonly array $scope | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
namespace CodeQ\ZoomApi\Domain\Service; | ||
|
||
use CodeQ\ZoomApi\Domain\Model\ZoomApiAccessToken; | ||
use CodeQ\ZoomApi\ZoomApiException; | ||
use GuzzleHttp\Client; | ||
use Neos\Flow\Annotations as Flow; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* @Flow\Scope("singleton") | ||
*/ | ||
class ZoomApiAccessTokenFactory | ||
{ | ||
private Client $client; | ||
|
||
/** | ||
* @Flow\InjectConfiguration | ||
* @var array | ||
*/ | ||
protected array $settings; | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var LoggerInterface | ||
*/ | ||
protected $systemLogger; | ||
|
||
/** | ||
* @return void | ||
* @throws ZoomApiException | ||
*/ | ||
public function initializeObject(): void | ||
{ | ||
$zoomApiClientId = $this->settings['auth']['clientId']; | ||
$zoomApiClientSecret = $this->settings['auth']['clientSecret']; | ||
if (!$zoomApiClientId || !$zoomApiClientSecret) { | ||
throw new ZoomApiException('Please set a Client ID and Secret for CodeQ.ZoomApi to be able to authenticate.', 1695830249149); | ||
} | ||
$this->client = $this->buildClient($zoomApiClientId, $zoomApiClientSecret); | ||
} | ||
|
||
/** | ||
* @return ZoomApiAccessToken | ||
* @throws ZoomApiException | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
public function createFromConfiguration(): ZoomApiAccessToken | ||
{ | ||
$zoomApiAccountId = $this->settings['auth']['accountId']; | ||
if (!$zoomApiAccountId) { | ||
throw new ZoomApiException('Please set a Zoom Account ID for CodeQ.ZoomApi to be able to authenticate.', 1695904285296); | ||
} | ||
$response = $this->client->post('oauth/token', [ | ||
'http_errors' => false, | ||
'form_params' => [ | ||
'grant_type' => 'account_credentials', | ||
'account_id' => $zoomApiAccountId | ||
] | ||
]); | ||
|
||
if ($response->getStatusCode() !== 200) { | ||
throw new ZoomApiException('Could not fetch Zoom access token. Please check the settings for account ID, client ID and client secret, as well as your Zoom app.', 1695040346621); | ||
} | ||
|
||
$responseBodyAsArray = json_decode($response->getBody()->getContents(), true); | ||
|
||
if (!str_contains($responseBodyAsArray['scope'], 'user:read:admin') || !str_contains($responseBodyAsArray['scope'], 'recording:read:admin') || !str_contains($responseBodyAsArray['scope'], 'meeting:read:admin')) { | ||
throw new ZoomApiException('Please ensure your Zoom app has the following scopes: user:read:admin, recording:read:admin, meeting:read:admin', 1695040540417); | ||
} | ||
|
||
return new ZoomApiAccessToken( | ||
$responseBodyAsArray['access_token'], | ||
explode(',', $responseBodyAsArray['scope']) | ||
); | ||
} | ||
|
||
/** | ||
* @param string $zoomApiClientId | ||
* @param string $zoomApiClientSecret | ||
* | ||
* @return Client | ||
*/ | ||
protected function buildClient(string $zoomApiClientId, string $zoomApiClientSecret): Client | ||
{ | ||
return (new Client([ | ||
'base_uri' => 'https://zoom.us/', | ||
'headers' => [ | ||
'Authorization' => "Basic " . base64_encode($zoomApiClientId . ':' . $zoomApiClientSecret), | ||
'Content-Type' => 'application/json', | ||
], | ||
])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is still suspiciously not covered by tests - and has a bug (guess you can find it on your own ;) ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sollte jetzt gefixt sein, was meinst du? ;-)
Ich habe jetzt auch noch PHPStan hinzugefügt und Codesniffer