
| Current Path : /var/www/html/rocksensor3/vendor/grasmash/yaml-cli/tests/src/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/rocksensor3/vendor/grasmash/yaml-cli/tests/src/TestBase.php |
<?php
namespace Grasmash\YamlCli\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
/**
* Class BltTestBase.
*
* Base class for all tests that are executed for BLT itself.
*/
abstract class TestBase extends TestCase
{
/** @var Application */
protected $application;
/** @var string */
protected $temp_file = '';
/**
* {@inheritdoc}
*
* @see https://symfony.com/doc/current/console.html#testing-commands
*/
protected function setUp(): void
{
parent::setUp();
$this->application = new Application();
}
/**
* Removes temporary file.
*/
protected function tearDown(): void
{
parent::tearDown();
// This will only exist if a test called setupTemporaryConfigFiles().
if ($this->temp_file && file_exists($this->temp_file)) {
unlink($this->temp_file);
}
}
/**
* Creates a temporary copy of a file and assigns it to $this->temp_file.
*
* @param string $source
* The filename of the source file.
* @param string $destination
* The filename of the destination file.
*
* @return bool
* TRUE if the file was created. Otherwise, FALSE.
*/
protected function createTemporaryFile($source, $destination)
{
$source_path = realpath($source);
if (file_exists($source_path)) {
copy($source_path, $destination);
$destination_path = realpath($destination);
$this->temp_file = $destination_path;
return true;
}
return false;
}
/**
* Creates a temporary copy of config files so that they can be modified.
*/
protected function setupTemporaryConfigFiles()
{
// Make a temporary copy of good.yml so that we can update a value
// without destroying the original.
$this->createTemporaryFile(__DIR__ . '/../resources/good.yml', __DIR__ . '/../resources/temp.yml');
}
}