Skip to content

04: Config facade - #4

Merged
nikolaystrikhar merged 4 commits into
mainfrom
04-config
Aug 11, 2026
Merged

04: Config facade#4
nikolaystrikhar merged 4 commits into
mainfrom
04-config

Conversation

@nikolaystrikhar

@nikolaystrikhar nikolaystrikhar commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Config static facade — hook prefix, version, optional container — plus Config_Exception.

Config::set_hook_prefix( 'give' );
Config::set_container( give()->container ); // optional
  • Validation happens on write. set_hook_prefix() rejects bad values, empty string included. Validating at read time would turn a bad prefix into a filter that silently never fires, surfacing later as a misleading "you must call set_hook_prefix()".
  • Config_Exception extends RuntimeException, so callers get one catchable type across the library.
  • Tests configure the facade through Tests\Support\Test_Container, because lucatume\DI52\Container implements PSR-11's ContainerInterface, not StellarWP's. set_container()'s signature is unchanged and stellarwp/container-contract stays the only production dependency.

get_version() is stored but nothing reads it yet — spec known-issue F.

…tate

- Assert Config_Exception is catchable as RuntimeException; nothing covered
  that inheritance, so dropping it would have left the suite green.
- Reset Config in setUp() as well as tearDown(), so the tests asserting on
  default state no longer depend on class execution order.
- Note that the container fixture inherits DI52's class_exists() fallback
  in has().
- Drop a README pointer to a section that does not exist yet.
Comment thread src/Config.php Outdated
Comment on lines +74 to +92
/**
* @since 1.0.0
*
* @param string $version Host plugin version.
*
* @return void
*/
public static function set_version( string $version ): void {
self::$version = $version;
}

/**
* @since 1.0.0
*
* @return string
*/
public static function get_version(): string {
return self::$version;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this accidentally was left in the engineering plan after some edits. It shouldn't be needed or used anywhere, right?

The only time we would ever care about the plugin version would be for weird cases like ProPanel v3.0 and that shouldn't be a concern for this library. We should be able to remove any version-related code from the Config object.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right

Comment thread src/Config.php Outdated
Comment on lines +127 to +138
/**
* Reset all static state. Test seam.
*
* @since 1.0.0
*
* @return void
*/
public static function reset(): void {
self::$hook_prefix = '';
self::$version = '';
self::$container = null;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need test-only code in the production object? We could use reflection to forcibly clear the state in tests. Exposing this means it is something we will support and I don't know if we should.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right

Comment thread tests/unit/ConfigTest.php Outdated
Comment on lines +51 to +61
/**
* @return array<string,array{0:string}>
*/
public function invalid_hook_prefixes(): array {
return [
'slash' => [ 'give/recurring' ],
'space' => [ 'give recurring' ],
'dot' => [ 'give.recurring' ],
'backslash' => [ 'give\\recurring' ],
];
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead use a Generator? This Array pattern that Claude likes to use unless otherwise specified I think is much harder to read personally.

Also, probably worth making it public static.

Comment thread tests/unit/ConfigTest.php Outdated
Comment on lines +34 to +38
public function test_it_accepts_letters_numbers_hyphens_and_underscores(): void {
Config::set_hook_prefix( 'give-recurring_2' );

$this->assertSame( 'give-recurring_2', Config::get_hook_prefix() );
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid/invalid formats could just be a Data Provider, right? Could have the input prefix as one param and a result for "valid" and if it is false then we would expect an exception. Alternatively, we could have separate Data Providers and test methods for valid vs invalid, but overall I think it would be worthwhile to utilize Data Providers for this type of test.

Comment thread tests/unit/ConfigTest.php Outdated
}

public function test_config_exception_is_catchable_as_a_runtime_exception(): void {
$this->expectException( RuntimeException::class );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we expecting RuntimeException here? Shouldn't we expect Config_Exception? This currently passes just because Config_Exception extends RuntimeException.

…g_State for test state management. Update tests to reflect changes and ensure proper exception handling for invalid hook prefixes.
@nikolaystrikhar
nikolaystrikhar merged commit f357c29 into main Aug 11, 2026
4 checks passed
@nikolaystrikhar
nikolaystrikhar deleted the 04-config branch August 11, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants