Skip to content

Commit

Permalink
Create ConfigWriter test
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Nov 19, 2024
1 parent 071d97d commit b7a09c5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ vendor/
config/*.local.php
data
bin/rr
test-resources/config/params/generated-in-test.php
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
* *Nothing*

### Removed
* *Nothing*
* Remove dependency on `laminas/laminas-config`.

### Fixed
* *Nothing*
Expand Down
1 change: 1 addition & 0 deletions src/Util/ConfigWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ConfigWriter implements ConfigWriterInterface
/* Shlink config generated by shlink-installer */
return %s;
TEMPLATE;


Expand Down
48 changes: 48 additions & 0 deletions test/Util/ConfigWriterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace ShlinkioTest\Shlink\Installer\Util;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Installer\Util\ConfigWriter;

use function unlink;

class ConfigWriterTest extends TestCase
{
private const FILENAME = __DIR__ . '/../../test-resources/config/params/generated-in-test.php';

private ConfigWriter $configWriter;

protected function setUp(): void
{
$this->configWriter = new ConfigWriter();
}

public static function tearDownAfterClass(): void
{
unlink(self::FILENAME);
}

#[Test]
#[TestWith([[
'foo' => 'foo',
'bar' => 'bar',
'baz' => 'baz',
]])]
#[TestWith([[
'foo' => null,
'bar' => 123,
'baz' => true,
]])]
public function configIsExportedAndWrittenToFile(array $config): void
{
$this->configWriter->toFile(self::FILENAME, $config);

self::assertFileExists(self::FILENAME);
self::assertEquals($config, require self::FILENAME);
}
}

0 comments on commit b7a09c5

Please sign in to comment.