Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: CI

permissions:
contents: read

on:
push:
branches: ['*']
Expand All @@ -14,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
php: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]
dependency-version: [ '' ]
include:
- php: '7.3'
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"psr/container": "^1.0|^2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"phpunit/phpunit": "^9.0 || ^10 || ^11 || ^12",
"athletic/athletic": "~0.1.8",
"mnapoli/hard-mode": "~0.3.0"
},
Expand Down
11 changes: 11 additions & 0 deletions tests/CallableResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function setUp(): void
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function resolves_function()
{
$result = $this->resolver->resolve('strlen');
Expand All @@ -37,6 +38,7 @@ public function resolves_function()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function resolves_namespaced_function()
{
$result = $this->resolver->resolve(__NAMESPACE__ . '\foo');
Expand All @@ -47,6 +49,7 @@ public function resolves_namespaced_function()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function resolves_callable_from_container()
{
$callable = function () {
Expand All @@ -59,6 +62,7 @@ public function resolves_callable_from_container()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function resolves_invokable_class()
{
$callable = new CallableSpy;
Expand All @@ -70,6 +74,7 @@ public function resolves_invokable_class()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function resolve_array_method_call()
{
$fixture = new InvokerTestFixture;
Expand All @@ -84,6 +89,7 @@ public function resolve_array_method_call()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function resolve_string_method_call()
{
$fixture = new InvokerTestFixture;
Expand All @@ -98,6 +104,7 @@ public function resolve_string_method_call()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function resolves_array_method_call_with_service()
{
$fixture = new InvokerTestFixture;
Expand All @@ -112,6 +119,7 @@ public function resolves_array_method_call_with_service()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function resolves_string_method_call_with_service()
{
$fixture = new InvokerTestFixture;
Expand All @@ -126,6 +134,7 @@ public function resolves_string_method_call_with_service()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function throws_resolving_non_callable_from_container()
{
$this->expectExceptionMessage("'foo' is neither a callable nor a valid container entry");
Expand All @@ -137,6 +146,7 @@ public function throws_resolving_non_callable_from_container()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function handles_objects_correctly_in_exception_message()
{
$this->expectExceptionMessage('Instance of stdClass is not a callable');
Expand All @@ -148,6 +158,7 @@ public function handles_objects_correctly_in_exception_message()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function handles_method_calls_correctly_in_exception_message()
{
$this->expectExceptionMessage('stdClass::test() is not a callable');
Expand Down
31 changes: 30 additions & 1 deletion tests/InvokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function setUp(): void
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_invoke_closure()
{
$callable = new CallableSpy;
Expand All @@ -44,6 +45,7 @@ public function should_invoke_closure()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_invoke_method()
{
$fixture = new InvokerTestFixture;
Expand All @@ -56,6 +58,7 @@ public function should_invoke_method()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function cannot_invoke_unknown_method()
{
$this->expectExceptionMessage('Invoker\Test\InvokerTestFixture::bar() is not a callable.');
Expand All @@ -66,6 +69,7 @@ public function cannot_invoke_unknown_method()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function cannot_invoke_magic_method()
{
$this->expectExceptionMessage('Invoker\Test\InvokerTestMagicMethodFixture::foo() is not a callable. A __call() or __callStatic() method exists but magic methods are not supported.');
Expand All @@ -76,6 +80,7 @@ public function cannot_invoke_magic_method()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function cannot_invoke_static_magic_method()
{
$this->expectExceptionMessage('Invoker\Test\InvokerTestStaticMagicMethodFixture::foo() is not a callable. A __call() or __callStatic() method exists but magic methods are not supported.');
Expand All @@ -86,6 +91,7 @@ public function cannot_invoke_static_magic_method()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_invoke_static_method()
{
$result = $this->invoker->call([InvokerTestStaticFixture::class, 'foo']);
Expand All @@ -96,6 +102,7 @@ public function should_invoke_static_method()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_invoke_static_method_with_scope_resolution_syntax()
{
$result = $this->invoker->call('Invoker\Test\InvokerTestStaticFixture::foo');
Expand All @@ -106,6 +113,7 @@ public function should_invoke_static_method_with_scope_resolution_syntax()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_return_the_callable_return_value()
{
$result = $this->invoker->call(function () {
Expand All @@ -118,6 +126,7 @@ public function should_return_the_callable_return_value()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_throw_if_no_value_for_parameter()
{
$this->expectExceptionMessage('Unable to invoke the callable because no value was given for parameter 2 ($bar)');
Expand All @@ -132,6 +141,7 @@ public function should_throw_if_no_value_for_parameter()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_throw_if_no_value_for_parameter_even_with_trailing_optional_parameters()
{
$this->expectExceptionMessage('Unable to invoke the callable because no value was given for parameter 2 ($bar)');
Expand All @@ -146,6 +156,7 @@ public function should_throw_if_no_value_for_parameter_even_with_trailing_option
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_invoke_callable_with_parameters_indexed_by_position()
{
$callable = new CallableSpy;
Expand All @@ -158,6 +169,7 @@ public function should_invoke_callable_with_parameters_indexed_by_position()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_invoke_callable_with_parameters_indexed_by_name()
{
$parameters = [
Expand All @@ -175,6 +187,7 @@ public function should_invoke_callable_with_parameters_indexed_by_name()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_invoke_callable_with_default_value_for_undefined_parameters()
{
$parameters = [
Expand All @@ -192,6 +205,7 @@ public function should_invoke_callable_with_default_value_for_undefined_paramete
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_invoke_callable_with_null_for_nullable_parameters()
{
$result = $this->invoker->call(function (?string $baz = null) {
Expand Down Expand Up @@ -238,6 +252,7 @@ public function should_invoke_callable_with_optional_parameter_before_required_p
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_do_dependency_injection_with_typehint_container_resolver()
{
$resolver = new TypeHintContainerResolver($this->container);
Expand All @@ -256,6 +271,7 @@ public function should_do_dependency_injection_with_typehint_container_resolver(
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_do_dependency_injection_with_parameter_name_container_resolver()
{
$resolver = new ParameterNameContainerResolver($this->container);
Expand All @@ -274,6 +290,7 @@ public function should_do_dependency_injection_with_parameter_name_container_res
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_resolve_callable_from_container()
{
$callable = new CallableSpy;
Expand All @@ -287,6 +304,7 @@ public function should_resolve_callable_from_container()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_resolve_array_callable_from_container()
{
$fixture = new InvokerTestFixture;
Expand All @@ -301,6 +319,7 @@ public function should_resolve_array_callable_from_container()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_resolve_callable_from_container_with_scope_resolution_syntax()
{
$fixture = new InvokerTestFixture;
Expand All @@ -315,6 +334,7 @@ public function should_resolve_callable_from_container_with_scope_resolution_syn
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_resolve_array_callable_from_container_with_class_name()
{
$fixture = new InvokerTestFixture;
Expand All @@ -329,6 +349,7 @@ public function should_resolve_array_callable_from_container_with_class_name()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_resolve_callable_from_container_with_class_name_in_scope_resolution_syntax()
{
$fixture = new InvokerTestFixture;
Expand Down Expand Up @@ -366,6 +387,7 @@ public function positioned_parameters_have_the_highest_priority()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_not_invoke_statically_a_non_static_method()
{
$this->expectExceptionMessage('Cannot call foo() on Invoker\Test\InvokerTestFixture because it is not a class nor a valid container entry');
Expand All @@ -376,6 +398,7 @@ public function should_not_invoke_statically_a_non_static_method()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_throw_if_calling_non_callable_without_container()
{
$this->expectExceptionMessage("'foo' is not a callable");
Expand All @@ -387,6 +410,7 @@ public function should_throw_if_calling_non_callable_without_container()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_throw_if_calling_non_callable_without_container_2()
{
$this->expectExceptionMessage('NULL is not a callable');
Expand All @@ -398,6 +422,7 @@ public function should_throw_if_calling_non_callable_without_container_2()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_throw_if_calling_non_callable_with_container()
{
$this->expectExceptionMessage("'foo' is neither a callable nor a valid container entry");
Expand All @@ -409,6 +434,7 @@ public function should_throw_if_calling_non_callable_with_container()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_throw_if_calling_non_callable_object()
{
$this->expectExceptionMessage('Instance of stdClass is not a callable');
Expand All @@ -420,6 +446,7 @@ public function should_throw_if_calling_non_callable_object()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_invoke_static_method_rather_than_resolving_entry_from_container()
{
// Register a non-callable so that test fails if we try to invoke that
Expand All @@ -434,6 +461,7 @@ public function should_invoke_static_method_rather_than_resolving_entry_from_con
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_throw_if_no_value_for_optional_parameter_1()
{
$this->expectExceptionMessage('Unable to invoke the callable because no value was given for parameter 2 ($bar)');
Expand All @@ -449,6 +477,7 @@ public function should_throw_if_no_value_for_optional_parameter_1()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_throw_if_no_value_for_optional_parameter_2()
{
$this->expectExceptionMessage('Unable to invoke the callable because no value was given for parameter 2 ($bar)');
Expand All @@ -465,6 +494,7 @@ public function should_throw_if_no_value_for_optional_parameter_2()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_invoke_callable_with_variadic_parameter()
{
$callable = function (...$param) {
Expand Down Expand Up @@ -533,4 +563,3 @@ public static function __callStatic(string $name, array $args): string
throw new Exception('Unknown method');
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function setUp(): void
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_resolve_parameter_with_parameter_name_from_container()
{
$callable = function ($foo) {
Expand All @@ -40,6 +41,7 @@ public function should_resolve_parameter_with_parameter_name_from_container()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_skip_parameter_if_container_cannot_provide_parameter()
{
$callable = function ($foo) {
Expand All @@ -54,6 +56,7 @@ public function should_skip_parameter_if_container_cannot_provide_parameter()
/**
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function should_skip_parameter_if_already_resolved()
{
$callable = function ($foo) {
Expand Down
Loading