Skip to content

Commit 388e9c7

Browse files
authored
Merge pull request #9 from twistersfury/master-session
Adjusting Session To Use Session Manager. @Fenikkusu thnx
2 parents ba4d287 + 0fcbbc1 commit 388e9c7

File tree

9 files changed

+62
-7
lines changed

9 files changed

+62
-7
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ DB_HOST=127.0.0.1
33
DB_NAME=phalcon
44
DB_USERNAME=root
55
DB_PASSWORD=password
6+
DB_PORT=3306

src/Codeception/Lib/Connector/Phalcon4/MemorySession.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,27 @@ private function generateId()
295295
{
296296
return md5(time());
297297
}
298+
299+
/**
300+
* Dummy - We Don't Actually Read Anything
301+
*
302+
* @return string
303+
*/
304+
public function read($id): string
305+
{
306+
return "";
307+
}
308+
309+
/**
310+
* Write - We Don't Actually Write Anything
311+
*
312+
* @param $id
313+
* @param $data
314+
*
315+
* @return bool
316+
*/
317+
public function write($id, $data): bool
318+
{
319+
return true;
320+
}
298321
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Codeception\Lib\Connector\Phalcon4;
4+
5+
use Phalcon\Session\Manager;
6+
7+
class SessionManager extends Manager
8+
{
9+
/**
10+
* We have to override this as otherwise nothing working correctly in testing.
11+
*
12+
* @return bool
13+
*/
14+
public function exists(): bool
15+
{
16+
return true;
17+
}
18+
}

src/Codeception/Module/Phalcon4.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
use Codeception\Lib\Interfaces\PartedModule;
1313
use Codeception\TestInterface;
1414
use Codeception\Util\ReflectionHelper;
15+
use Exception;
1516
use PDOException;
1617
use Phalcon\Di;
1718
use Phalcon\Di\Injectable;
1819
use Phalcon\DiInterface;
1920
use Phalcon\Mvc\Model as PhalconModel;
2021
use Phalcon\Mvc\Router\RouteInterface;
2122
use Phalcon\Mvc\RouterInterface;
23+
use Codeception\Lib\Connector\Phalcon4\SessionManager;
2224
use Phalcon\Url;
2325

2426
/**
@@ -150,8 +152,14 @@ public function _before(TestInterface $test)
150152
Di::setDefault($this->di);
151153

152154
if ($this->di->has('session')) {
155+
/** @var Manager $manager */
156+
$manager = $this->di->get(SessionManager::class);
157+
$manager->setAdapter(
158+
$this->di->get($this->config['session'])
159+
);
160+
153161
// Destroy existing sessions of previous tests
154-
$this->di['session'] = $this->di->get($this->config['session']);
162+
$this->di['session'] = $manager;
155163
}
156164

157165
if ($this->di->has('cookies')) {
@@ -223,7 +231,7 @@ public function getApplication()
223231
public function haveInSession($key, $val)
224232
{
225233
$this->di->get('session')->set($key, $val);
226-
$this->debugSection('Session', json_encode($this->di['session']->toArray()));
234+
$this->debugSection('Session', json_encode($this->di['session']->getAdapter()->toArray()));
227235
}
228236

229237
/**
@@ -242,7 +250,7 @@ public function haveInSession($key, $val)
242250
*/
243251
public function seeInSession($key, $value = null)
244252
{
245-
$this->debugSection('Session', json_encode($this->di['session']->toArray()));
253+
$this->debugSection('Session', json_encode($this->di['session']->getAdapter()->toArray()));
246254

247255
if (is_array($key)) {
248256
$this->seeSessionHasValues($key);

tests/_data/bootstrap-micro.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<?php
2+
23
$di = new \Phalcon\DI\FactoryDefault();
34
return new \Phalcon\Mvc\Micro($di);

tests/_support/AcceptanceTester.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
43
/**
54
* Inherited Methods
5+
*
66
* @method void wantToTest($text)
77
* @method void wantTo($text)
88
* @method void execute($callable)
@@ -16,6 +16,7 @@
1616
*
1717
* @SuppressWarnings(PHPMD)
1818
*/
19+
1920
class AcceptanceTester extends \Codeception\Actor
2021
{
2122
use _generated\AcceptanceTesterActions;

tests/_support/FunctionalTester.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
43
/**
54
* Inherited Methods
5+
*
66
* @method void wantToTest($text)
77
* @method void wantTo($text)
88
* @method void execute($callable)
@@ -16,6 +16,7 @@
1616
*
1717
* @SuppressWarnings(PHPMD)
1818
*/
19+
1920
class FunctionalTester extends \Codeception\Actor
2021
{
2122
use _generated\FunctionalTesterActions;

tests/_support/UnitTester.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
43
/**
54
* Inherited Methods
5+
*
66
* @method void wantToTest($text)
77
* @method void wantTo($text)
88
* @method void execute($callable)
@@ -16,6 +16,7 @@
1616
*
1717
* @SuppressWarnings(PHPMD)
1818
*/
19+
1920
class UnitTester extends \Codeception\Actor
2021
{
2122
use _generated\UnitTesterActions;

tests/unit/Phalcon4ModuleTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ public function testContainerMethods()
140140
$module->_before($test);
141141

142142
$session = $module->grabServiceFromContainer('session');
143-
$this->assertInstanceOf('Codeception\Lib\Connector\Phalcon4\MemorySession', $session);
143+
$this->assertInstanceOf('Phalcon\Session\Manager', $session);
144+
$this->assertInstanceOf('Codeception\Lib\Connector\Phalcon4\MemorySession', $session->getAdapter());
144145

145146
$testService = $module->addServiceToContainer('std', function () {
146147
return new \stdClass();

0 commit comments

Comments
 (0)