This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from chesslablab/issue/5-install-and-configure-…
…Doctrine Issue/5 install and configure doctrine
- Loading branch information
Showing
17 changed files
with
251 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,11 @@ | ||
# In all environments, the following files are loaded if they exist, | ||
# the latter taking precedence over the former: | ||
# | ||
# * .env contains default values for the environment variables needed by the app | ||
# * .env.local uncommitted file with local overrides | ||
# * .env.$APP_ENV committed environment-specific defaults | ||
# * .env.$APP_ENV.local uncommitted environment-specific overrides | ||
# | ||
# Real environment variables win over .env files. | ||
# | ||
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES. | ||
# | ||
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2). | ||
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration | ||
|
||
###> symfony/framework-bundle ### | ||
APP_ENV=dev | ||
APP_SECRET=cf517d2e216f2c631fbd7be616bd7fce | ||
###< symfony/framework-bundle ### | ||
|
||
DB_DRIVER=mysql | ||
DB_HOST=localhost | ||
DB_PORT=3306 | ||
DB_DATABASE=chess | ||
DB_USERNAME=root | ||
DB_PASSWORD= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
###> symfony/framework-bundle ### | ||
APP_ENV=dev | ||
APP_SECRET=cf517d2e216f2c631fbd7be616bd7fce | ||
###< symfony/framework-bundle ### | ||
|
||
DB_DRIVER=mysql | ||
DB_HOST=localhost | ||
DB_PORT=3306 | ||
DB_DATABASE=chess | ||
DB_USERNAME=root | ||
DB_PASSWORD= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# define your env variables for the test env here | ||
KERNEL_CLASS='ChessApi\Kernel' | ||
APP_SECRET='$ecretf0rt3st' | ||
SYMFONY_DEPRECATIONS_HELPER=999999 | ||
PANTHER_APP_ENV=panther | ||
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
## Chess API | ||
|
||
A chess REST API. | ||
|
||
### Setup | ||
|
||
Clone the `chesslablab/chess-api` repo into your projects folder as it is described in the following example: | ||
|
||
$ git clone [email protected]:chesslablab/chess-api.git | ||
|
||
Then `cd` the `chess-api` directory and install the Composer dependencies: | ||
|
||
$ composer install | ||
|
||
Create an `.env` file: | ||
|
||
$ cp .env.example .env | ||
|
||
If necessary, update the environment variables in your `.env` file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?php | ||
|
||
if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) { | ||
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php'; | ||
if (file_exists(dirname(__DIR__).'/var/cache/prod/ChessApi_KernelProdContainer.preload.php')) { | ||
require dirname(__DIR__).'/var/cache/prod/ChessApi_KernelProdContainer.preload.php'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
api_play: | ||
path: /api/play | ||
controller: App\Controller\PlayController::index | ||
controller: ChessApi\Controller\PlayController::index | ||
methods: POST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html --> | ||
<phpunit xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
bootstrap="tests/bootstrap.php" | ||
convertDeprecationsToExceptions="false" | ||
> | ||
<php> | ||
<ini name="display_errors" value="1" /> | ||
<ini name="error_reporting" value="-1" /> | ||
<server name="APP_ENV" value="test" force="true" /> | ||
<server name="SHELL_VERBOSITY" value="-1" /> | ||
<server name="SYMFONY_PHPUNIT_REMOVE" value="" /> | ||
<server name="SYMFONY_PHPUNIT_VERSION" value="9.5" /> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="Project Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</coverage> | ||
|
||
<!-- Run `composer require symfony/panther` before enabling this extension --> | ||
<!-- | ||
<extensions> | ||
<extension class="Symfony\Component\Panther\ServerExtension" /> | ||
</extensions> | ||
--> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
use App\Kernel; | ||
use ChessApi\Kernel; | ||
|
||
require_once dirname(__DIR__).'/vendor/autoload_runtime.php'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
namespace ChessApi\Controller; | ||
|
||
use Chess\Player; | ||
use Chess\FEN\BoardToString; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace ChessApi; | ||
|
||
/** | ||
* Pdo class. | ||
*/ | ||
class Pdo | ||
{ | ||
/** | ||
* Pdo instance. | ||
* | ||
* @var \ChessApi\Pdo | ||
*/ | ||
private static $instance; | ||
|
||
/** | ||
* DSN. | ||
* | ||
* @var string | ||
*/ | ||
private $dsn; | ||
|
||
/** | ||
* PDO handler. | ||
* | ||
* @var \PDO | ||
*/ | ||
private $pdo; | ||
|
||
/** | ||
* Returns the current instance. | ||
* | ||
* @param array $conf | ||
* @return \ChessData\Pdo | ||
*/ | ||
public static function getInstance(array $conf) | ||
{ | ||
if (null === static::$instance) { | ||
static::$instance = new static($conf); | ||
} | ||
|
||
return static::$instance; | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param array $conf | ||
*/ | ||
protected function __construct(array $conf) | ||
{ | ||
$this->dsn = $conf['driver'] . ':host=' . $conf['host'] . ';dbname=' . $conf['database']; | ||
|
||
$this->pdo = new \PDO( | ||
$this->dsn, | ||
$conf['username'], | ||
$conf['password'] | ||
); | ||
|
||
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); | ||
} | ||
|
||
/** | ||
* Prevents from cloning. | ||
*/ | ||
private function __clone() | ||
{ | ||
} | ||
|
||
/** | ||
* Prevents from unserializing. | ||
*/ | ||
public function __wakeup() | ||
{ | ||
} | ||
|
||
/** | ||
* Queries the database. | ||
* | ||
* @param string | ||
* @param array | ||
* @return bool | ||
*/ | ||
public function query($sql, $values = []) | ||
{ | ||
$stmt = $this->pdo->prepare($sql); | ||
|
||
foreach ($values as $value) { | ||
$stmt->bindValue( | ||
$value['param'], | ||
$value['value'], | ||
$value['type'] ?? null | ||
); | ||
} | ||
|
||
$stmt->execute(); | ||
|
||
return $stmt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
use Symfony\Component\Dotenv\Dotenv; | ||
|
||
require dirname(__DIR__).'/vendor/autoload.php'; | ||
|
||
if (file_exists(dirname(__DIR__).'/config/bootstrap.php')) { | ||
require dirname(__DIR__).'/config/bootstrap.php'; | ||
} elseif (method_exists(Dotenv::class, 'bootEnv')) { | ||
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace ChessApi\Tests\Integration; | ||
|
||
use ChessApi\Pdo; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DatabaseTest extends TestCase | ||
{ | ||
public static $pdo; | ||
|
||
public static function setUpBeforeClass(): void | ||
{ | ||
$conf = [ | ||
'driver' => $_ENV['DB_DRIVER'], | ||
'host' => $_ENV['DB_HOST'], | ||
'database' => $_ENV['DB_DATABASE'], | ||
'username' => $_ENV['DB_USERNAME'], | ||
'password' => $_ENV['DB_PASSWORD'], | ||
]; | ||
|
||
self::$pdo = Pdo::getInstance($conf); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function count_all() | ||
{ | ||
$sql = 'SELECT * FROM games'; | ||
$result = self::$pdo->query($sql)->fetchAll(); | ||
$expected = 402976; | ||
|
||
$this->assertEquals($expected, count($result)); | ||
} | ||
} |