Skip to content

Instantly share code, notes, and snippets.

View Adroit11's full-sized avatar
🏠
Working from home

Ogundiji Bolade Adroit11

🏠
Working from home
View GitHub Profile
@Adroit11
Adroit11 / composer.json
Created January 19, 2019 12:13
mini library app demo snippet for my TDD in Slim framework blog post
{
"name": "your name",
"description":"a simple mini library demo app"
}
@Adroit11
Adroit11 / index.php
Created January 19, 2019 12:33
TDD in Slim Framework mini library demo
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
$app = new \Slim\App();
$app->get('/', function (Request $request, Response $response) {
$response->withStatus(200)->write("Welcome to the Adroit Library Demo.");
return $response;
});
@Adroit11
Adroit11 / composer.json
Created January 19, 2019 13:45
updated compose file
{
"name": "your name",
"description":"a simple mini library demo app",
"require": {
"slim/slim": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^7"
}
}
@Adroit11
Adroit11 / LibraryTestCase.php
Created January 19, 2019 13:58
The test file
<?php
use PHPUnit\Framework\TestCase;
class LibraryTestCase extends TestCase
{
public function testLibraryGet() {
$this->assertTrue(true);
}
}
@Adroit11
Adroit11 / index.php
Last active January 19, 2019 14:15
updated inde.php file
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
$app = new \Slim\App();
function availableLibraryId($id) {
return (int)$id && $id > 0 && $id <= 5;
@Adroit11
Adroit11 / libraryRoute.php
Last active January 19, 2019 20:20
libraryRoute.php file
<?php
namespace Library\App;
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
class LibraryRoute
{
/**
* Stores an instance of the Slim application.
*
* @var \Slim\App
@Adroit11
Adroit11 / composer.json
Created January 19, 2019 14:42
updated for composer dump-autoload
{
"name": "your name",
"description":"a simple mini library demo app",
"require": {
"slim/slim": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^7"
},
"autoload": {
@Adroit11
Adroit11 / index.php
Last active January 19, 2019 14:46
Updated index.php
<?php
require '../vendor/autoload.php';
// Run app
$app = (new Library\App\LibraryRoute())->get();
$app->run();
@Adroit11
Adroit11 / libraryTestCase.php
Last active January 19, 2019 15:17
updated libraryTestCase file
<?php
use Library\App\LibraryRoute;
use Slim\Http\Environment;
use Slim\Http\Request;
use PHPUnit\Framework\TestCase;
class LibraryTestCase extends TestCase
{
protected $app;
public function setUp()
@Adroit11
Adroit11 / libraryTestCase.php
Created January 19, 2019 15:19
updated library testcase to get all libraries
<?php
use Library\App\LibraryRoute;
use Slim\Http\Environment;
use Slim\Http\Request;
use PHPUnit\Framework\TestCase;
class LibraryTestCase extends TestCase
{
protected $app;
public function setUp()