Skip to content

Commit

Permalink
Updated tests for the Configuration class, updated the Rector config,…
Browse files Browse the repository at this point in the history
… and updated the code.
  • Loading branch information
rosven9856 committed Aug 14, 2024
1 parent c1cb92e commit 86ab8fc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 12 deletions.
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
]);
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_83,
DowngradeLevelSetList::DOWN_TO_PHP_81,
// DowngradeLevelSetList::DOWN_TO_PHP_81,
]);
};
4 changes: 2 additions & 2 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace App\Configuration;

final class Configuration
final readonly class Configuration
{
protected readonly array $options;
protected array $options;

/**
* @use
Expand Down
66 changes: 57 additions & 9 deletions tests/Configuration/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,39 @@
*/
class ConfigurationTest extends TestCase
{
const string DEFAULT_ENV_GITHUB_WORKSPACE = '/usr/bin/app';
const string OTHER_ENV_GITHUB_WORKSPACE = '/app';
const string OTHER_ENV_BUILD_DIRECTORY_NAME = '.build_directory';
const string OTHER_ENV_BUILD_FILE_NAME = 'build_file.zip';
/**
* @var string
*/
private const string DEFAULT_ENV_GITHUB_WORKSPACE = '/usr/bin/app';

/**
* @var string
*/
private const string DEFAULT_ENV_BUILD_DIRECTORY_NAME = '.build';

/**
* @var string
*/
private const string DEFAULT_ENV_BUILD_FILE_NAME = 'package.zip';

/**
* @var string
*/
private const string OTHER_ENV_GITHUB_WORKSPACE = '/app';

/**
* @var string
*/
private const string OTHER_ENV_BUILD_DIRECTORY_NAME = '.build_directory';

/**
* @var string
*/
private const string OTHER_ENV_BUILD_FILE_NAME = 'build_file.zip';

protected Configuration $configuration;

Check failure on line 42 in tests/Configuration/ConfigurationTest.php

View workflow job for this annotation

GitHub Actions / psalm (8.3)

PossiblyUnusedProperty

tests/Configuration/ConfigurationTest.php:42:29: PossiblyUnusedProperty: Cannot find any references to property App\Configuration\ConfigurationTest::$configuration (see https://psalm.dev/149)

#[\Override]
protected function setUp(): void
{
putenv('GITHUB_WORKSPACE=' . self::DEFAULT_ENV_GITHUB_WORKSPACE);
Expand All @@ -29,8 +55,14 @@ protected function setUp(): void
*/
public function testCheckDefaultOptionRoot()
{
putenv('GITHUB_WORKSPACE=' . self::DEFAULT_ENV_GITHUB_WORKSPACE);
putenv('BUILD_DIRECTORY_NAME=' . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::DEFAULT_ENV_BUILD_FILE_NAME);

$configuration = new Configuration();

$this->assertEquals(
$this->configuration->get('root'),
$configuration->get('root'),
self::DEFAULT_ENV_GITHUB_WORKSPACE
);
}
Expand All @@ -41,9 +73,15 @@ public function testCheckDefaultOptionRoot()
*/
public function testCheckDefaultOptionBuildDirectory()
{
putenv('GITHUB_WORKSPACE=' . self::DEFAULT_ENV_GITHUB_WORKSPACE);
putenv('BUILD_DIRECTORY_NAME=' . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::DEFAULT_ENV_BUILD_FILE_NAME);

$configuration = new Configuration();

$this->assertEquals(
$this->configuration->get('build.directory'),
self::DEFAULT_ENV_GITHUB_WORKSPACE . '/.build'
$configuration->get('build.directory'),
self::DEFAULT_ENV_GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME
);
}

Expand All @@ -53,9 +91,16 @@ public function testCheckDefaultOptionBuildDirectory()
*/
public function testCheckDefaultOptionBuildFile()
{
putenv('GITHUB_WORKSPACE=' . self::DEFAULT_ENV_GITHUB_WORKSPACE);
putenv('BUILD_DIRECTORY_NAME=' . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::DEFAULT_ENV_BUILD_FILE_NAME);

$configuration = new Configuration();

$this->assertEquals(
$this->configuration->get('build.file'),
self::DEFAULT_ENV_GITHUB_WORKSPACE . '/.build/package.zip'
$configuration->get('build.file'),
self::DEFAULT_ENV_GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . self::DEFAULT_ENV_BUILD_DIRECTORY_NAME .
DIRECTORY_SEPARATOR . self::DEFAULT_ENV_BUILD_FILE_NAME
);
}

Expand All @@ -66,6 +111,8 @@ public function testCheckDefaultOptionBuildFile()
public function testCheckOtherOptionRoot()
{
putenv('GITHUB_WORKSPACE=' . self::OTHER_ENV_GITHUB_WORKSPACE);
putenv('BUILD_DIRECTORY_NAME=' . self::OTHER_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::OTHER_ENV_BUILD_FILE_NAME);

$configuration = new Configuration();

Expand All @@ -83,6 +130,7 @@ public function testCheckOtherOptionBuildDirectory()
{
putenv('GITHUB_WORKSPACE=' . self::OTHER_ENV_GITHUB_WORKSPACE);
putenv('BUILD_DIRECTORY_NAME=' . self::OTHER_ENV_BUILD_DIRECTORY_NAME);
putenv('BUILD_FILE_NAME=' . self::OTHER_ENV_BUILD_FILE_NAME);

$configuration = new Configuration();

Expand Down

0 comments on commit 86ab8fc

Please sign in to comment.