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 all 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
10 changes: 5 additions & 5 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -67,7 +67,9 @@ public function isStarted()
*/
public function start()
{
$this->driver->start();
if (!$this->isStarted()) {
$this->driver->start();
}
}

/**
Expand Down Expand Up @@ -141,9 +143,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