1111namespace tests \aik099 \PHPUnit \BrowserConfiguration ;
1212
1313
14+ use aik099 \PHPUnit \APIClient \IAPIClient ;
1415use aik099 \PHPUnit \BrowserConfiguration \ApiBrowserConfiguration ;
15- use aik099 \PHPUnit \BrowserConfiguration \IBrowserConfigurationFactory ;
1616use aik099 \PHPUnit \Event \TestEndedEvent ;
1717use aik099 \PHPUnit \Event \TestEvent ;
1818use aik099 \PHPUnit \Session \ISessionStrategyFactory ;
19- use Mockery \MockInterface ;
2019use Symfony \Component \EventDispatcher \EventDispatcher ;
2120use aik099 \PHPUnit \BrowserTestCase ;
2221use Mockery as m ;
@@ -29,25 +28,18 @@ abstract class ApiBrowserConfigurationTestCase extends BrowserConfigurationTest
2928 const AUTOMATIC_TEST_NAME = 'AUTOMATIC ' ;
3029
3130 /**
32- * Browser configuration class.
33- *
34- * @var string
35- */
36- protected $ browserConfigurationClass = '' ;
37-
38- /**
39- * Browser configuration factory.
31+ * Desired capabilities use to configure the tunnel.
4032 *
41- * @var IBrowserConfigurationFactory|MockInterface
33+ * @var array
4234 */
43- protected $ browserConfigurationFactory ;
35+ protected $ tunnelCapabilities = array () ;
4436
4537 /**
46- * Desired capabilities use to configure the tunnel .
38+ * API client .
4739 *
48- * @var array
40+ * @var IAPIClient
4941 */
50- protected $ tunnelCapabilities = array () ;
42+ protected $ apiClient ;
5143
5244 /**
5345 * Configures all tests.
@@ -60,9 +52,10 @@ protected function setUp()
6052 $ this ->testsRequireSubscriber [] = 'testTestEndedEvent ' ;
6153 $ this ->testsRequireSubscriber [] = 'testTestEndedWithoutSession ' ;
6254 $ this ->testsRequireSubscriber [] = 'testTunnelIdentifier ' ;
63- $ this ->browserConfigurationFactory = m::mock (
64- 'aik099 \\PHPUnit \\BrowserConfiguration \\IBrowserConfigurationFactory '
65- );
55+
56+ if ( $ this ->getName (false ) === 'testTestEndedEvent ' ) {
57+ $ this ->mockBrowserMethods [] = 'getAPIClient ' ;
58+ }
6659
6760 parent ::setUp ();
6861
@@ -133,7 +126,9 @@ public function testSetAPICorrect()
133126 */
134127 public function testSetHostCorrect ()
135128 {
136- $ browser = $ this ->createBrowserConfiguration (array (), false , true );
129+ $ browser = $ this ->createBrowserConfiguration ();
130+ $ browser ->setApiUsername ('A ' );
131+ $ browser ->setApiKey ('B ' );
137132
138133 $ this ->assertSame ($ browser , $ browser ->setHost ('EXAMPLE_HOST ' ));
139134 $ this ->assertSame ('A:B@ondemand.saucelabs.com ' , $ browser ->getHost ());
@@ -146,7 +141,10 @@ public function testSetHostCorrect()
146141 */
147142 public function testSetPortCorrect ()
148143 {
149- $ browser = $ this ->createBrowserConfiguration (array (), false , true );
144+ $ browser = $ this ->createBrowserConfiguration ();
145+ $ browser ->setApiUsername ('A ' );
146+ $ browser ->setApiKey ('B ' );
147+
150148 $ this ->assertSame ($ browser , $ browser ->setPort (5555 ));
151149 $ this ->assertSame (80 , $ browser ->getPort ());
152150 }
@@ -158,7 +156,10 @@ public function testSetPortCorrect()
158156 */
159157 public function testSetBrowserNameCorrect ()
160158 {
161- $ browser = $ this ->createBrowserConfiguration (array (), false , true );
159+ $ browser = $ this ->createBrowserConfiguration ();
160+ $ browser ->setApiUsername ('A ' );
161+ $ browser ->setApiKey ('B ' );
162+
162163 $ this ->assertSame ($ browser , $ browser ->setBrowserName ('' ));
163164 $ this ->assertSame ('chrome ' , $ browser ->getBrowserName ());
164165 }
@@ -174,7 +175,10 @@ public function testSetBrowserNameCorrect()
174175 */
175176 public function testSetDesiredCapabilitiesCorrect (array $ desired_capabilities = null , array $ expected = null )
176177 {
177- $ browser = $ this ->createBrowserConfiguration (array (), false , true );
178+ $ browser = $ this ->createBrowserConfiguration ();
179+ $ browser ->setApiUsername ('A ' );
180+ $ browser ->setApiKey ('B ' );
181+
178182 $ this ->assertSame ($ browser , $ browser ->setDesiredCapabilities ($ desired_capabilities ));
179183 $ this ->assertSame ($ expected , $ browser ->getDesiredCapabilities ());
180184 }
@@ -296,9 +300,7 @@ public function testTestEndedEvent($driver_type)
296300 $ test_case = $ this ->createTestCase ('TEST_NAME ' );
297301
298302 $ api_client = m::mock ('aik099 \\PHPUnit \\APIClient \\IAPIClient ' );
299- $ this ->browserConfigurationFactory ->shouldReceive ('createAPIClient ' )
300- ->with ($ this ->browser )
301- ->andReturn ($ api_client );
303+ $ this ->browser ->shouldReceive ('getAPIClient ' )->andReturn ($ api_client );
302304
303305 if ( $ driver_type == 'selenium ' ) {
304306 $ driver = m::mock ('\\Behat \\Mink \\Driver \\Selenium2Driver ' );
@@ -471,33 +473,4 @@ public function tunnelIdentifierDataProvider()
471473 );
472474 }
473475
474- /**
475- * Creates instance of browser configuration.
476- *
477- * @param array $aliases Aliases.
478- * @param boolean $add_subscriber Expect addition of subscriber to event dispatcher.
479- * @param boolean $with_api Include test API configuration.
480- *
481- * @return ApiBrowserConfiguration
482- */
483- protected function createBrowserConfiguration (array $ aliases = array (), $ add_subscriber = false , $ with_api = false )
484- {
485- /** @var ApiBrowserConfiguration $browser */
486- $ browser = new $ this ->browserConfigurationClass (
487- $ this ->eventDispatcher ,
488- $ this ->driverFactoryRegistry ,
489- $ this ->browserConfigurationFactory
490- );
491- $ browser ->setAliases ($ aliases );
492-
493- $ this ->eventDispatcher ->shouldReceive ('addSubscriber ' )->with ($ browser )->times ($ add_subscriber ? 1 : 0 );
494-
495- if ( $ with_api ) {
496- $ browser ->setApiUsername ('A ' );
497- $ browser ->setApiKey ('B ' );
498- }
499-
500- return $ browser ;
501- }
502-
503476}
0 commit comments