Skip to content

Commit

Permalink
feat(ci): implement base of test unit and move current ci to codding …
Browse files Browse the repository at this point in the history
…standards and implement missing docs
  • Loading branch information
jorisdugue committed Nov 5, 2024
1 parent 99b2c63 commit 8b3d86a
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 35 deletions.
50 changes: 41 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
name: CI
name: "CI Tests"

on: [push]
on: [push, pull_request]

jobs:
build-test:
runs-on: ubuntu-latest

test:
runs-on: 'ubuntu-20.04'
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3']
symfony: ['6.0.*', '6.1.*', '6.2.*', '6.3.*', '6.4.*', '7.0.*', '7.1.*']
composer-flags: ['--prefer-stable']
extensions: ['curl, iconv, mbstring, pdo, pdo_sqlite, sqlite, zip']
include:
- php: '8.1'
symfony: '6.0.*'
composer-flags: '--prefer-stable --prefer-lowest'
extensions: 'curl, iconv, mbstring, pdo, pdo_sqlite, sqlite, zip'
exclude:
- php: '8.2'
symfony: '6.0.*'
name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"
steps:
- uses: actions/checkout@v3
- uses: php-actions/composer@v6
- uses: php-actions/phpstan@v3
- name: Checkout Code
uses: actions/checkout@v4
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: dependencies-symfony-${{ matrix.symfony }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}-flags-${{ matrix.composer-flags }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
memory_limit: -1
php-version: ${{ matrix.php }}
tools: composer:v2, flex
extensions: ${{ matrix.extensions }}
coverage: none
- name: Install dependencies
run: composer update ${{ matrix.composer-flags }} --prefer-dist --no-suggest
env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}

- name: Run PHPUnit
run: bin/phpunit --verbose

13 changes: 13 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "CI Tests"

on: [push, pull_request]
jobs:
build-lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: php-actions/composer@v6
- uses: php-actions/phpstan@v3
with:
memory_limit: -1
19 changes: 12 additions & 7 deletions Core/H5PIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,25 @@ public function __construct(
}

/**
* Prepares the generic H5PIntegration settings
* Prepares the generic H5PIntegration settings.
* @return array|null
*/
public function getGenericH5PIntegrationSettings()
public function getGenericH5PIntegrationSettings(): ?array
{
static $settings;
if (!empty($settings)) {
// Only needs to be generated the first time
return $settings;
}

// Load current user
$user = $this->getCurrentOrAnonymousUser();

// Load configuration settings
$saveContentState = $this->options->getOption('save_content_state', false);
$saveContentFrequency = $this->options->getOption('save_content_frequency', 30);
$hubIsEnabled = $this->options->getOption('hub_is_enabled', true);

// Create AJAX URLs
$setFinishedUrl = $this->router->generate('studit_h5p_h5pinteraction_setfinished', [
'token' => \H5PCore::createToken('result')
Expand All @@ -101,6 +105,7 @@ public function getGenericH5PIntegrationSettings()
'subContentId' => ':subContentId',
'token' => \H5PCore::createToken('contentuserdata')
]);

// Define the generic H5PIntegration settings
$settings = [
'baseUrl' => "/",
Expand Down Expand Up @@ -224,7 +229,7 @@ protected function getExportUrl(Content $content): string
}
}

public function getEditorIntegrationSettings($contentId = null)
public function getEditorIntegrationSettings($contentId = null): array
{
$editorSettings = [
'filesPath' => $this->options->getRelativeH5PPath(),
Expand Down Expand Up @@ -271,7 +276,7 @@ private function getEditorAssets(): array
}

/**
* Extracts assets from a collection of assets
* Extracts assets from a collection of assets.
*
* @param array $collection Collection of assets
* @param string $prefix Prefix needed for constructing the file-path of the assets
Expand All @@ -294,7 +299,7 @@ private function getAssets($collection, $prefix, $exceptions = null): array
}

/**
* Get cache buster
* Get cache buster.
*
* @return string A cache buster that may be applied to resources
*/
Expand All @@ -305,7 +310,7 @@ public function getCacheBuster(): string
}

/**
* Translation file path for the editor. Defaults to English if chosen
* Translation file path for the editor. Defaults to English if chosen.
* language is not available.
*
* @return string Path to translation file for editor
Expand Down Expand Up @@ -334,7 +339,7 @@ private function getH5PAssetUrl(): string
}

/**
* Access to direct access to the configuration to save time
* Access to direct access to the configuration to save time.
* @return H5POptions
*/
public function getOptions(): H5POptions
Expand Down
6 changes: 3 additions & 3 deletions Core/H5POptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,20 @@ public function getUploadedH5pPath($set = null)
public function getRelativeH5PPath()
{
$dir = $this->getOption('storage_dir');
return $dir[0] === '/' ? $dir : '/' . $dir;
return $dir[0] === '/' ? $dir : "/{$dir}";
}

public function getAbsoluteH5PPathWithSlash(): string
{
$dir = $this->getOption('storage_dir');
$dir = $dir[0] === '/' ? $dir : '/' . $dir;
$dir = $dir[0] === '/' ? $dir : "/{$dir}";

return $this->getAbsoluteWebPath() . $dir . '/';
}
public function getAbsoluteH5PPath(): string
{
$dir = $this->getOption('storage_dir');
$dir = $dir[0] === '/' ? $dir : '/' . $dir;
$dir = $dir[0] === '/' ? $dir : "/{$dir}";

return $this->getAbsoluteWebPath() . $dir;
}
Expand Down
10 changes: 5 additions & 5 deletions Core/H5PSymfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,16 +548,16 @@ public function saveLibraryData(&$libraryData, $new = true)
}

/**
* Convert list of file paths to csv
* Convert list of file paths to csv.
*
* @param array $libraryData
* Library data as found in library.json files
* @param string $key
* Key that should be found in $libraryData
* @return string
* file paths separated by ', '
* @param array $libraryData
* @param string $key
* @return string
*/
private function pathsToCsv($libraryData, $key)
private function pathsToCsv(array $libraryData, string $key): string
{
if (isset($libraryData[$key])) {
$paths = array();
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Configuration implements ConfigurationInterface
* version of Symfony H5P bundle
* @return string
*/
const H5P_VERSION = '2.2.1';
const H5P_VERSION = '3.0.0';

/**
* Generates the configuration tree.
Expand Down
2 changes: 1 addition & 1 deletion Editor/EditorAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getLatestLibraryVersions(): array


/**
* Get locally stored Content Type Cache. If machine name is provided
* Get locally stored Content Type Cache. If machine name is provided.
* it will only get the given content type from the cache
*
* @param $machineName
Expand Down
6 changes: 3 additions & 3 deletions Editor/EditorStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ public function getAvailableLanguages($machineName, $majorVersion, $minorVersion
* "Callback" for mark the given file as a permanent file.
* Used when saving content that has new uploaded files.
*
* @param string $path To new file
* @param int $fileId To new file
*/
public function keepFile($path)
public function keepFile($fileId)
{
var_dump($path);
var_dump($fileId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Editor/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
class Utilities
{
/**
* Extract library information from library string
* Extract library information from library string.
*
* @param string $library Library string with versioning, e.g. H5P.MultiChoice 1.9
* @return array|bool
*/
public static function getLibraryProperties($library)
public static function getLibraryProperties($library): array|bool
{
$matches = [];
preg_match_all('/(.+)\s(\d+)\.(\d+)$/', $library, $matches);
Expand Down
9 changes: 5 additions & 4 deletions Service/ResultService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ResultService

/**
* ResultService constructor.
* @param EntityManagerInterface $em
*/
public function __construct(EntityManagerInterface $em)
{
Expand All @@ -26,7 +27,7 @@ public function __construct(EntityManagerInterface $em)
* @param $userId
* @return ContentResult
*/
public function handleRequestFinished(Request $request, $userId)
public function handleRequestFinished(Request $request, $userId): ContentResult
{
$contentId = $request->get('contentId', false);
if (!$contentId) {
Expand All @@ -49,13 +50,13 @@ public function handleRequestFinished(Request $request, $userId)
}

/**
* remove data in content User Data
* remove data in content User Data.
* @param integer $contentId
* @param string $dataType
* @param $user
* @param int|null|string $user Current user
* @param integer $subContentId
*/
public function removeData($contentId, $dataType, $user, $subContentId)
public function removeData(int $contentId, string $dataType, $user, int $subContentId): void
{
$ContentUserData = $this->em->getRepository('Studit\H5PBundle\Entity\ContentUserData')->findBy(
[
Expand Down

0 comments on commit 8b3d86a

Please sign in to comment.