Skip to content

Commit 203c8a5

Browse files
Merge branch '4.4' into 5.0
* 4.4: (34 commits) Add test for tagged iterator with numeric index Fix container lint command when a synthetic service is used in combination with the expression language [Validator][Range] Fix typos [SecurityBundle] Minor fix in LDAP config tree builder [HttpClient] fix requests to hosts that idn_to_ascii() cannot handle [FrameworkBundle] remove redundant PHPDoc in console Descriptor and subclass [Mime] remove phpdoc mentioning Utf8AddressEncoder Add missing phpdoc Remove int return type from FlattenException::getCode [Yaml] fix dumping strings containing CRs [DI] Fix XmlFileLoader bad error message [Form] Handle false as empty value on expanded choices [Messenger] Add ext-redis min version req to tests Tweak message improve PlaintextPasswordEncoder docBlock summary [Validator] Add two missing translations for the Arabic (ar) locale Use some PHP 5.4 constants unconditionally Add new packages on the link script [DI] fix dumping errored definitions [DI] ignore extra tags added by autoconfiguration in PriorityTaggedServiceTrait ...
2 parents 24a938d + 3c76461 commit 203c8a5

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

Exception/FlattenException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ public function setMessage($message): self
210210
return $this;
211211
}
212212

213-
public function getCode(): int
213+
/**
214+
* @return int|string int most of the time (might be a string with PDOException)
215+
*/
216+
public function getCode()
214217
{
215218
return $this->code;
216219
}

Tests/Exception/FlattenExceptionTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\ErrorHandler\Exception\FlattenException;
16+
use Symfony\Component\ErrorHandler\Tests\Fixtures\StringErrorCodeException;
1617
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
1718
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
1819
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
@@ -183,6 +184,15 @@ public function testFile(\Throwable $exception)
183184
$this->assertSame($exception->getFile(), $flattened->getFile());
184185
}
185186

187+
/**
188+
* @dataProvider stringAndIntDataProvider
189+
*/
190+
public function testCode(\Throwable $exception)
191+
{
192+
$flattened = FlattenException::createFromThrowable($exception);
193+
$this->assertSame($exception->getCode(), $flattened->getCode());
194+
}
195+
186196
/**
187197
* @dataProvider flattenDataProvider
188198
*/
@@ -224,6 +234,14 @@ public function flattenDataProvider(): array
224234
];
225235
}
226236

237+
public function stringAndIntDataProvider(): array
238+
{
239+
return [
240+
[new \Exception('test1', 123)],
241+
[new StringErrorCodeException('test2', '42S02')],
242+
];
243+
}
244+
227245
public function testArguments()
228246
{
229247
if (\PHP_VERSION_ID >= 70400) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Symfony\Component\ErrorHandler\Tests\Fixtures;
4+
5+
class StringErrorCodeException extends \Exception
6+
{
7+
8+
public function __construct(string $message, string $code) {
9+
parent::__construct($message);
10+
$this->code = $code;
11+
}
12+
13+
}

0 commit comments

Comments
 (0)