class Mink in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/behat/mink/src/Mink.php \Behat\Mink\Mink
Mink sessions manager.
@author Konstantin Kudryashov <ever.zet@gmail.com>
Hierarchy
- class \Behat\Mink\Mink
Expanded class hierarchy of Mink
3 files declare their use of Mink
- BrowserTestBase.php in core/
modules/ simpletest/ src/ BrowserTestBase.php - Contains \Drupal\simpletest\BrowserTestBase.
- MinkTest.php in vendor/
behat/ mink/ tests/ MinkTest.php - TestCase.php in vendor/
behat/ mink/ driver-testsuite/ tests/ TestCase.php
1 string reference to 'Mink'
- SessionTest::provideResponseHeader in vendor/
behat/ mink/ tests/ SessionTest.php
File
- vendor/
behat/ mink/ src/ Mink.php, line 18
Namespace
Behat\MinkView source
class Mink {
private $defaultSessionName;
/**
* Sessions.
*
* @var Session[]
*/
private $sessions = array();
/**
* Initializes manager.
*
* @param Session[] $sessions
*/
public function __construct(array $sessions = array()) {
foreach ($sessions as $name => $session) {
$this
->registerSession($name, $session);
}
}
/**
* Stops all started sessions.
*/
public function __destruct() {
$this
->stopSessions();
}
/**
* Registers new session.
*
* @param string $name
* @param Session $session
*/
public function registerSession($name, Session $session) {
$name = strtolower($name);
$this->sessions[$name] = $session;
}
/**
* Checks whether session with specified name is registered.
*
* @param string $name
*
* @return Boolean
*/
public function hasSession($name) {
return isset($this->sessions[strtolower($name)]);
}
/**
* Sets default session name to use.
*
* @param string $name name of the registered session
*
* @throws \InvalidArgumentException
*/
public function setDefaultSessionName($name) {
$name = strtolower($name);
if (!isset($this->sessions[$name])) {
throw new \InvalidArgumentException(sprintf('Session "%s" is not registered.', $name));
}
$this->defaultSessionName = $name;
}
/**
* Returns default session name or null if none.
*
* @return null|string
*/
public function getDefaultSessionName() {
return $this->defaultSessionName;
}
/**
* Returns registered session by it's name or active one and automatically starts it if required.
*
* @param string $name session name
*
* @return Session
*
* @throws \InvalidArgumentException If the named session is not registered
*/
public function getSession($name = null) {
$session = $this
->locateSession($name);
// start session if needed
if (!$session
->isStarted()) {
$session
->start();
}
return $session;
}
/**
* Checks whether a named session (or the default session) has already been started.
*
* @param string $name session name - if null then the default session will be checked
*
* @return bool whether the session has been started
*
* @throws \InvalidArgumentException If the named session is not registered
*/
public function isSessionStarted($name = null) {
$session = $this
->locateSession($name);
return $session
->isStarted();
}
/**
* Returns session asserter.
*
* @param Session|string $session session object or name
*
* @return WebAssert
*/
public function assertSession($session = null) {
if (!$session instanceof Session) {
$session = $this
->getSession($session);
}
return new WebAssert($session);
}
/**
* Resets all started sessions.
*/
public function resetSessions() {
foreach ($this->sessions as $session) {
if ($session
->isStarted()) {
$session
->reset();
}
}
}
/**
* Restarts all started sessions.
*/
public function restartSessions() {
foreach ($this->sessions as $session) {
if ($session
->isStarted()) {
$session
->restart();
}
}
}
/**
* Stops all started sessions.
*/
public function stopSessions() {
foreach ($this->sessions as $session) {
if ($session
->isStarted()) {
$session
->stop();
}
}
}
/**
* Returns the named or default session without starting it.
*
* @param string $name session name
*
* @return Session
*
* @throws \InvalidArgumentException If the named session is not registered
*/
protected function locateSession($name = null) {
$name = strtolower($name) ?: $this->defaultSessionName;
if (null === $name) {
throw new \InvalidArgumentException('Specify session name to get');
}
if (!isset($this->sessions[$name])) {
throw new \InvalidArgumentException(sprintf('Session "%s" is not registered.', $name));
}
$session = $this->sessions[$name];
return $session;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Mink:: |
private | property | ||
Mink:: |
private | property | Sessions. | |
Mink:: |
public | function | Returns session asserter. | |
Mink:: |
public | function | Returns default session name or null if none. | |
Mink:: |
public | function | Returns registered session by it's name or active one and automatically starts it if required. | |
Mink:: |
public | function | Checks whether session with specified name is registered. | |
Mink:: |
public | function | Checks whether a named session (or the default session) has already been started. | |
Mink:: |
protected | function | Returns the named or default session without starting it. | |
Mink:: |
public | function | Registers new session. | |
Mink:: |
public | function | Resets all started sessions. | |
Mink:: |
public | function | Restarts all started sessions. | |
Mink:: |
public | function | Sets default session name to use. | |
Mink:: |
public | function | Stops all started sessions. | |
Mink:: |
public | function | Initializes manager. | |
Mink:: |
public | function | Stops all started sessions. |