Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Wagner committed Jan 30, 2018
1 parent c0bd329 commit b540121
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"heimrichhannot/contao-submissions_creator": "^1.1",
"heimrichhannot/contao-list-bundle": "dev-master",
"heimrichhannot/contao-filter-bundle": "dev-master",
"heimrichhannot/contao-utils-bundle": "dev-master"
"heimrichhannot/contao-utils-bundle": "dev-master",
"heimrichhannot/contao-haste_plus": "^1.8"
},
"require-dev": {
"contao/test-case": "^1.1",
Expand Down
20 changes: 14 additions & 6 deletions tests/TokenManager/TokenManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Firebase\JWT\JWT;
use HeimrichHannot\QuizBundle\Manager\TokenManager;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Routing\RouterInterface;

class TokenManagerTest extends ContaoTestCase
Expand All @@ -35,23 +36,21 @@ public function setUp(): void

$router = $this->createRouterMock();
$requestStack = $this->createRequestStackMock();
$framework = $this->mockContaoFramework($this->createMockAdapater());
$framework = $this->mockContaoFramework($this->createMockAdapter());

$database = $this->createMock(Connection::class);
$container = $this->mockContainer();
$container->set('kernel', $this->createMock(ContaoKernel::class));
$container->setParameter('secret', Config::class);
$container->set('request_stack', $requestStack);
$container->set('router', $router);
$container->set('session', new Session());
$container->set('contao.framework', $framework);
$container->set('database_connection', $database);
System::setContainer($container);
}

/**
* @return array
*/
public function testAddDataToJwtToken()
public function testGetDataFromJwtToken()
{
$tokenManager = new TokenManager();
$encode = JWT::encode(['id' => 12], System::getContainer()->getParameter('secret'));
Expand All @@ -60,6 +59,15 @@ public function testAddDataToJwtToken()
$this->assertSame(12, $token->id);
}

public function testAddDataToJwtToken()
{
$tokenManager = new TokenManager();
$encode = JWT::encode(['session' => ''], System::getContainer()->getParameter('secret'));
$token = $tokenManager->addDataToJwtToken($encode, 12, 'id');

$this->assertNotEmpty($token);
}

public function createRouterMock()
{
$router = $this->createMock(RouterInterface::class);
Expand Down Expand Up @@ -90,7 +98,7 @@ public function createRequestStackMock()
return $requestStack;
}

public function createMockAdapater()
public function createMockAdapter()
{
$modelAdapter = $this->mockAdapter(['__construct']);

Expand Down

0 comments on commit b540121

Please sign in to comment.