Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit 36f38ff

Browse files
committed
Merge pull request #167 from kokspflanze/bugfix/pdoexception_code_return_string
bugfix PDOException return string as code
2 parents b6b646b + 63b0109 commit 36f38ff

File tree

4 files changed

+57
-1
lines changed

4 files changed

+57
-1
lines changed

src/ServiceManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ private function doCreate($resolvedName, array $options = null)
755755
'Service with name "%s" could not be created. Reason: %s',
756756
$resolvedName,
757757
$exception->getMessage()
758-
), $exception->getCode(), $exception);
758+
), (int)$exception->getCode(), $exception);
759759
}
760760

761761
foreach ($this->initializers as $initializer) {

test/CommonServiceLocatorBehaviorsTrait.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Zend\ServiceManager\ServiceLocatorInterface;
2424
use ZendTest\ServiceManager\TestAsset\FailingAbstractFactory;
2525
use ZendTest\ServiceManager\TestAsset\FailingFactory;
26+
use ZendTest\ServiceManager\TestAsset\FailingExceptionWithStringAsCodeFactory;
2627
use ZendTest\ServiceManager\TestAsset\InvokableObject;
2728
use ZendTest\ServiceManager\TestAsset\SimpleAbstractFactory;
2829

@@ -227,6 +228,19 @@ public function testThrowExceptionIfServiceCannotBeCreated()
227228
$serviceManager->get(stdClass::class);
228229
}
229230

231+
public function testThrowExceptionWithStringAsCodeIfServiceCannotBeCreated()
232+
{
233+
$serviceManager = $this->createContainer([
234+
'factories' => [
235+
stdClass::class => FailingExceptionWithStringAsCodeFactory::class
236+
]
237+
]);
238+
239+
$this->setExpectedException(ServiceNotCreatedException::class);
240+
241+
$serviceManager->get(stdClass::class);
242+
}
243+
230244
public function testConfigureCanAddNewServices()
231245
{
232246
$serviceManager = $this->createContainer([
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace ZendTest\ServiceManager\TestAsset;
11+
12+
use Exception;
13+
14+
class ExceptionWithStringAsCode extends Exception
15+
{
16+
/** @var string */
17+
protected $code = 'ExceptionString';
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace ZendTest\ServiceManager\TestAsset;
11+
12+
use Interop\Container\ContainerInterface;
13+
use Zend\ServiceManager\Factory\FactoryInterface;
14+
15+
class FailingExceptionWithStringAsCodeFactory implements FactoryInterface
16+
{
17+
/**
18+
* {@inheritDoc}
19+
*/
20+
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
21+
{
22+
throw (new ExceptionWithStringAsCode('There is an error'));
23+
}
24+
}

0 commit comments

Comments
 (0)