Skip to content

Commit

Permalink
Merge pull request #28 from studoo-app/develop
Browse files Browse the repository at this point in the history
v0.1.3
  • Loading branch information
bfoujols authored Apr 14, 2023
2 parents 6cc5568 + 32a54ae commit b584d22
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:
- name: Install dependencies
run: composer self-update && composer install && composer dump-autoload

- name: Install & run API
run: |
git clone https://github.com/studoo-app/mock-ecole-directe-api.git
cd mock-ecole-directe-api && composer install && php -S localhost:9042 -t api &
- name: Run tests and collect coverage
run: vendor/bin/phpunit --coverage-clover clover.xml

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/testing-php81.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ jobs:
- name: Install dependencies
run: composer self-update && composer install && composer dump-autoload

- name: Install & run API
run: |
git clone https://github.com/studoo-app/mock-ecole-directe-api.git
cd mock-ecole-directe-api && composer install && php -S localhost:9042 -t api &
- name: Run tests and collect coverage
run: vendor/bin/phpunit
5 changes: 5 additions & 0 deletions .github/workflows/testing-php82.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ jobs:
- name: Install dependencies
run: composer self-update && composer install && composer dump-autoload

- name: Install & run API
run: |
git clone https://github.com/studoo-app/mock-ecole-directe-api.git
cd mock-ecole-directe-api && composer install && php -S localhost:9042 -t api &
- name: Run tests and collect coverage
run: vendor/bin/phpunit
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
CHANGELOG
=========
# CHANGELOG

0.1.3
---

* Add Mock API Ecole Directe


0.1.2
---

* Fix SSL certificate problem #24

0.1.1
---

* Code Style
* Code Coverage

0.1.0
---
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: "3.8"
services:
mock-ecole-directe-api:
container_name: mock-ecole-directe-api
image: bfoujols/mock-api-ecole-directe
ports:
- "9042:80"
restart: always
6 changes: 6 additions & 0 deletions examples/exampleForDotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
use Studoo\Api\EcoleDirecte\Client;
use Symfony\Component\Dotenv\Dotenv;

/**
* Mise en place de l'environnement de développement via DotEnv
* via le fichier .env à la racine du projet
* Renseigner les variables CLIENT_ID, CLIENT_SECRET
*/

$dotenv = new Dotenv();
$dotenv->loadEnv(__DIR__ . '/../.env');

Expand Down
42 changes: 42 additions & 0 deletions examples/exampleForDotenvDocker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';

use Studoo\Api\EcoleDirecte\Client;
use Symfony\Component\Dotenv\Dotenv;

/**
* Mise en place de l'environnement de développement via DotEnv
* via le fichier .env à la racine du projet
* Renseigner les variables ENV
* Pour faire fonctionner le Docker, il faut renseigner ENV=test
* Dans la classe Client, il faut renseigner le base_path "http://localhost:9042" (adresse du serveur Docker)
* Voir https://github.com/studoo-app/mock-ecole-directe-api
*/

$dotenv = new Dotenv();
$dotenv->loadEnv(__DIR__ . '/../.env');

if (isset($_POST['username']) && isset($_POST['password'])) {
$client = new Client([
"base_path" => "http://localhost:9042",
"client_id" => $_POST['username'],
"client_secret" => $_POST['password'],
]);
// Recupération du token et profile
$etudiant = $client->fetchAccessToken();
echo "Token: {$etudiant->getToken()} <br>";
echo "Email: {$etudiant->getEmail()} <br>";
echo "Nom: {$etudiant->getNom()} <br>";
echo "Prenom: {$etudiant->getPrenom()} <br>";
echo "Identifiant: {$etudiant->getIdentifiant()} <br>";
} else {
echo "<h1>API ECOLE DIRECTE via Form</h1>";
echo "<form method='post'>";
echo "<label for='username'> Username </label>";
echo "<input type='text' name='username' id='username' required>";
echo "<label for='password'> Password </label>";
echo "<input type='password' name='password' id='password' required>";
echo "<input type='submit' value='Envoyer'>";
echo "</form>";
}
1 change: 1 addition & 0 deletions examples/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

echo "<h1>API ECOLE DIRECTE</h1>";
echo "<a href='exampleForDotenv.php'>Exemple avec un fichier DotEnv (.env)</a><br>";
echo "<a href='exampleForDotenvDocker.php'>Exemple avec un formulaire via le mock API Docker</a><br>";
echo "<a href='exampleForForm.php'>Exemple avec un formulaire</a><br>";
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class Client
{
private const LIBVER = '0.1.0';
private const LIBVER = '0.1.3';

private const API_BASE_PATH = 'https://apip.ecoledirecte.com';

Expand Down
2 changes: 1 addition & 1 deletion src/Query/LoginQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LoginQuery extends Query implements EntityQueryInterface
public function __construct()
{
$this->methode = 'POST';
$this->path = 'login.awp';
$this->path = isset($_ENV["ENV"]) && $_ENV["ENV"] === "test" ? 'login' : 'login.awp';
$this->query = [
'identifiant' => '',
'motdepasse' => ''
Expand Down
23 changes: 23 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Studoo\Api\EcoleDirecte\Client;
use PHPUnit\Framework\TestCase;

class ClientTest extends TestCase
{

/**
* @throws \Studoo\Api\EcoleDirecte\Exception\InvalidModelException
*/
public function testFetchAccessToken()
{
$_ENV["ENV"] = "test";

$client = new Client([
"base_path" => "http://localhost:9042",
"client_id" => "jeremy",
"client_secret" => "test",
]);
$this->assertEquals('7654-5678-43345-80R8-54324', $client->fetchAccessToken()->getToken());
}
}
21 changes: 0 additions & 21 deletions tests/Entity/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,13 @@ public function testSetIdLogin()
$this->assertEquals('345', $login->getIdLogin());
}

public function testGetIdLogin()
{
$login = new Login();
$login->setIdLogin('345');
$this->assertEquals('345', $login->getIdLogin());
}

public function testGetId()
{
$login = new Login();
$login->setId('345');
$this->assertEquals('345', $login->getId());
}

public function testSetId()
{
$login = new Login();
$login->setId('345');
$this->assertEquals('345', $login->getId());
}

public function testGetUid()
{
$login = new Login();
$login->setUid('345');
$this->assertEquals('345', $login->getUid());
}

public function testSetUid()
{
$login = new Login();
Expand Down
1 change: 1 addition & 0 deletions tests/Query/LoginQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class LoginQueryTest extends TestCase

public function setUp(): void
{
$_ENV["ENV"] = "";
$this->loginQuery = new LoginQuery();
$this->jsonContent = json_decode(
file_get_contents(__DIR__ . '/../Data/loginV3TypeP.json'),
Expand Down

0 comments on commit b584d22

Please sign in to comment.