mirror of
https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
synced 2024-12-22 23:25:03 +01:00
Added Core and test
This commit is contained in:
parent
d79616c3ae
commit
b11cea5337
73
src/core/Core.php
Normal file
73
src/core/Core.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace core;
|
||||
|
||||
use entity\user\UserInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
final class Core implements CoreInterface
|
||||
{
|
||||
const DATABASE_USERNAME = 'devuser';
|
||||
|
||||
const DATABASE_PASSWORD = 'devpass';
|
||||
|
||||
const DATABASE_NAME = 'test_db';
|
||||
|
||||
const DATABASE_PORT = '3306';
|
||||
|
||||
const DATABASE_HOST = 'codingchallengeonlineshop_db_1';
|
||||
|
||||
/**
|
||||
* @var \Twig_Environment
|
||||
*/
|
||||
private $twig;
|
||||
|
||||
/**
|
||||
* @var UserInterface
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @var \PDO
|
||||
*/
|
||||
private $database;
|
||||
|
||||
public function __construct(){
|
||||
$this->initTwig();
|
||||
$this->initDatabase();
|
||||
}
|
||||
|
||||
private function initTwig():void{
|
||||
$loader = new \Twig_Loader_Filesystem(__DIR__.'/../template');
|
||||
$this->twig = new \Twig_Environment($loader);
|
||||
}
|
||||
|
||||
private function initDatabase():void{
|
||||
$this->database = new \PDO('mysql:host='.self::DATABASE_HOST.';dbname='.self::DATABASE_NAME.';port='.self::DATABASE_PORT, self::DATABASE_USERNAME, self::DATABASE_PASSWORD);
|
||||
}
|
||||
|
||||
public function getDatabase(): \PDO
|
||||
{
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
public function getTwig(): \Twig_Environment
|
||||
{
|
||||
return $this->twig;
|
||||
}
|
||||
|
||||
public function getUser(): ?UserInterface
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function setUser(?UserInterface $user = null): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
}
|
||||
|
21
src/core/CoreInterface.php
Normal file
21
src/core/CoreInterface.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace core;
|
||||
|
||||
use entity\user\UserInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
interface CoreInterface
|
||||
{
|
||||
public function getDatabase():\PDO;
|
||||
|
||||
public function getTwig():\Twig_Environment;
|
||||
|
||||
public function getUser():?UserInterface;
|
||||
|
||||
public function setUser(?UserInterface $user = null):void;
|
||||
}
|
||||
|
44
src/core/CoreTest.php
Normal file
44
src/core/CoreTest.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace core;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use entity\user\User;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
class CoreTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var Core
|
||||
*/
|
||||
protected $core;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
protected function setUp():void{
|
||||
$this->core = new Core();
|
||||
$this->user = new User();
|
||||
$this->core->setUser($this->user);
|
||||
}
|
||||
|
||||
public function testTwig():void{
|
||||
$this->assertInstanceOf(\Twig_Environment::class, $this->core->getTwig());
|
||||
}
|
||||
|
||||
public function testDatabase():void{
|
||||
$this->assertInstanceOf(\PDO::class, $this->core->getDatabase());
|
||||
}
|
||||
|
||||
public function testUser():void{
|
||||
$this->assertEquals($this->user, $this->core->getUser());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user