From a78efd0ab1950ce0efe30ce3f09f1eff06f39145 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Tue, 7 Feb 2017 09:40:34 +0100 Subject: [PATCH 1/8] Only start session if the session has not been started before --- src/Session.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Session.php b/src/Session.php index d8107724c..90e9ff6e6 100644 --- a/src/Session.php +++ b/src/Session.php @@ -55,7 +55,7 @@ public function isStarted() } /** - * Starts session driver. + * Starts session driver if session is not started. * * Calling any action before visiting a page is an undefined behavior. * The only supported method calls on a fresh driver are @@ -67,7 +67,10 @@ public function isStarted() */ public function start() { - $this->driver->start(); + // start session if needed + if (!$this->isStarted()) { + $this->driver->start(); + } } /** @@ -141,9 +144,7 @@ public function getSelectorsHandler() public function visit($url) { // start session if needed - if (!$this->isStarted()) { - $this->start(); - } + $this->start(); $this->driver->visit($url); } From 93087a251fb57f86d5ea3e829917b75eb638f885 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Tue, 7 Feb 2017 09:48:49 +0100 Subject: [PATCH 2/8] Adjusted tests --- tests/SessionTest.php | 46 +++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/tests/SessionTest.php b/tests/SessionTest.php index f89705ae7..808a241d8 100644 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -57,14 +57,32 @@ public function testIsStarted() $this->assertTrue($this->session->isStarted()); } - public function testStart() + public function testStartWithoutRunningSession() { + $this->driver + ->expects($this->once()) + ->method('isStarted') + ->willReturn(false); + $this->driver->expects($this->once()) ->method('start'); $this->session->start(); } + public function testStartWithRunningSession() + { + $this->driver + ->expects($this->once()) + ->method('isStarted') + ->willReturn(true); + + $this->driver->expects($this->never()) + ->method('start'); + + $this->session->start(); + } + public function testStop() { $this->driver->expects($this->once()) @@ -83,34 +101,10 @@ public function testRestart() $this->session->restart(); } - public function testVisitWithoutRunningSession() - { - $this->driver - ->expects($this->once()) - ->method('isStarted') - ->willReturn(false); - - $this->driver - ->expects($this->once()) - ->method('start'); - - $this->driver - ->expects($this->once()) - ->method('visit') - ->with($url = 'some_url'); - - $this->session->visit($url); - } - - public function testVisitWithRunningSession() + public function testVisit() { $this->driver ->expects($this->once()) - ->method('isStarted') - ->willReturn(true); - - $this->driver - ->expects($this->never()) ->method('start'); $this->driver From d3a2a1b4745994f0b7e44fc164a83457871353ef Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Tue, 7 Feb 2017 10:12:13 +0100 Subject: [PATCH 3/8] Completed methods allowed on fresh driver --- src/Session.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Session.php b/src/Session.php index 90e9ff6e6..6818c8bdb 100644 --- a/src/Session.php +++ b/src/Session.php @@ -59,6 +59,8 @@ public function isStarted() * * Calling any action before visiting a page is an undefined behavior. * The only supported method calls on a fresh driver are + * - resizeWindow() + * - maximizeWindow() * - visit() * - setRequestHeader() * - setBasicAuth() @@ -95,6 +97,8 @@ public function restart() * * Calling any action before visiting a page is an undefined behavior. * The only supported method calls on a fresh driver are + * - resizeWindow() + * - maximizeWindow() * - visit() * - setRequestHeader() * - setBasicAuth() From cc3df3df37b81f3c68f137cb9a32b293543ad048 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Tue, 7 Feb 2017 10:13:20 +0100 Subject: [PATCH 4/8] Removed comment --- src/Session.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Session.php b/src/Session.php index 6818c8bdb..071e4b172 100644 --- a/src/Session.php +++ b/src/Session.php @@ -69,7 +69,6 @@ public function isStarted() */ public function start() { - // start session if needed if (!$this->isStarted()) { $this->driver->start(); } From 900e11ad1bbb5326d4de8385a2fbccefea4d5322 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Tue, 7 Feb 2017 10:34:16 +0100 Subject: [PATCH 5/8] Revert "Completed methods allowed on fresh driver" This reverts commit d3a2a1b4745994f0b7e44fc164a83457871353ef. --- src/Session.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Session.php b/src/Session.php index 071e4b172..0edf3de69 100644 --- a/src/Session.php +++ b/src/Session.php @@ -59,8 +59,6 @@ public function isStarted() * * Calling any action before visiting a page is an undefined behavior. * The only supported method calls on a fresh driver are - * - resizeWindow() - * - maximizeWindow() * - visit() * - setRequestHeader() * - setBasicAuth() @@ -96,8 +94,6 @@ public function restart() * * Calling any action before visiting a page is an undefined behavior. * The only supported method calls on a fresh driver are - * - resizeWindow() - * - maximizeWindow() * - visit() * - setRequestHeader() * - setBasicAuth() From dd2b7e08e8b27ce211f2c5e1f51cf1d78a66dbb8 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Tue, 7 Feb 2017 09:50:49 +0100 Subject: [PATCH 6/8] Added session autostart to resizeWindow and maximizeWindow --- src/Session.php | 4 ++++ tests/SessionTest.php | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Session.php b/src/Session.php index 0edf3de69..f26faa466 100644 --- a/src/Session.php +++ b/src/Session.php @@ -363,6 +363,8 @@ public function wait($time, $condition = 'false') */ public function resizeWindow($width, $height, $name = null) { + // start session if needed + $this->start(); $this->driver->resizeWindow($width, $height, $name); } @@ -373,6 +375,8 @@ public function resizeWindow($width, $height, $name = null) */ public function maximizeWindow($name = null) { + // start session if needed + $this->start(); $this->driver->maximizeWindow($name); } } diff --git a/tests/SessionTest.php b/tests/SessionTest.php index 808a241d8..6167d3661 100644 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -316,6 +316,10 @@ public function testWait() public function testResizeWindow() { + $this->driver + ->expects($this->once()) + ->method('start'); + $this->driver->expects($this->once()) ->method('resizeWindow') ->with(800, 600, 'test'); @@ -325,6 +329,10 @@ public function testResizeWindow() public function testMaximizeWindow() { + $this->driver + ->expects($this->once()) + ->method('start'); + $this->driver->expects($this->once()) ->method('maximizeWindow') ->with('test'); From d018f1705a72dfc82728b633280717641a172fe4 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Tue, 7 Feb 2017 10:02:41 +0100 Subject: [PATCH 7/8] Removed comments --- src/Session.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Session.php b/src/Session.php index f26faa466..cb09be5fc 100644 --- a/src/Session.php +++ b/src/Session.php @@ -142,9 +142,7 @@ public function getSelectorsHandler() */ public function visit($url) { - // start session if needed $this->start(); - $this->driver->visit($url); } @@ -363,7 +361,6 @@ public function wait($time, $condition = 'false') */ public function resizeWindow($width, $height, $name = null) { - // start session if needed $this->start(); $this->driver->resizeWindow($width, $height, $name); } @@ -375,7 +372,6 @@ public function resizeWindow($width, $height, $name = null) */ public function maximizeWindow($name = null) { - // start session if needed $this->start(); $this->driver->maximizeWindow($name); } From da1143474d9adefb4b4d97f8936f203243ab06db Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Tue, 7 Feb 2017 10:12:13 +0100 Subject: [PATCH 8/8] Completed methods allowed on fresh driver --- src/Session.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Session.php b/src/Session.php index cb09be5fc..ebe853cb2 100644 --- a/src/Session.php +++ b/src/Session.php @@ -59,6 +59,8 @@ public function isStarted() * * Calling any action before visiting a page is an undefined behavior. * The only supported method calls on a fresh driver are + * - resizeWindow() + * - maximizeWindow() * - visit() * - setRequestHeader() * - setBasicAuth() @@ -94,6 +96,8 @@ public function restart() * * Calling any action before visiting a page is an undefined behavior. * The only supported method calls on a fresh driver are + * - resizeWindow() + * - maximizeWindow() * - visit() * - setRequestHeader() * - setBasicAuth()