Skip to content

Commit

Permalink
Adjusted integration for Ilias release_8
Browse files Browse the repository at this point in the history
  • Loading branch information
thojou committed Feb 28, 2024
1 parent 24b06ff commit 054c74b
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 23 deletions.
34 changes: 25 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
name: CI

env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
PLUGIN_PATH: Customizing/global/libs/ilias-plugin-utils
MATRIX: |
{
"release/7": {"php": ["7.4"], "ilias": ["release_7"]},
"release/8": {"php": ["8.0"], "ilias": ["release_8"]}
}
on:
push:
branches:
- release/*
pull_request:

jobs:
build-matrix:
if: "!contains(github.event.head_commit.message, '[CI SKIP]')"
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: echo "$(echo $MATRIX | jq -c --arg branch $BRANCH_NAME '.[$branch]')" >> $GITHUB_OUTPUT

PHPUnit:
name: PHPUnit (PHP ${{ matrix.php }})
if: "!contains(github.event.head_commit.message, '[CI SKIP]')"
runs-on: ubuntu-22.04
env:
PLUGIN_PATH: Customizing/global/libs/ilias-plugin-utils
needs: build-matrix
name: Check (ILIAS ${{ matrix.ilias }} PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
matrix:
php:
- 8.0
- 7.4
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
with:
repository: ILIAS-eLearning/ILIAS
ref: release_8
ref: ${{ matrix.ilias }}
- uses: actions/checkout@v4
with:
path: ${{ env.PLUGIN_PATH }}
Expand Down
4 changes: 2 additions & 2 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
TXT;

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__);
->in(__DIR__)
->exclude('vendor');

return (new PhpCsFixer\Config())
->setRules([
Expand Down
4 changes: 3 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="tests/bootstrap.php"
executionOrder="depends,defects"
backupGlobals="true"
backupStaticAttributes="true"
cacheResult="false"
colors="true"
executionOrder="depends,defects"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuites>
<testsuite name="Ilias Plugin Utils">
Expand Down
2 changes: 1 addition & 1 deletion src/DI/PluginContainerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
* @author Thomas Joußen <[email protected]>
* @see https://www.php-fig.org/psr/psr-11/#32-psrcontainercontainerexceptioninterface
*/
class PluginContainerException extends \RuntimeException implements ContainerExceptionInterface
class PluginContainerException extends Exception implements ContainerExceptionInterface
{
}
3 changes: 2 additions & 1 deletion src/DI/PluginContainerNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Thojou\Ilias\Plugin\Utils\DI;

use Exception;
use Psr\Container\NotFoundExceptionInterface;

/**
Expand All @@ -23,6 +24,6 @@
* @author Thomas Joußen <[email protected]>
* @see https://www.php-fig.org/psr/psr-11/#33-psrcontainernotfoundexceptioninterface
*/
class PluginContainerNotFoundException extends \Exception implements NotFoundExceptionInterface
class PluginContainerNotFoundException extends Exception implements NotFoundExceptionInterface
{
}
2 changes: 0 additions & 2 deletions src/DI/PluginContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use Psr\Container\ContainerInterface;
use RuntimeException;

use function is_object;

/**
* PluginContainerTrait
*
Expand Down
2 changes: 1 addition & 1 deletion src/DI/PluginContainerWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function get(string $id)
{
$id = $this->resolveId($id);

if(!$this->has($id)) {
if(!isset($this->container[$id])) {
throw new PluginContainerNotFoundException("Service with id '$id' not found in PluginContainer.");
}

Expand Down
2 changes: 0 additions & 2 deletions src/Test/TestCase/AbstractGUITestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
namespace Thojou\Ilias\Plugin\Utils\Test\TestCase;

use ILIAS\HTTP\Wrapper\WrapperFactory;
use ILIAS\Refinery\Factory as Refinery;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
Expand Down
2 changes: 0 additions & 2 deletions src/Test/TestCase/AbstractPluginTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Thojou\Ilias\Plugin\Utils\Test\TestCase;

use ilDBInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Thojou\Ilias\Plugin\Utils\Test\ContainerMockHelperInterface;
use Thojou\Ilias\Plugin\Utils\Test\Traits\CommonHelperTrait;
Expand Down
1 change: 0 additions & 1 deletion src/Test/Traits/ContainerMockHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Thojou\Ilias\Plugin\Utils\Test\Traits;

use ilCoSourceCodePlugin;
use ILIAS\DI\Container;
use Thojou\Ilias\Plugin\Utils\Test\ContainerMockHelperInterface;

Expand Down
28 changes: 28 additions & 0 deletions tests/DI/PluginContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ILIAS\DI\Container;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use Thojou\Ilias\Plugin\Utils\DI\PluginContainerException;
use Thojou\Ilias\Plugin\Utils\DI\PluginContainerNotFoundException;
use Thojou\Ilias\Plugin\Utils\DI\PluginContainerWrapper;
use Thojou\Ilias\Plugin\Utils\Tests\DI\Fixtures\TestPluginContainer;
Expand Down Expand Up @@ -72,6 +73,11 @@ public function testGetService(): void
{
$service = $this->createMock(stdClass::class);
$DIC = $this->createMock(Container::class);
$DIC
->expects($this->once())
->method('offsetExists')
->with($this->equalTo('plugin_id'.'.' . stdClass::class))
->willReturn(true);
$DIC
->expects($this->once())
->method('offsetGet')
Expand All @@ -82,4 +88,26 @@ public function testGetService(): void
$this->assertSame($service, TestPluginContainer::get()->plugin()->get(stdClass::class));
}

public function testPluginContainerException()
{
$this->expectException(PluginContainerException::class);

$DIC = $this->createMock(Container::class);
$DIC
->expects($this->once())
->method('offsetExists')
->with($this->equalTo('plugin_id'.'.' . stdClass::class))
->willReturn(true);

$DIC
->expects($this->once())
->method('offsetGet')
->willReturnCallback(function () {
throw new RuntimeException('Test');
});

TestPluginContainer::init($DIC, 'plugin_id');
TestPluginContainer::get()->plugin()->get(stdClass::class);
}

}
73 changes: 73 additions & 0 deletions tests/DI/PluginContainerWrapperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Thojou\Ilias\Plugin\Utils\Tests\DI;

use Exception;
use PHPUnit\Framework\TestCase;
use Thojou\Ilias\Plugin\Utils\DI\PluginContainerException;
use Thojou\Ilias\Plugin\Utils\DI\PluginContainerNotFoundException;
use Thojou\Ilias\Plugin\Utils\DI\PluginContainerWrapper;
use ILIAS\DI\Container;

class PluginContainerWrapperTest extends TestCase
{
public function testGet()
{
$container = $this->createMock(Container::class);
$container->method('offsetExists')->willReturn(true);
$container->method('offsetGet')->willReturn('service');
$pluginContainerWrapper = new PluginContainerWrapper($container);

$this->assertEquals('service', $pluginContainerWrapper->get('service'));
}

public function testGetWithPrefix()
{
$container = $this->createMock(Container::class);
$container->method('offsetExists')->willReturn(true);
$container->method('offsetGet')->willReturn('service');
$pluginContainerWrapper = new PluginContainerWrapper($container, 'prefix_');

$this->assertEquals('service', $pluginContainerWrapper->get('service'));
}

public function testHas()
{
$container = $this->createMock(Container::class);
$container->method('offsetExists')->willReturn(true);
$pluginContainerWrapper = new PluginContainerWrapper($container);

$this->assertTrue($pluginContainerWrapper->has('service'));
}

public function testHasReturnsFalse()
{
$container = $this->createMock(Container::class);
$container->method('offsetExists')->willReturn(false);
$pluginContainerWrapper = new PluginContainerWrapper($container);

$this->assertFalse($pluginContainerWrapper->has('nonexistent_service'));
}

public function testGetThrowsNotFoundException()
{
$this->expectException(PluginContainerNotFoundException::class);

$container = $this->createMock(Container::class);
$container->method('offsetExists')->willReturn(false);
$pluginContainerWrapper = new PluginContainerWrapper($container);

$pluginContainerWrapper->get('nonexistent_service');
}

public function testGetThrowsContainerException()
{
$container = $this->createMock(Container::class);
$container->method('offsetExists')->willReturn(true);
$container->method('offsetGet')->will($this->throwException(new Exception()));
$pluginContainerWrapper = new PluginContainerWrapper($container);

$this->expectException(PluginContainerException::class);
$pluginContainerWrapper->get('service_causing_exception');
}
}
1 change: 0 additions & 1 deletion tests/Test/Traits/ContainerMockHelperTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use ilComponentRepositoryWrite;
use ILIAS\DI\Container;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use stdClass;
use Thojou\Ilias\Plugin\Utils\Test\ContainerMockHelperInterface;
Expand Down

0 comments on commit 054c74b

Please sign in to comment.