Skip to content

Commit 5f1cba2

Browse files
committed
Improve exception messages for argument positions to match PHP 8+ format
1 parent eedc82f commit 5f1cba2

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/Container.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ private static function parameterError(\ReflectionParameter $parameter): string
381381
$name = explode("\0", $class->getName())[0] . '::' . $name;
382382
}
383383

384-
return 'Argument ' . ($parameter->getPosition() + 1) . ' ($' . $parameter->getName() . ') of ' . $name . '()';
384+
return 'Argument #' . ($parameter->getPosition() + 1) . ' ($' . $parameter->getName() . ') of ' . $name . '()';
385385
}
386386

387387
/**

tests/AppTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -1529,25 +1529,25 @@ public function provideInvalidClasses(): \Generator
15291529

15301530
yield [
15311531
InvalidConstructorUntyped::class,
1532-
'Argument 1 ($value) of %s::__construct() has no type'
1532+
'Argument #1 ($value) of %s::__construct() has no type'
15331533
];
15341534

15351535
yield [
15361536
InvalidConstructorInt::class,
1537-
'Argument 1 ($value) of %s::__construct() expects unsupported type int'
1537+
'Argument #1 ($value) of %s::__construct() expects unsupported type int'
15381538
];
15391539

15401540
if (PHP_VERSION_ID >= 80000) {
15411541
yield [
15421542
InvalidConstructorUnion::class,
1543-
'Argument 1 ($value) of %s::__construct() expects unsupported type int|float'
1543+
'Argument #1 ($value) of %s::__construct() expects unsupported type int|float'
15441544
];
15451545
}
15461546

15471547
if (PHP_VERSION_ID >= 80100) {
15481548
yield [
15491549
InvalidConstructorIntersection::class,
1550-
'Argument 1 ($value) of %s::__construct() expects unsupported type Traversable&ArrayAccess'
1550+
'Argument #1 ($value) of %s::__construct() expects unsupported type Traversable&ArrayAccess'
15511551
];
15521552
}
15531553

@@ -1558,7 +1558,7 @@ public function provideInvalidClasses(): \Generator
15581558

15591559
yield [
15601560
InvalidConstructorSelf::class,
1561-
'Argument 1 ($value) of %s::__construct() is recursive'
1561+
'Argument #1 ($value) of %s::__construct() is recursive'
15621562
];
15631563
}
15641564

tests/ContainerTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ public function __construct(\stdClass $data)
12851285
$callable = $container->callable(get_class($controller));
12861286

12871287
$this->expectException(\BadMethodCallException::class);
1288-
$this->expectExceptionMessage('Argument 1 ($username) of {closure:' . __FILE__ . ':' . $line .'}() is not defined');
1288+
$this->expectExceptionMessage('Argument #1 ($username) of {closure:' . __FILE__ . ':' . $line .'}() is not defined');
12891289
$callable($request);
12901290
}
12911291

@@ -1641,7 +1641,7 @@ public function __construct(string $name)
16411641
$callable = $container->callable(get_class($controller));
16421642

16431643
$this->expectException(\BadMethodCallException::class);
1644-
$this->expectExceptionMessage('Argument 1 ($name) of class@anonymous::__construct() expects unsupported type string');
1644+
$this->expectExceptionMessage('Argument #1 ($name) of class@anonymous::__construct() expects unsupported type string');
16451645
$callable($request);
16461646
}
16471647

@@ -1772,7 +1772,7 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryRequiresUntypedA
17721772
$callable = $container->callable(\stdClass::class);
17731773

17741774
$this->expectException(\BadMethodCallException::class);
1775-
$this->expectExceptionMessage('Argument 1 ($undefined) of {closure:' . __FILE__ . ':' . $line .'}() has no type');
1775+
$this->expectExceptionMessage('Argument #1 ($undefined) of {closure:' . __FILE__ . ':' . $line .'}() has no type');
17761776
$callable($request);
17771777
}
17781778

@@ -1791,7 +1791,7 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryRequiresUndefine
17911791
$callable = $container->callable(\stdClass::class);
17921792

17931793
$this->expectException(\BadMethodCallException::class);
1794-
$this->expectExceptionMessage('Argument 1 ($undefined) of {closure:' . __FILE__ . ':' . $line .'}() is not defined');
1794+
$this->expectExceptionMessage('Argument #1 ($undefined) of {closure:' . __FILE__ . ':' . $line .'}() is not defined');
17951795
$callable($request);
17961796
}
17971797

@@ -1807,7 +1807,7 @@ public function testCallableReturnsCallableThatThrowsWhenFactoryRequiresRecursiv
18071807
$callable = $container->callable(\stdClass::class);
18081808

18091809
$this->expectException(\BadMethodCallException::class);
1810-
$this->expectExceptionMessage('Argument 1 ($data) of {closure:' . __FILE__ . ':' . $line .'}() is recursive');
1810+
$this->expectExceptionMessage('Argument #1 ($data) of {closure:' . __FILE__ . ':' . $line .'}() is recursive');
18111811
$callable($request);
18121812
}
18131813

@@ -2101,7 +2101,7 @@ public function testGetEnvThrowsWhenFactoryUsesBuiltInFunctionThatReferencesUnkn
21012101
]);
21022102

21032103
$this->expectException(\BadMethodCallException::class);
2104-
$this->expectExceptionMessage('Argument 1 ($extension) of extension_loaded() is not defined');
2104+
$this->expectExceptionMessage('Argument #1 ($extension) of extension_loaded() is not defined');
21052105
$container->getEnv('X_FOO');
21062106
}
21072107

@@ -2119,7 +2119,7 @@ public function foo(string $bar): string
21192119
]);
21202120

21212121
$this->expectException(\BadMethodCallException::class);
2122-
$this->expectExceptionMessage('Argument 1 ($bar) of class@anonymous::foo() is not defined');
2122+
$this->expectExceptionMessage('Argument #1 ($bar) of class@anonymous::foo() is not defined');
21232123
$container->getEnv('X_FOO');
21242124
}
21252125

0 commit comments

Comments
 (0)