Skip to content
Snippets Groups Projects
Commit ed17f707 authored by Marko Ivancic's avatar Marko Ivancic
Browse files

WIP

parent 970c6178
No related branches found
No related tags found
1 merge request!1Relate histories
/.idea/
/vendor/
/build/
\ No newline at end of file
......@@ -19,6 +19,11 @@
"SimpleSAML\\Module\\accounting\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"SimpleSAML\\Test\\Module\\accounting\\": "tests/"
}
},
"require": {
"php": "^7.4 || ^8.0",
"ext-pdo": "*",
......
<?php
$config = [
];
\ No newline at end of file
'test-config' => 'test-value',
];
<?xml version="1.0"?>
<ruleset name="SimpleSAMLphp accounting module ruleset">
<file>config-templates</file>
<file>src</file>
<file>tests</file>
<file>www</file>
<!-- Use this to exclude paths. You can have multiple patterns -->
<!--<exclude-pattern>*/tests/*</exclude-pattern>-->
<!--<exclude-pattern>*/other/*</exclude-pattern>-->
<exclude-pattern>www/assets/*</exclude-pattern>
<!-- This is the rule we inherit from. If you want to exlude some specific rules, see the docs on how to do that -->
<rule ref="PSR12"/>
</ruleset>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile="build/.phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage cacheDirectory="build/.phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="build/coverage/clover.xml"/>
<html outputDirectory="build/coverage/html"/>
<text outputFile="php://stdout"/>
</report>
</coverage>
<logging>
<junit outputFile="build/logs/junit.xml"/>
</logging>
<php>
<env name="SIMPLESAMLPHP_CONFIG_DIR" value="tests/config-templates"/>
</php>
</phpunit>
<?xml version="1.0"?>
<psalm
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<directory name="config-templates" />
<directory name="tests" />
<directory name="www" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<!-- Ignore the fact that $config variable is not used in particular config files. -->
<UnusedVariable>
<errorLevel type="suppress">
<directory name="config-templates" />
<directory name="tests/config-templates" />
</errorLevel>
</UnusedVariable>
<!--
Ignore PropertyNotSetInConstructor for phpunit tests. For example, this will ignore things like
"Property SomeTestClass::$backupStaticAttributes is not defined in constructor of SomeTestClass..."
-->
<PropertyNotSetInConstructor>
<errorLevel type="suppress">
<directory name="tests" />
</errorLevel>
</PropertyNotSetInConstructor>
</issueHandlers>
</psalm>
File moved
services:
# default configuration for services in *this* file
_defaults:
public: false
SimpleSAML\Module\accounting\ModuleConfiguration:
class: SimpleSAML\Module\accounting\ModuleConfiguration
\ No newline at end of file
......@@ -4,6 +4,7 @@ namespace SimpleSAML\Module\accounting\Controller;
use SimpleSAML\Configuration;
use SimpleSAML\Locale\Translate;
use SimpleSAML\Module\accounting\ModuleConfiguration;
use SimpleSAML\Session;
use SimpleSAML\XHTML\Template;
use Symfony\Component\HttpFoundation\Request;
......@@ -12,15 +13,21 @@ class Test
{
protected Configuration $configuration;
protected Session $session;
protected ModuleConfiguration $moduleConfiguration;
/**
* @param Configuration $configuration
* @param Session $session The current user session.
* @param ModuleConfiguration $moduleConfiguration
*/
public function __construct(Configuration $configuration, Session $session)
{
public function __construct(
Configuration $configuration,
Session $session,
ModuleConfiguration $moduleConfiguration
) {
$this->configuration = $configuration;
$this->session = $session;
$this->moduleConfiguration = $moduleConfiguration;
}
/**
......@@ -30,10 +37,11 @@ class Test
*/
public function test(Request $request): Template
{
$template = new Template(Configuration::getConfig(), 'accounting:configuration.twig');
$template = new Template($this->configuration, 'accounting:configuration.twig');
$template->data = [
'test' => Translate::noop('Accounting'),
'test_config' => $this->moduleConfiguration->getConfiguration()->getString('test_config'),
];
return $template;
......
<?php
namespace SimpleSAML\Module\accounting\Exceptions;
class InvalidConfigurationNameException extends \InvalidArgumentException
{
}
<?php
namespace SimpleSAML\Module\accounting;
use SimpleSAML\Configuration;
use SimpleSAML\Module\accounting\Exceptions\InvalidConfigurationNameException;
class ModuleConfiguration
{
protected Configuration $configuration;
public const FILE_NAME = 'module_accounting.php';
/**
* @throws \Exception
*/
public function __construct(string $fileName = null)
{
$fileName = $fileName ?? self::FILE_NAME;
$this->configuration = Configuration::getConfig($fileName);
}
/**
* @param string $name
* @return mixed
*/
public function getValue(string $name)
{
if (! $this->configuration->hasValue($name)) {
throw new InvalidConfigurationNameException(sprintf('Config name does not exist (%s).', $name));
}
return $this->configuration->getValue($name);
}
/**
* @return Configuration
*/
public function getConfiguration(): Configuration
{
return $this->configuration;
}
}
......@@ -12,7 +12,8 @@
<h2>{{ pagetitle }} </h2>
<p>
{{ test }}
{{ test }}, <br>
{{ test_config }}
</p>
{% endblock %}
<?php
namespace SimpleSAML\Test\Module\accounting;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Configuration;
use SimpleSAML\Module\accounting\ModuleConfiguration;
/**
* @covers \SimpleSAML\Module\accounting\ModuleConfiguration
*/
class ModuleConfigurationTest extends TestCase
{
public function testSample(): void
{
$moduleConfiguration = new ModuleConfiguration('module_accounting_basic.php');
$this->assertInstanceOf(Configuration::class, $moduleConfiguration->getConfiguration());
}
}
<?php
$config = [
'test-config' => 'test-value',
];
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment