Skip to content

Commit

Permalink
[user] separate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
connorhu committed Dec 20, 2023
1 parent 607158e commit cf7a2a5
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 16 deletions.
44 changes: 44 additions & 0 deletions tests/user/sfUserEventDispatcherTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the symfony package.
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use PHPUnit\Framework\TestCase;

require_once __DIR__.'/../PhpUnitSfTestHelperTrait.php';
require_once __DIR__.'/../sfEventDispatcherTestCase.php';

/**
* @internal
*
* @coversNothing
*/
class sfUserEventDispatcherTest extends sfEventDispatcherTestCase
{
protected $sessionPath;
protected $storage;

public function setUp(): void
{
$this->dispatcher = new sfEventDispatcher();
$this->sessionPath = sys_get_temp_dir().'/sessions_'.rand(11111, 99999);
$this->storage = new sfSessionTestStorage(array('session_path' => $this->sessionPath));

$user = new sfUser($this->dispatcher, $this->storage);

$this->testObject = $user;
$this->class = 'user';
}

protected function tearDown(): void
{
$this->storage->clear();

sfToolkit::clearDirectory($this->sessionPath);
}
}
45 changes: 45 additions & 0 deletions tests/user/sfUserParameterHolderProxyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/*
* This file is part of the symfony package.
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use PHPUnit\Framework\TestCase;

require_once __DIR__.'/../PhpUnitSfTestHelperTrait.php';
require_once __DIR__.'/../sfParameterHolderProxyTestCase.php';

/**
* @internal
*
* @coversNothing
*/
class sfUserParameterHolderProxyTest extends sfParameterHolderProxyTestCase
{
protected $dispatcher;
protected $sessionPath;
protected $storage;

public function setUp(): void
{
$this->dispatcher = new sfEventDispatcher();
$this->sessionPath = sys_get_temp_dir().'/sessions_'.rand(11111, 99999);
$this->storage = new sfSessionTestStorage(array('session_path' => $this->sessionPath));

$user = new sfUser($this->dispatcher, $this->storage);

$this->methodName = 'attribute';
$this->object = $user;
}

protected function tearDown(): void
{
$this->storage->clear();

sfToolkit::clearDirectory($this->sessionPath);
}
}
21 changes: 5 additions & 16 deletions tests/user/sfUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPUnit\Framework\TestCase;

require_once __DIR__.'/../PhpUnitSfTestHelperTrait.php';
require_once __DIR__.'/../fixtures/mySfUser.php';

function user_flush($dispatcher, $user, $storage, $options = array())
{
Expand Down Expand Up @@ -38,7 +39,7 @@ public function testTodoMigrate()
$sessionPath = sys_get_temp_dir().'/sessions_'.rand(11111, 99999);
$storage = new sfSessionTestStorage(array('session_path' => $sessionPath));

$user = new mySfUser($dispatcher, $storage);
$user = new sfUser($dispatcher, $storage);

// ->initialize()
$this->diag('->initialize()');
Expand All @@ -54,7 +55,7 @@ public function testTodoMigrate()
user_flush($dispatcher, $user, $storage);
$this->is($user->getCulture(), 'de', '->initialize() reads the culture from the session data if available');

$userBis = new mySfUser($dispatcher, $storage);
$userBis = new sfUser($dispatcher, $storage);
$this->is($userBis->getCulture(), 'de', '->initialize() serializes the culture to the session data');

// ->setCulture() ->getCulture()
Expand All @@ -70,12 +71,12 @@ public function testTodoMigrate()
$this->is($user->hasFlash('foo'), true, '->hasFlash() returns true if the flash variable exists');
user_flush($dispatcher, $user, $storage, array('use_flash' => true));

$userBis = new mySfUser($dispatcher, $storage, array('use_flash' => true));
$userBis = new sfUser($dispatcher, $storage, array('use_flash' => true));
$this->is($userBis->getFlash('foo'), 'bar', '->getFlash() returns a flash previously set');
$this->is($userBis->hasFlash('foo'), true, '->hasFlash() returns true if the flash variable exists');
user_flush($dispatcher, $user, $storage, array('use_flash' => true));

$userBis = new mySfUser($dispatcher, $storage, array('use_flash' => true));
$userBis = new sfUser($dispatcher, $storage, array('use_flash' => true));
$this->is($userBis->getFlash('foo'), null, 'Flashes are automatically removed after the next request');
$this->is($userBis->hasFlash('foo'), false, '->hasFlash() returns true if the flash variable exists');

Expand All @@ -94,18 +95,6 @@ public function testTodoMigrate()
unset($user['foo2']);
$this->is(isset($user['foo2']), false, '->offsetUnset() unsets attribute by name');

$user = new mySfUser($dispatcher, $storage);

// attribute holder proxy
require_once __DIR__.'/../../test/unit/sfParameterHolderTest.class.php';
$pht = new sfParameterHolderProxyTest($this);
$pht->launchTests($user, 'attribute');

// new methods via sfEventDispatcher
require_once __DIR__.'/../../test/unit/sfEventDispatcherTest.class.php';
$dispatcherTest = new sfEventDispatcherTest($this);
$dispatcherTest->launchTests($dispatcher, $user, 'user');

$storage->clear();

sfToolkit::clearDirectory($sessionPath);
Expand Down

0 comments on commit cf7a2a5

Please sign in to comment.