This repository was archived by the owner on Feb 6, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 21
21
use Zend \ServiceManager \Factory \InvokableFactory ;
22
22
use Zend \ServiceManager \Initializer \InitializerInterface ;
23
23
use Zend \ServiceManager \ServiceLocatorInterface ;
24
+ use ZendTest \ServiceManager \TestAsset \CallOnlyOnceAbstractFactory ;
24
25
use ZendTest \ServiceManager \TestAsset \FailingAbstractFactory ;
25
26
use ZendTest \ServiceManager \TestAsset \FailingFactory ;
26
27
use ZendTest \ServiceManager \TestAsset \InvokableObject ;
@@ -139,6 +140,22 @@ public function testCanCreateServiceWithAbstractFactory()
139
140
$ serviceManager ->get (DateTime::class);
140
141
}
141
142
143
+ public function testCallOnlyOnceWithMultipleIdenticalAbstractFactory ()
144
+ {
145
+ CallOnlyOnceAbstractFactory::setCallTimes (0 );
146
+
147
+ $ serviceManager = $ this ->createContainer ([
148
+ 'abstract_factories ' => [
149
+ new CallOnlyOnceAbstractFactory (),
150
+ new CallOnlyOnceAbstractFactory (),
151
+ ]
152
+ ]);
153
+ $ serviceManager ->addAbstractFactory (CallOnlyOnceAbstractFactory::class);
154
+ $ serviceManager ->has (stdClass::class);
155
+
156
+ $ this ->assertEquals (1 , CallOnlyOnceAbstractFactory::getCallTimes ());
157
+ }
158
+
142
159
public function testCanCreateServiceWithAlias ()
143
160
{
144
161
$ serviceManager = $ this ->createContainer ([
Original file line number Diff line number Diff line change
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-2015 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 \AbstractFactoryInterface ;
14
+
15
+ class CallOnlyOnceAbstractFactory implements AbstractFactoryInterface
16
+ {
17
+ protected static $ callTimes = 0 ;
18
+
19
+ /**
20
+ * {@inheritDoc}
21
+ */
22
+ public function canCreate (ContainerInterface $ container , $ name )
23
+ {
24
+ self ::$ callTimes ++;
25
+
26
+ return false ;
27
+ }
28
+
29
+ /**
30
+ * {@inheritDoc}
31
+ */
32
+ public function __invoke (ContainerInterface $ container , $ className , array $ options = null )
33
+ {
34
+ }
35
+
36
+ /**
37
+ * @return int
38
+ */
39
+ public static function getCallTimes ()
40
+ {
41
+ return self ::$ callTimes ;
42
+ }
43
+
44
+ /**
45
+ * @param int $callTimes
46
+ */
47
+ public static function setCallTimes ($ callTimes )
48
+ {
49
+ self ::$ callTimes = $ callTimes ;
50
+ }
51
+ }
You can’t perform that action at this time.
0 commit comments