From b11cea5337a13452c9090f1836f0817d2ccad813 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sat, 14 Jul 2018 16:52:17 +0200 Subject: [PATCH] Added Core and test --- src/core/Core.php | 73 ++++++++++++++++++++++++++++++++++++++ src/core/CoreInterface.php | 21 +++++++++++ src/core/CoreTest.php | 44 +++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 src/core/Core.php create mode 100644 src/core/CoreInterface.php create mode 100644 src/core/CoreTest.php diff --git a/src/core/Core.php b/src/core/Core.php new file mode 100644 index 0000000..b83e952 --- /dev/null +++ b/src/core/Core.php @@ -0,0 +1,73 @@ +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; + } + +} + diff --git a/src/core/CoreInterface.php b/src/core/CoreInterface.php new file mode 100644 index 0000000..30b14f8 --- /dev/null +++ b/src/core/CoreInterface.php @@ -0,0 +1,21 @@ +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()); + } +} +