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

Commit 683a008

Browse files
shadowhandweierophinney
authored andcommitted
Ensure that factories return an object
Some containers (eg: Auryn) require that all returns are objects.
1 parent fdd4a60 commit 683a008

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

src/FactoryTestTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function factoryWithName() : Generator
5959
[
6060
'factories' => [
6161
'service' => function () {
62-
return func_get_args();
62+
return new TestAsset\FactoryService(func_get_args());
6363
},
6464
],
6565
],
@@ -73,7 +73,7 @@ public function testFactoryIsProvidedContainerAndServiceNameAsArguments(array $c
7373
{
7474
$container = $this->createContainer($config);
7575

76-
$args = $container->get('service');
76+
$args = $container->get('service')->args;
7777
self::assertGreaterThanOrEqual(2, $args);
7878
// Not testing for identical $container argument here, as some implementations
7979
// may decorate another container in order to fulfill the config contracts.

src/TestAsset/FactoryService.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-container-config-test for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-container-config-test/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Zend\ContainerConfigTest\TestAsset;
11+
12+
class FactoryService
13+
{
14+
public $args = [];
15+
16+
public function __construct(array $args)
17+
{
18+
$this->args = $args;
19+
}
20+
}

src/TestAsset/FactoryStatic.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public static function create(ContainerInterface $container, string $name) : Ser
1818
return new Service();
1919
}
2020

21-
public static function withName() : array
21+
public static function withName() : FactoryService
2222
{
23-
return func_get_args();
23+
return new FactoryService(func_get_args());
2424
}
2525
}

src/TestAsset/FactoryWithName.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
class FactoryWithName
1313
{
14-
public function __invoke() : array
14+
public function __invoke() : FactoryService
1515
{
16-
return func_get_args();
16+
return new FactoryService(func_get_args());
1717
}
1818
}

src/TestAsset/function-factory-with-name.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use Psr\Container\ContainerInterface;
1313

14-
function factoryWithName(ContainerInterface $container, string $name) : array
14+
function factoryWithName(ContainerInterface $container, string $name) : FactoryService
1515
{
16-
return func_get_args();
16+
return new FactoryService(func_get_args());
1717
}

0 commit comments

Comments
 (0)