Skip to content

Instantly share code, notes, and snippets.

@kalifg
Created March 20, 2013 15:58
Show Gist options
  • Save kalifg/5205853 to your computer and use it in GitHub Desktop.
Save kalifg/5205853 to your computer and use it in GitHub Desktop.
<?php
namespace Chess\ChessBundle\Test;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
use Chess\UserBundle\Entity\User;
class WebTestCase extends BaseWebTestCase
{
protected $client;
protected $user;
# Attempt to be able to test code which has references to qcodo code
public function __construct($name = NULL, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
# TODO For the qcodo
defined('APP_ROOT') || define('APP_ROOT', realpath(__DIR__ .'/../../../../'));
require_once(APP_ROOT.'/chess/ChessKernel.php');
$kernel = new \ChessKernel('test', false);
$kernel->boot();
require_once(APP_ROOT . '/includes/prepend.inc.php');
}
protected function getClient()
{
if (!isset($this->client)) {
$this->client = static::createClient();
}
return $this->client;
}
protected function getContainer()
{
return $this->getClient()->getContainer();
}
protected function get($service)
{
return $this->getContainer()->get($service);
}
protected function getParameter($parameter)
{
return $this->getContainer()->getParameter($parameter);
}
protected function loginAs(User $user)
{
$qCodoUser = \User::Load($user->getUserId(), true);
\UserSecurity::Login($qCodoUser, false);
$this->user = $user;
}
protected function loginAsUsername($username)
{
$user = $this->get('user.user_manager')->findUserByUsername($username);
$this->loginAs($user);
}
protected function getUser()
{
return $this->user;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment