-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create KernelTest and trait to test Config
- Loading branch information
mazarini
committed
Jan 21, 2024
1 parent
469e8ef
commit f8ddce4
Showing
6 changed files
with
126 additions
and
20 deletions.
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
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,33 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (C) 2024 Mazarini <mazarini@protonmail.com>. | ||
* This file is part of mazarini/config. | ||
* | ||
* mazarini/config is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at your | ||
* option) any later version. | ||
* | ||
* mazarini/config is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
*/ | ||
|
||
namespace Mazarini\Config; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; | ||
use Symfony\Component\HttpKernel\Kernel as BaseKernel; | ||
|
||
abstract class KernelTest extends BaseKernel | ||
{ | ||
use MicroKernelTrait; | ||
|
||
protected function getConfigDir(): string | ||
{ | ||
return $this->getProjectDir().'/tests/config'; | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (C) 2024 Mazarini <mazarini@protonmail.com>. | ||
* This file is part of mazarini/config. | ||
* | ||
* mazarini/config is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at your | ||
* option) any later version. | ||
* | ||
* mazarini/config is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
*/ | ||
|
||
namespace Mazarini\Config\Test; | ||
|
||
use Mazarini\Config\Config\ConfigInterface; | ||
|
||
trait ConfigTestTrait | ||
{ | ||
public function getConfig(): ConfigInterface | ||
{ | ||
$config = $this->getContainer()->get(ConfigInterface::class); | ||
if ($config instanceof ConfigInterface) { | ||
return $config; | ||
} | ||
throw new \LogicException(sprintf('Container don\'t contain "%s"', ConfigInterface::class)); | ||
} | ||
|
||
/** | ||
* setConfig. | ||
* | ||
* @param array<string,mixed> $data | ||
*/ | ||
public function setConfig(array $data): static | ||
{ | ||
$config = $this->getConfig(); | ||
(new \ReflectionClass($config::class)) | ||
->getProperty('configData') | ||
->setValue($config, array_merge($config->getData(), $data)) | ||
; | ||
|
||
return $this; | ||
} | ||
} |
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
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
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,38 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (C) 2024 Mazarini <mazarini@protonmail.com>. | ||
* This file is part of mazarini/config. | ||
* | ||
* mazarini/config is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at your | ||
* option) any later version. | ||
* | ||
* mazarini/config is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
*/ | ||
|
||
namespace App\Tests\ConfigurationPager; | ||
|
||
use Mazarini\Config\Test\ConfigTestTrait; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
|
||
class UpdateTest extends KernelTestCase | ||
{ | ||
use ConfigTestTrait; | ||
|
||
public function testModifiyConfig(): void | ||
{ | ||
$this->setConfig([ | ||
'type' => [ | ||
'string' => 'set', | ||
], | ||
]); | ||
$this->assertSame('set', $this->getConfig()->getValue('type.string')); | ||
} | ||
} |