Skip to content

Commit 2588d78

Browse files
committed
Integrated SessionFactory class into the IsolatedSessionStrategy class
1 parent c621fe2 commit 2588d78

8 files changed

Lines changed: 23 additions & 180 deletions

File tree

library/.phpstorm.meta.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPSTORM_META {
44
override(\aik099\PHPUnit\Application::getObject(), map([
5-
'session_factory' => \aik099\PHPUnit\Session\SessionFactory::class,
65
'session_strategy_factory' => \aik099\PHPUnit\Session\SessionStrategyFactory::class,
76
'session_strategy_manager' => \aik099\PHPUnit\Session\SessionStrategyManager::class,
87
'remote_url' => \aik099\PHPUnit\RemoteCoverage\RemoteUrl::class,

library/aik099/PHPUnit/DIContainer.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use aik099\PHPUnit\RemoteCoverage\RemoteUrl;
2626
use aik099\PHPUnit\Session\ISessionStrategyFactory;
2727
use aik099\PHPUnit\Session\IsolatedSessionStrategy;
28-
use aik099\PHPUnit\Session\SessionFactory;
2928
use aik099\PHPUnit\Session\SessionStrategyFactory;
3029
use aik099\PHPUnit\Session\SessionStrategyManager;
3130
use aik099\PHPUnit\Session\SharedSessionStrategy;
@@ -60,22 +59,18 @@ public function __construct(array $values = array())
6059
{
6160
parent::__construct($values);
6261

63-
$this['session_factory'] = function () {
64-
return new SessionFactory();
65-
};
66-
6762
$this['session_strategy_factory'] = function ($c) {
6863
$session_strategy_factory = new SessionStrategyFactory();
6964

7065
$session_strategy_factory->register(
7166
ISessionStrategyFactory::TYPE_ISOLATED,
72-
new IsolatedSessionStrategy($c['session_factory'])
67+
new IsolatedSessionStrategy()
7368
);
7469

7570
$session_strategy_factory->register(
7671
ISessionStrategyFactory::TYPE_SHARED,
7772
new SharedSessionStrategy(
78-
new IsolatedSessionStrategy($c['session_factory'])
73+
new IsolatedSessionStrategy()
7974
)
8075
);
8176

library/aik099/PHPUnit/Session/ISessionFactory.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

library/aik099/PHPUnit/Session/IsolatedSessionStrategy.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,12 @@
2323
class IsolatedSessionStrategy extends AbstractSessionStrategy
2424
{
2525

26-
/**
27-
* Session factory.
28-
*
29-
* @var ISessionFactory
30-
*/
31-
private $_sessionFactory;
32-
33-
/**
34-
* Creates isolated session strategy instance.
35-
*
36-
* @param ISessionFactory $session_factory Session factory.
37-
*/
38-
public function __construct(ISessionFactory $session_factory)
39-
{
40-
$this->_sessionFactory = $session_factory;
41-
}
42-
4326
/**
4427
* @inheritDoc
4528
*/
4629
public function session(BrowserConfiguration $browser)
4730
{
48-
$session = $this->_sessionFactory->createSession($browser);
31+
$session = new Session($browser->createDriver());
4932
$this->isFreshSession = true;
5033

5134
return $session;

library/aik099/PHPUnit/Session/SessionFactory.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/aik099/PHPUnit/Integration/DIContainerTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use aik099\PHPUnit\RemoteCoverage\RemoteUrl;
2929
use aik099\PHPUnit\Session\ISessionStrategyFactory;
3030
use aik099\PHPUnit\Session\IsolatedSessionStrategy;
31-
use aik099\PHPUnit\Session\SessionFactory;
3231
use aik099\PHPUnit\Session\SessionStrategyFactory;
3332
use aik099\PHPUnit\Session\SessionStrategyManager;
3433
use aik099\PHPUnit\Session\SharedSessionStrategy;
@@ -82,7 +81,6 @@ public static function serviceDefinitionsDataProvider()
8281
{
8382
return array(
8483
array('application', Application::class),
85-
array('session_factory', SessionFactory::class),
8684
array('session_strategy_factory', SessionStrategyFactory::class),
8785
array('session_strategy_manager', SessionStrategyManager::class),
8886
array('remote_url', RemoteUrl::class),

tests/aik099/PHPUnit/Session/IsolatedSessionStrategyTest.php

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,20 @@
1111
namespace tests\aik099\PHPUnit\Session;
1212

1313

14-
use aik099\PHPUnit\Session\ISessionFactory;
1514
use aik099\PHPUnit\Session\IsolatedSessionStrategy;
15+
use Behat\Mink\Driver\DriverInterface;
16+
use Behat\Mink\Session;
1617
use Mockery as m;
17-
use Mockery\MockInterface;
1818

1919
class IsolatedSessionStrategyTest extends AbstractSessionStrategyTestCase
2020
{
2121

22-
/**
23-
* Session factory.
24-
*
25-
* @var ISessionFactory|MockInterface
26-
*/
27-
private $_factory;
28-
2922
/**
3023
* @before
3124
*/
3225
protected function setUpTest()
3326
{
34-
$this->_factory = m::mock(ISessionFactory::class);
35-
$this->strategy = new IsolatedSessionStrategy($this->_factory);
27+
$this->strategy = new IsolatedSessionStrategy();
3628
}
3729

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

47-
$session1 = m::mock(self::SESSION_CLASS);
48-
$session2 = m::mock(self::SESSION_CLASS);
39+
$driver1 = m::mock(DriverInterface::class);
40+
$driver1->shouldReceive('setSession')->with(m::type(Session::class))->once();
41+
42+
$driver2 = m::mock(DriverInterface::class);
43+
$driver2->shouldReceive('setSession')->with(m::type(Session::class))->once();
4944

50-
$this->_factory
51-
->shouldReceive('createSession')
52-
->with($browser)
53-
->twice()
54-
->andReturn($session1, $session2);
45+
$browser->shouldReceive('createDriver')->twice()->andReturn($driver1, $driver2);
5546

56-
$this->assertEquals($session1, $this->strategy->session($browser));
57-
$this->assertEquals($session2, $this->strategy->session($browser));
47+
$session1 = $this->strategy->session($browser);
48+
$this->assertInstanceOf(Session::class, $session1);
49+
$this->assertSame($driver1, $session1->getDriver());
50+
51+
$session2 = $this->strategy->session($browser);
52+
$this->assertInstanceOf(Session::class, $session2);
53+
$this->assertSame($driver2, $session2->getDriver());
5854
}
5955

6056
public function testIsFreshSessionAfterSessionIsStarted()
6157
{
62-
$browser = m::mock(self::BROWSER_CLASS);
63-
$session = m::mock(self::SESSION_CLASS);
58+
$driver = m::mock(DriverInterface::class);
59+
$driver->shouldReceive('setSession')->with(m::type(Session::class))->once();
6460

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

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

tests/aik099/PHPUnit/Session/SessionFactoryTest.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)