. */ namespace SP\Tests\Config; use DI\Container; use DI\DependencyException; use DI\NotFoundException; use PHPUnit\Framework\TestCase; use SP\Config\Config; use SP\Config\ConfigData; use SP\Core\Context\ContextInterface; use function SP\Tests\getResource; use function SP\Tests\saveResource; use function SP\Tests\setupContext; /** * Class ConfigTest * * Test de integración para comprobar el funcionamiento de la clase SP\Config\Config y sus utilidades * * @package SP\Tests */ class ConfigTest extends TestCase { /** * @var Container */ protected static $dic; /** * @var string */ protected static $currentConfig; /** * @throws DependencyException * @throws NotFoundException * @throws \SP\Core\Context\ContextException */ public static function setUpBeforeClass() { self::$dic = setupContext(); self::$currentConfig = getResource('config', 'config.xml'); } /** * This method is called after the last test of this test class is run. */ public static function tearDownAfterClass() { saveResource('config', 'config.xml', self::$currentConfig); } /** * Comprobar la carga de la configuración * * @throws DependencyException * @throws NotFoundException */ public function testLoadClass() { $config = self::$dic->get(Config::class); $this->assertInstanceOf(Config::class, $config); $this->assertFileExists(CONFIG_FILE); return $config; } /** * Comprobar que la configuración se guarda correctamente * * @depends testLoadClass * * @param Config $config * * @throws \SP\Storage\File\FileException */ public function testSaveConfig($config) { $config->saveConfig(new ConfigData(), false); $this->assertFileExists(CONFIG_FILE); } /** * Comprobar la carga de la configuración en el contexto * * @depends testLoadClass * * @param Config $config * * @throws DependencyException * @throws NotFoundException */ public function testLoadConfig($config) { $context = self::$dic->get(ContextInterface::class); $config->loadConfig($context); $this->assertInstanceOf(ConfigData::class, $context->getConfig()); } /** * Comprobar la actualización de la configuración * * @depends testLoadClass * * @param Config $config */ public function testUpdateConfig($config) { $config->updateConfig(new ConfigData()); $this->assertEquals(Config::getTimeUpdated(), $config->getConfigData()->getConfigDate()); } /** * Comprobar la generación de una clave de actualización y que su longitud es correcta * * @depends testLoadClass * * @param Config $config * * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException */ public function testGenerateUpgradeKey($config) { $config->generateUpgradeKey(); $this->assertEquals(32, strlen($config->getConfigData()->getUpgradeKey())); } }