55
66class FactoryTrackerTest extends \PHPUnit \Framework \TestCase
77{
8- private function getFactoryClient ()
9- {
10- $ parameters = array ('scheme ' => 'redis ' , 'host ' => REDIS_HOST , 'port ' => REDIS_PORT , 'timeout ' => 881 );
11- $ options = array ('prefix ' => TEST_PREFIX );
12-
13- $ sdkConfig = array (
14- 'log ' => array ('adapter ' => 'stdout ' ),
15- 'cache ' => array ('adapter ' => 'predis ' , 'parameters ' => $ parameters , 'options ' => $ options )
16- );
17-
18- //Initializing the SDK instance.
19- $ splitFactory = \SplitIO \Sdk::factory ('asdqwe123456 ' , $ sdkConfig );
20-
21- return $ splitFactory ;
22- }
23-
248 private function getMockedLogger ()
259 {
2610 //Initialize mock logger
@@ -38,18 +22,45 @@ private function getMockedLogger()
3822
3923 public function testMultipleClientInstantiation ()
4024 {
41- $ splitFactory = $ this ->getFactoryClient ();
25+ ReflectiveTools::overrideTracker ();
26+ $ parameters = array ('scheme ' => 'redis ' , 'host ' => REDIS_HOST , 'port ' => REDIS_PORT , 'timeout ' => 881 );
27+ $ options = array ('prefix ' => TEST_PREFIX );
28+
29+ $ sdkConfig = array (
30+ 'log ' => array ('adapter ' => 'stdout ' ),
31+ 'cache ' => array ('adapter ' => 'predis ' , 'parameters ' => $ parameters , 'options ' => $ options )
32+ );
33+
34+ //Initializing the SDK instance.
35+ $ splitFactory = \SplitIO \Sdk::factory ('asdqwe123456 ' , $ sdkConfig );
4236 $ this ->assertNotNull ($ splitFactory ->client ());
4337
4438 $ logger = $ this ->getMockedLogger ();
45-
46- $ logger ->expects ($ this ->once ())
39+ $ logger ->expects ($ this ->any ())
4740 ->method ('warning ' )
48- ->with ($ this ->equalTo ("Factory Instantiation: You already have an instance of the Split factory. "
49- . "Make sure you definitely want this additional instance. We recommend keeping only one instance "
50- . "of the factory at all times (Singleton pattern) and reusing it throughout your application. " ));
51-
52- $ splitFactory2 = $ this ->getFactoryClient ();
41+ ->with ($ this ->logicalOr (
42+ $ this ->equalTo ("Factory Instantiation: You already have 1 factory/factories with this API Key. "
43+ . "We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing "
44+ . "it throughout your application. " ),
45+ $ this ->equalTo ("Factory Instantiation: You already have 2 factory/factories with this API Key. "
46+ . "We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing "
47+ . "it throughout your application. " ),
48+ $ this ->equalTo ("Factory Instantiation: You already have an instance of the Split factory. "
49+ . "Make sure you definitely want this additional instance. We recommend keeping only one instance "
50+ . "of the factory at all times (Singleton pattern) and reusing it throughout your application. " )
51+ )
52+ );
53+
54+ //Initializing the SDK instance2.
55+ $ splitFactory2 = \SplitIO \Sdk::factory ('asdqwe123456 ' , $ sdkConfig );
5356 $ this ->assertNotNull ($ splitFactory2 ->client ());
57+
58+ //Initializing the SDK instance3.
59+ $ splitFactory3 = \SplitIO \Sdk::factory ('asdqwe123456 ' , $ sdkConfig );
60+ $ this ->assertNotNull ($ splitFactory3 ->client ());
61+
62+ //Initializing the SDK instance4.
63+ $ splitFactory4 = \SplitIO \Sdk::factory ('other ' , $ sdkConfig );
64+ $ this ->assertNotNull ($ splitFactory4 ->client ());
5465 }
5566}
0 commit comments