Skip to content

Commit

Permalink
Session driver-independent way to make sessions unique.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Obuhovich committed Jun 6, 2013
1 parent 0afca9c commit 953c8a8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Behat/Mink/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Session
private $driver;
private $page;
private $selectorsHandler;
private $uniqueId;

/**
* Initializes session.
Expand All @@ -42,6 +43,7 @@ public function __construct(DriverInterface $driver, SelectorsHandler $selectors
$this->driver = $driver;
$this->page = new DocumentElement($this);
$this->selectorsHandler = $selectorsHandler;
$this->uniqueId = uniqid('mink_session_');
}

/**
Expand Down Expand Up @@ -97,6 +99,17 @@ public function getDriver()
return $this->driver;
}

/**
* Returns session unique id.
*
* @return string
* @access public
*/
public function getUniqueId()
{
return $this->uniqueId;
}

/**
* Returns page element.
*
Expand Down Expand Up @@ -205,7 +218,7 @@ public function getCurrentUrl()
/**
* Capture a screenshot of the current window.
*
* @return string screenshot of MIME type image/* depending
* @return string screenshot of MIME type image/* depending
* on driver (e.g., image/png, image/jpeg)
*/
public function getScreenshot()
Expand Down
21 changes: 21 additions & 0 deletions tests/Behat/Mink/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class SessionTest extends \PHPUnit_Framework_TestCase
{
private $driver;
private $selectorsHandler;

/**
* Session.
*
* @var Session
* @access private
*/
private $session;

protected function setUp()
Expand Down Expand Up @@ -114,4 +121,18 @@ public function testWait()

$this->session->wait(1000, 'function() {}');
}

/**
* Testing that 2 sessions created with same parameters have different IDs.
*
* @return void
* @access public
*/
public function testUniqueId()
{
$session = new Session($this->driver, $this->selectorsHandler);

$this->assertNotEquals($session->getUniqueId(), $this->session->getUniqueId());

}
}

5 comments on commit 953c8a8

@stof
Copy link
Member

@stof stof commented on 953c8a8 Apr 15, 2014

Choose a reason for hiding this comment

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

@aik099 what was the goal of this uniqueId property ? It is not used anywhere in Mink or in related code I know of, and I don't understand its goal (and on the other hand, the unique id is not unique enough as I regularly get test failures because the same id is reused on Windows)

@aik099
Copy link
Member

@aik099 aik099 commented on 953c8a8 Apr 15, 2014

Choose a reason for hiding this comment

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

This was created to be able distinct 2 Session class instances with identical drivers. It also was used during Session cloning.

Since all cloning related code was removed, then I guess we can safely remove this uniqueid stuff as well.

@aik099
Copy link
Member

@aik099 aik099 commented on 953c8a8 Apr 15, 2014

Choose a reason for hiding this comment

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

This is the original PR where it was added: #348

@stof
Copy link
Member

@stof stof commented on 953c8a8 Apr 15, 2014

Choose a reason for hiding this comment

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

OK, I suggest removing it before the 1.6 release

@aik099
Copy link
Member

@aik099 aik099 commented on 953c8a8 Apr 15, 2014

Choose a reason for hiding this comment

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

Agreed.

Please sign in to comment.