|
|
@@ -6,16 +6,16 @@ use App\Entity\Organization\Organization;
|
|
|
use App\Entity\Organization\Settings;
|
|
|
use App\Service\Cotisation\Utils as CotisationUtils;
|
|
|
use App\Service\Security\Module;
|
|
|
-use App\Service\Utils\Parser;
|
|
|
+use App\Service\Utils\ConfigUtils;
|
|
|
+use App\Service\Utils\Parser\YamlParser;
|
|
|
use App\Service\Utils\Reflection;
|
|
|
+use Hoa\Iterator\Mock;
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
+use PHPUnit\Util\Test;
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
|
|
|
|
|
class TestableModule extends Module {
|
|
|
- public function loadModuleConfig(): array { return parent::loadModuleConfig(); }
|
|
|
- public function getModuleConfig(): array { return parent::getModuleConfig(); }
|
|
|
- public function loadModuleByConditionsConfig(): array { return parent::loadModuleByConditionsConfig(); }
|
|
|
public function getModuleByConditionsConfig(): array { return parent::getModuleByConditionsConfig(); }
|
|
|
}
|
|
|
|
|
|
@@ -24,12 +24,19 @@ class ModuleTest extends TestCase
|
|
|
private const OPENTALENT_CONFIG = __DIR__.'/../../../config/opentalent';
|
|
|
|
|
|
private MockObject | Reflection $reflection;
|
|
|
- private MockObject | Parser $parser;
|
|
|
+ private MockObject | YamlParser $parser;
|
|
|
|
|
|
public function setUp():void
|
|
|
{
|
|
|
$this->reflection = $this->getMockBuilder(Reflection::class)->disableOriginalConstructor()->getMock();
|
|
|
- $this->parser = $this->getMockBuilder(Parser::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->configUtils = $this->getMockBuilder(ConfigUtils::class)->disableOriginalConstructor()->getMock();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getMockForMethod(string $methodName): MockObject | TestableModule {
|
|
|
+ return $this->getMockBuilder(TestableModule::class)
|
|
|
+ ->setConstructorArgs([$this->reflection, $this->configUtils])
|
|
|
+ ->setMethodsExcept([$methodName])
|
|
|
+ ->getMock();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -37,10 +44,7 @@ class ModuleTest extends TestCase
|
|
|
*/
|
|
|
public function testGetOrganizationModules(): void
|
|
|
{
|
|
|
- $module = $this->getMockBuilder(Module::class)
|
|
|
- ->setConstructorArgs([$this->reflection, $this->parser, self::OPENTALENT_CONFIG])
|
|
|
- ->setMethodsExcept(['getOrganizationModules'])
|
|
|
- ->getMock();
|
|
|
+ $module = $this->getMockForMethod('getOrganizationModules');
|
|
|
|
|
|
$module->expects(self::once())->method('getModuleBySettings')->willReturn(['Sms']);
|
|
|
$module->expects(self::once())->method('getModulesByConditions')->willReturn(['CotisationCall']);
|
|
|
@@ -64,10 +68,7 @@ class ModuleTest extends TestCase
|
|
|
*/
|
|
|
public function testGetModuleBySettings(): void
|
|
|
{
|
|
|
- $module = $this->getMockBuilder(TestableModule::class)
|
|
|
- ->setConstructorArgs([$this->reflection, $this->parser, self::OPENTALENT_CONFIG])
|
|
|
- ->setMethodsExcept(['getModuleBySettings'])
|
|
|
- ->getMock();
|
|
|
+ $module = $this->getMockForMethod('getModuleBySettings');
|
|
|
|
|
|
$settings = $this->getMockBuilder(Settings::class)->getMock();
|
|
|
$settings
|
|
|
@@ -89,12 +90,9 @@ class ModuleTest extends TestCase
|
|
|
*/
|
|
|
public function testGetModulesByConditions(): void
|
|
|
{
|
|
|
- $module = $this->getMockBuilder(TestableModule::class)
|
|
|
- ->setConstructorArgs([$this->reflection, $this->parser, self::OPENTALENT_CONFIG])
|
|
|
- ->setMethodsExcept(['getModulesByConditions'])
|
|
|
- ->getMock();
|
|
|
+ $module = $this->getMockForMethod('getModulesByConditions');
|
|
|
|
|
|
- $module->method('getModuleByConditionsConfig')->willReturn(
|
|
|
+ $this->configUtils->method('loadFromFile')->with('modulesbyconditions')->willReturn(
|
|
|
['opentalent' =>
|
|
|
['modulesbyconditions' =>
|
|
|
['CotisationCall' => [
|
|
|
@@ -124,12 +122,9 @@ class ModuleTest extends TestCase
|
|
|
*/
|
|
|
public function testGetModulesByConditionsLogicError(): void
|
|
|
{
|
|
|
- $module = $this->getMockBuilder(TestableModule::class)
|
|
|
- ->setConstructorArgs([$this->reflection, $this->parser, self::OPENTALENT_CONFIG])
|
|
|
- ->setMethodsExcept(['getModulesByConditions'])
|
|
|
- ->getMock();
|
|
|
+ $module = $this->getMockForMethod('getModulesByConditions');
|
|
|
|
|
|
- $module->method('getModuleByConditionsConfig')->willReturn(
|
|
|
+ $this->configUtils->method('loadFromFile')->with('modulesbyconditions')->willReturn(
|
|
|
['opentalent' =>
|
|
|
['modulesbyconditions' =>
|
|
|
['CotisationCall' => []]
|
|
|
@@ -153,12 +148,11 @@ class ModuleTest extends TestCase
|
|
|
*/
|
|
|
public function testGetModulesByProductConfiguration(): void
|
|
|
{
|
|
|
- $module = $this->getMockBuilder(TestableModule::class)
|
|
|
- ->setConstructorArgs([$this->reflection, $this->parser, self::OPENTALENT_CONFIG])
|
|
|
- ->setMethodsExcept(['getModulesByProductConfiguration'])
|
|
|
- ->getMock();
|
|
|
+ $module = $this->getMockForMethod('getModulesByProductConfiguration');
|
|
|
|
|
|
- $module->method('getModuleConfig')->willReturn(['opentalent' => ['products' => ['artist' => ['modules' => ['foo']]]]]);
|
|
|
+ $this->configUtils->method('loadFromFile')->with('products')->willReturn(
|
|
|
+ ['opentalent' => ['products' => ['artist' => ['modules' => ['foo']]]]]
|
|
|
+ );
|
|
|
|
|
|
$this->assertEquals(['foo'], $module->getModulesByProductConfiguration('artist')) ;
|
|
|
}
|
|
|
@@ -168,12 +162,9 @@ class ModuleTest extends TestCase
|
|
|
*/
|
|
|
public function testGetModulesByProductConfigurationExtend(): void
|
|
|
{
|
|
|
- $module = $this->getMockBuilder(TestableModule::class)
|
|
|
- ->setConstructorArgs([$this->reflection, $this->parser, self::OPENTALENT_CONFIG])
|
|
|
- ->setMethodsExcept(['getModulesByProductConfiguration'])
|
|
|
- ->getMock();
|
|
|
+ $module = $this->getMockForMethod('getModulesByProductConfiguration');
|
|
|
|
|
|
- $module->method('getModuleConfig')->willReturn(
|
|
|
+ $this->configUtils->method('loadFromFile')->with('products')->willReturn(
|
|
|
['opentalent' =>
|
|
|
['products' =>
|
|
|
[
|
|
|
@@ -195,12 +186,13 @@ class ModuleTest extends TestCase
|
|
|
*/
|
|
|
public function testGetModulesByProductConfigurationAccessDenied(): void
|
|
|
{
|
|
|
- $module = $this->getMockBuilder(TestableModule::class)
|
|
|
- ->setConstructorArgs([$this->reflection, $this->parser, self::OPENTALENT_CONFIG])
|
|
|
- ->setMethodsExcept(['getModulesByProductConfiguration'])
|
|
|
- ->getMock();
|
|
|
+ $module = $this->getMockBuilder(TestableModule::class);
|
|
|
|
|
|
- $module->method('getModuleConfig')->willReturn(['opentalent' => ['products' => ['artist' => ['modules' => ['foo']]]]]);
|
|
|
+ $module = $this->getMockForMethod('getModulesByProductConfiguration');
|
|
|
+
|
|
|
+ $this->configUtils->method('loadFromFile')->with('products')->willReturn(
|
|
|
+ ['opentalent' => ['products' => ['artist' => ['modules' => ['foo']]]]]
|
|
|
+ );
|
|
|
|
|
|
$this->expectException(AccessDeniedHttpException::class);
|
|
|
$this->expectExceptionMessage('The product artist_premium does not exist !');
|
|
|
@@ -208,88 +200,13 @@ class ModuleTest extends TestCase
|
|
|
$module->getModulesByProductConfiguration('artist-premium');
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @see Module::getModuleConfig()
|
|
|
- */
|
|
|
- public function testGetModuleConfig(): void {
|
|
|
- $module = $this->getMockBuilder(TestableModule::class)
|
|
|
- ->setConstructorArgs([$this->reflection, $this->parser, self::OPENTALENT_CONFIG])
|
|
|
- ->setMethodsExcept(['getModuleConfig'])
|
|
|
- ->getMock();
|
|
|
-
|
|
|
- $module->expects(self::once())->method('loadModuleConfig')->willReturn(['foo']);
|
|
|
-
|
|
|
- $this->assertEquals(['foo'], $module->getModuleConfig());
|
|
|
- $this->assertEquals(['foo'], $module->getModuleConfig());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @see Module::loadModuleConfig()
|
|
|
- */
|
|
|
- public function testLoadModuleConfig(): void {
|
|
|
- $module = $this->getMockBuilder(TestableModule::class)
|
|
|
- ->setConstructorArgs([$this->reflection, $this->parser, self::OPENTALENT_CONFIG])
|
|
|
- ->setMethodsExcept(['loadModuleConfig'])
|
|
|
- ->getMock();
|
|
|
-
|
|
|
- $this->parser
|
|
|
- ->expects(self::once())
|
|
|
- ->method('yamlParser')
|
|
|
- ->with(self::OPENTALENT_CONFIG, 'products.yaml')
|
|
|
- ->willReturn(['foo']);
|
|
|
-
|
|
|
- $this->assertEquals(
|
|
|
- ['foo'],
|
|
|
- $module->loadModuleConfig()
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @see Module::getModuleByConditionsConfig()
|
|
|
- */
|
|
|
- public function testGetModuleByConditionsConfig(): void {
|
|
|
- $module = $this->getMockBuilder(TestableModule::class)
|
|
|
- ->setConstructorArgs([$this->reflection, $this->parser, self::OPENTALENT_CONFIG])
|
|
|
- ->setMethodsExcept(['getModuleByConditionsConfig'])
|
|
|
- ->getMock();
|
|
|
-
|
|
|
- $module->expects(self::once())->method('loadModuleByConditionsConfig')->willReturn(['foo']);
|
|
|
-
|
|
|
- $this->assertEquals(['foo'], $module->getModuleByConditionsConfig());
|
|
|
- $this->assertEquals(['foo'], $module->getModuleByConditionsConfig());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @see Module::loadModuleByConditionsConfig()
|
|
|
- */
|
|
|
- public function testLoadModuleByConditionsConfig(): void {
|
|
|
- $module = $this->getMockBuilder(TestableModule::class)
|
|
|
- ->setConstructorArgs([$this->reflection, $this->parser, self::OPENTALENT_CONFIG])
|
|
|
- ->setMethodsExcept(['loadModuleByConditionsConfig'])
|
|
|
- ->getMock();
|
|
|
-
|
|
|
- $this->parser->expects(self::once())
|
|
|
- ->method('yamlParser')
|
|
|
- ->with(self::OPENTALENT_CONFIG, 'modulesbyconditions.yaml')
|
|
|
- ->willReturn(['foo']);
|
|
|
-
|
|
|
- $this->assertEquals(
|
|
|
- ['foo'],
|
|
|
- $module->loadModuleByConditionsConfig()
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* @see Module::getModuleByResourceName()
|
|
|
*/
|
|
|
public function testGetModuleByResourceName(): void {
|
|
|
- $module = $this->getMockBuilder(TestableModule::class)
|
|
|
- ->setConstructorArgs([$this->reflection, $this->parser, self::OPENTALENT_CONFIG])
|
|
|
- ->setMethodsExcept(['getModuleByResourceName'])
|
|
|
- ->getMock();
|
|
|
+ $module = $this->getMockForMethod('getModuleByResourceName');
|
|
|
|
|
|
-
|
|
|
- $module->method('getModuleConfig')->willReturn(
|
|
|
+ $this->configUtils->method('loadFromFile')->with('products')->willReturn(
|
|
|
['opentalent' =>
|
|
|
['modules' =>
|
|
|
['Core' => ['entities' => ['foo', 'bar']]]
|
|
|
@@ -304,12 +221,9 @@ class ModuleTest extends TestCase
|
|
|
* @see Module::getModuleByResourceName()
|
|
|
*/
|
|
|
public function testGetModuleByResourceNameNotFound(): void {
|
|
|
- $module = $this->getMockBuilder(TestableModule::class)
|
|
|
- ->setConstructorArgs([$this->reflection, $this->parser, self::OPENTALENT_CONFIG])
|
|
|
- ->setMethodsExcept(['getModuleByResourceName'])
|
|
|
- ->getMock();
|
|
|
+ $module = $this->getMockForMethod('getModuleByResourceName');
|
|
|
|
|
|
- $module->method('getModuleConfig')->willReturn(
|
|
|
+ $this->configUtils->method('loadFromFile')->with('products')->willReturn(
|
|
|
['opentalent' =>
|
|
|
['modules' =>
|
|
|
['Core' => ['entities' => ['bar']]]
|