Skip to content

Commit

Permalink
Merge pull request #132 from aik099/inline-session-factory
Browse files Browse the repository at this point in the history
Integrated "SessionFactory" class into the "IsolatedSessionStrategy" class
  • Loading branch information
aik099 committed Mar 16, 2024
2 parents c621fe2 + 2588d78 commit 64070d5
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 180 deletions.
1 change: 0 additions & 1 deletion library/.phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace PHPSTORM_META {
override(\aik099\PHPUnit\Application::getObject(), map([
'session_factory' => \aik099\PHPUnit\Session\SessionFactory::class,
'session_strategy_factory' => \aik099\PHPUnit\Session\SessionStrategyFactory::class,
'session_strategy_manager' => \aik099\PHPUnit\Session\SessionStrategyManager::class,
'remote_url' => \aik099\PHPUnit\RemoteCoverage\RemoteUrl::class,
Expand Down
9 changes: 2 additions & 7 deletions library/aik099/PHPUnit/DIContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use aik099\PHPUnit\RemoteCoverage\RemoteUrl;
use aik099\PHPUnit\Session\ISessionStrategyFactory;
use aik099\PHPUnit\Session\IsolatedSessionStrategy;
use aik099\PHPUnit\Session\SessionFactory;
use aik099\PHPUnit\Session\SessionStrategyFactory;
use aik099\PHPUnit\Session\SessionStrategyManager;
use aik099\PHPUnit\Session\SharedSessionStrategy;
Expand Down Expand Up @@ -60,22 +59,18 @@ public function __construct(array $values = array())
{
parent::__construct($values);

$this['session_factory'] = function () {
return new SessionFactory();
};

$this['session_strategy_factory'] = function ($c) {
$session_strategy_factory = new SessionStrategyFactory();

$session_strategy_factory->register(
ISessionStrategyFactory::TYPE_ISOLATED,
new IsolatedSessionStrategy($c['session_factory'])
new IsolatedSessionStrategy()
);

$session_strategy_factory->register(
ISessionStrategyFactory::TYPE_SHARED,
new SharedSessionStrategy(
new IsolatedSessionStrategy($c['session_factory'])
new IsolatedSessionStrategy()
)
);

Expand Down
34 changes: 0 additions & 34 deletions library/aik099/PHPUnit/Session/ISessionFactory.php

This file was deleted.

19 changes: 1 addition & 18 deletions library/aik099/PHPUnit/Session/IsolatedSessionStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,12 @@
class IsolatedSessionStrategy extends AbstractSessionStrategy
{

/**
* Session factory.
*
* @var ISessionFactory
*/
private $_sessionFactory;

/**
* Creates isolated session strategy instance.
*
* @param ISessionFactory $session_factory Session factory.
*/
public function __construct(ISessionFactory $session_factory)
{
$this->_sessionFactory = $session_factory;
}

/**
* @inheritDoc
*/
public function session(BrowserConfiguration $browser)
{
$session = $this->_sessionFactory->createSession($browser);
$session = new Session($browser->createDriver());
$this->isFreshSession = true;

return $session;
Expand Down
37 changes: 0 additions & 37 deletions library/aik099/PHPUnit/Session/SessionFactory.php

This file was deleted.

2 changes: 0 additions & 2 deletions tests/aik099/PHPUnit/Integration/DIContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use aik099\PHPUnit\RemoteCoverage\RemoteUrl;
use aik099\PHPUnit\Session\ISessionStrategyFactory;
use aik099\PHPUnit\Session\IsolatedSessionStrategy;
use aik099\PHPUnit\Session\SessionFactory;
use aik099\PHPUnit\Session\SessionStrategyFactory;
use aik099\PHPUnit\Session\SessionStrategyManager;
use aik099\PHPUnit\Session\SharedSessionStrategy;
Expand Down Expand Up @@ -82,7 +81,6 @@ public static function serviceDefinitionsDataProvider()
{
return array(
array('application', Application::class),
array('session_factory', SessionFactory::class),
array('session_strategy_factory', SessionStrategyFactory::class),
array('session_strategy_manager', SessionStrategyManager::class),
array('remote_url', RemoteUrl::class),
Expand Down
43 changes: 20 additions & 23 deletions tests/aik099/PHPUnit/Session/IsolatedSessionStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,20 @@
namespace tests\aik099\PHPUnit\Session;


use aik099\PHPUnit\Session\ISessionFactory;
use aik099\PHPUnit\Session\IsolatedSessionStrategy;
use Behat\Mink\Driver\DriverInterface;
use Behat\Mink\Session;
use Mockery as m;
use Mockery\MockInterface;

class IsolatedSessionStrategyTest extends AbstractSessionStrategyTestCase
{

/**
* Session factory.
*
* @var ISessionFactory|MockInterface
*/
private $_factory;

/**
* @before
*/
protected function setUpTest()
{
$this->_factory = m::mock(ISessionFactory::class);
$this->strategy = new IsolatedSessionStrategy($this->_factory);
$this->strategy = new IsolatedSessionStrategy();
}

/**
Expand All @@ -44,25 +36,30 @@ public function testSession()
{
$browser = m::mock(self::BROWSER_CLASS);

$session1 = m::mock(self::SESSION_CLASS);
$session2 = m::mock(self::SESSION_CLASS);
$driver1 = m::mock(DriverInterface::class);
$driver1->shouldReceive('setSession')->with(m::type(Session::class))->once();

$driver2 = m::mock(DriverInterface::class);
$driver2->shouldReceive('setSession')->with(m::type(Session::class))->once();

$this->_factory
->shouldReceive('createSession')
->with($browser)
->twice()
->andReturn($session1, $session2);
$browser->shouldReceive('createDriver')->twice()->andReturn($driver1, $driver2);

$this->assertEquals($session1, $this->strategy->session($browser));
$this->assertEquals($session2, $this->strategy->session($browser));
$session1 = $this->strategy->session($browser);
$this->assertInstanceOf(Session::class, $session1);
$this->assertSame($driver1, $session1->getDriver());

$session2 = $this->strategy->session($browser);
$this->assertInstanceOf(Session::class, $session2);
$this->assertSame($driver2, $session2->getDriver());
}

public function testIsFreshSessionAfterSessionIsStarted()
{
$browser = m::mock(self::BROWSER_CLASS);
$session = m::mock(self::SESSION_CLASS);
$driver = m::mock(DriverInterface::class);
$driver->shouldReceive('setSession')->with(m::type(Session::class))->once();

$this->_factory->shouldReceive('createSession')->with($browser)->once()->andReturn($session);
$browser = m::mock(self::BROWSER_CLASS);
$browser->shouldReceive('createDriver')->once()->andReturn($driver);

$this->strategy->session($browser);

Expand Down
58 changes: 0 additions & 58 deletions tests/aik099/PHPUnit/Session/SessionFactoryTest.php

This file was deleted.

0 comments on commit 64070d5

Please sign in to comment.