Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only start session if the session has not been started before #732

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ 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
* - resizeWindow()
* - maximizeWindow()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want to allow this, we must add new tests in the driver testsuite calling these methods before visiting a page, to ensure it actually works in all drivers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, this does not seem related to this PR, but to #733

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, that is my bad. Where would you add the tests? Looking at the CoreDriverTest and the Tests in the Selenium driver I could not see any tests on e.g. the visit method

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved that to #733.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the driver testsuite lives in https://github.com/minkphp/driver-testsuite and is a dev dependency in all drivers repositories, to share the same testsuite in all of them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I was scanning the testsuite, I could not find a test where the autostart is tested e.g. for the visit method by grepping te repository. Do you know if there is anything in this regard?

Copy link
Member

@stof stof Feb 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowing to call these methods without visiting a page is not related to auto-starting. It is a different feature (and this is what you need to test).

Auto-starting is not tested in the driver testsuite, because drivers don't care about it. It is implemented at the session level. But being able to resize before visiting is something that drivers themselves must support

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay. So what do you think about: minkphp/driver-testsuite#10

* - visit()
* - setRequestHeader()
* - setBasicAuth()
Expand All @@ -67,7 +69,9 @@ public function isStarted()
*/
public function start()
{
$this->driver->start();
if (!$this->isStarted()) {
$this->driver->start();
}
}

/**
Expand All @@ -92,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()
Expand Down Expand Up @@ -141,9 +147,7 @@ public function getSelectorsHandler()
public function visit($url)
{
// start session if needed
if (!$this->isStarted()) {
$this->start();
}
$this->start();

$this->driver->visit($url);
}
Expand Down
46 changes: 20 additions & 26 deletions tests/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test must not be removed. We still need to cover the case of calling visit on a started and on a non-started session IMO (thus, your mocks don't describe the actual interaction happening, as you removed the mocking of isStarted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the discussion from https://github.com/minkphp/Mink/pull/733/files#r99773293 is meant to happen on this PR instead.

{
$this->driver->expects($this->once())
Expand All @@ -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
Expand Down