You've already forked Php-Template
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
54ea22c49a
|
|||
|
f8d3462cb7
|
|||
|
68614958a9
|
|||
|
413145f479
|
|||
|
d2bd9d2d1b
|
@@ -1,3 +1,5 @@
|
|||||||
.idea/
|
.idea/
|
||||||
|
.DS_Store
|
||||||
vendor/
|
vendor/
|
||||||
.phpunit.cache/
|
.phpunit.cache/
|
||||||
|
tests/
|
||||||
@@ -246,10 +246,23 @@ jobs:
|
|||||||
siteworxpro/composer \
|
siteworxpro/composer \
|
||||||
install --ignore-platform-reqs --no-interaction --prefer-dist --optimize-autoloader
|
install --ignore-platform-reqs --no-interaction --prefer-dist --optimize-autoloader
|
||||||
|
|
||||||
- name: Run Unit Tests
|
- name: 🧪 ✅ Run Unit Tests
|
||||||
run: |
|
uses: addnab/docker-run-action@v3
|
||||||
docker run --rm \
|
with:
|
||||||
--volumes-from ${{ env.JOB_CONTAINER_NAME }} \
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
-w ${{ github.workspace }} \
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
siteworxpro/composer \
|
image: siteworxpro/composer
|
||||||
run tests:unit
|
options: --volumes-from ${{ env.JOB_CONTAINER_NAME }} -w ${{ gitea.workspace }}
|
||||||
|
run: |
|
||||||
|
bin/pcov.sh
|
||||||
|
composer run tests:unit:coverage
|
||||||
|
|
||||||
|
# - name: 📦 Publish Build Artifacts
|
||||||
|
# env:
|
||||||
|
# NODE_TLS_REJECT_UNAUTHORIZED: 0
|
||||||
|
# uses: christopherhx/gitea-upload-artifact@v4
|
||||||
|
# with:
|
||||||
|
# options: --volumes-from ${{ env.JOB_CONTAINER_NAME }} -w ${{ gitea.workspace }}
|
||||||
|
# name: junit-coverage.xml
|
||||||
|
# path: tests/reports/junit.xml
|
||||||
|
# retention-days: 1
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,6 @@
|
|||||||
.idea/
|
.idea/
|
||||||
|
.DS_Store
|
||||||
vendor/
|
vendor/
|
||||||
.phpunit.cache/
|
.phpunit.cache/
|
||||||
|
|
||||||
|
tests/reports/
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
include:
|
|
||||||
- local: .gitlab/ci/stages.yml
|
|
||||||
- local: .gitlab/ci/tests.yml
|
|
||||||
- local: .gitlab/ci/libraries.yml
|
|
||||||
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
Install Composer Libraries:
|
|
||||||
stage: libraries
|
|
||||||
image: siteworxpro/composer:latest
|
|
||||||
rules:
|
|
||||||
- if: '$CI_COMMIT_TAG'
|
|
||||||
when: never
|
|
||||||
- if: '$CI_PIPELINE_SOURCE == "push"'
|
|
||||||
when: always
|
|
||||||
- when: never
|
|
||||||
script:
|
|
||||||
- composer install --ignore-platform-reqs
|
|
||||||
artifacts:
|
|
||||||
paths:
|
|
||||||
- vendor/
|
|
||||||
expire_in: 1 hour
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
stages:
|
|
||||||
- libraries
|
|
||||||
- tests
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
Unit Tests:
|
|
||||||
stage: tests
|
|
||||||
needs:
|
|
||||||
- Install Composer Libraries
|
|
||||||
rules:
|
|
||||||
- if: '$CI_COMMIT_TAG'
|
|
||||||
when: never
|
|
||||||
- if: '$CI_PIPELINE_SOURCE == "push"'
|
|
||||||
when: always
|
|
||||||
- when: never
|
|
||||||
image: siteworxpro/composer
|
|
||||||
before_script: |
|
|
||||||
bin/pcov.sh
|
|
||||||
script: |
|
|
||||||
echo "Running unit tests..."
|
|
||||||
composer run tests:unit:coverage
|
|
||||||
coverage: '/^\s*Lines:\s*\d+.\d+\%/'
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 day
|
|
||||||
reports:
|
|
||||||
junit: tests/reports/junit.xml
|
|
||||||
paths:
|
|
||||||
- tests/reports/
|
|
||||||
|
|
||||||
Run License Check:
|
|
||||||
stage: tests
|
|
||||||
needs:
|
|
||||||
- Install Composer Libraries
|
|
||||||
rules:
|
|
||||||
- if: '$CI_COMMIT_TAG'
|
|
||||||
when: never
|
|
||||||
- if: '$CI_PIPELINE_SOURCE == "push"'
|
|
||||||
when: on_success
|
|
||||||
- when: never
|
|
||||||
image: siteworxpro/composer
|
|
||||||
script:
|
|
||||||
- composer run tests:license
|
|
||||||
|
|
||||||
Run Code Lint:
|
|
||||||
stage: tests
|
|
||||||
needs:
|
|
||||||
- Install Composer Libraries
|
|
||||||
rules:
|
|
||||||
- if: '$CI_COMMIT_TAG'
|
|
||||||
when: never
|
|
||||||
- if: '$CI_PIPELINE_SOURCE == "push"'
|
|
||||||
when: on_success
|
|
||||||
- when: never
|
|
||||||
image: siteworxpro/composer
|
|
||||||
script:
|
|
||||||
- composer run tests:lint
|
|
||||||
|
|
||||||
Run Code Sniffer:
|
|
||||||
stage: tests
|
|
||||||
needs:
|
|
||||||
- Install Composer Libraries
|
|
||||||
rules:
|
|
||||||
- if: '$CI_COMMIT_TAG'
|
|
||||||
when: never
|
|
||||||
- if: '$CI_PIPELINE_SOURCE == "push"'
|
|
||||||
when: on_success
|
|
||||||
- when: never
|
|
||||||
image: siteworxpro/composer
|
|
||||||
script:
|
|
||||||
- composer run tests:phpstan
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# Use the RoadRunner image as a base for the first stage
|
# Use the RoadRunner image as a base for the first stage
|
||||||
FROM ghcr.io/roadrunner-server/roadrunner:2025.1.1 AS roadrunner
|
FROM ghcr.io/roadrunner-server/roadrunner:2025.1.4 AS roadrunner
|
||||||
|
|
||||||
# Use the official Composer image as the base for the library stage
|
# Use the official Composer image as the base for the library stage
|
||||||
FROM siteworxpro/composer AS library
|
FROM siteworxpro/composer AS library
|
||||||
@@ -12,7 +12,7 @@ RUN composer install --optimize-autoloader --ignore-platform-reqs --no-dev
|
|||||||
|
|
||||||
|
|
||||||
# Use the official PHP CLI image with Alpine Linux for the second stage
|
# Use the official PHP CLI image with Alpine Linux for the second stage
|
||||||
FROM php:8.4.6-alpine AS php
|
FROM php:8.4.14-alpine AS php
|
||||||
|
|
||||||
# Move the production PHP configuration file to the default location
|
# Move the production PHP configuration file to the default location
|
||||||
RUN mv /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini \
|
RUN mv /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini \
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ You can access the api at `http://localhost:9501/`
|
|||||||
|
|
||||||
xdebug needs to be built into the container before it will work
|
xdebug needs to be built into the container before it will work
|
||||||
```shell
|
```shell
|
||||||
docker exec -it template-runtime-1 bin/xdebug.sh
|
docker exec -it php-template-composer-runtime-1 bin/xdebug.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install the dependencies
|
### Install the dependencies
|
||||||
|
|||||||
4
bin/migrate.sh
Executable file
4
bin/migrate.sh
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
eval #!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
migrate -path /app/db/migrations -database "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_DATABASE?sslmode=disable" up
|
||||||
11
config.php
11
config.php
@@ -8,7 +8,7 @@ return [
|
|||||||
* The server configuration.
|
* The server configuration.
|
||||||
*/
|
*/
|
||||||
'server' => [
|
'server' => [
|
||||||
'port' => Env::get('HTTP_PORT', 9501, 'int'),
|
'port' => Env::get('HTTP_PORT', 9501, 'int'),
|
||||||
'dev_mode' => Env::get('DEV_MODE', false, 'bool'),
|
'dev_mode' => Env::get('DEV_MODE', false, 'bool'),
|
||||||
],
|
],
|
||||||
|
|
||||||
@@ -21,9 +21,15 @@ return [
|
|||||||
'database' => Env::get('DB_DATABASE', 'siteworxpro'),
|
'database' => Env::get('DB_DATABASE', 'siteworxpro'),
|
||||||
'username' => Env::get('DB_USERNAME', 'siteworxpro'),
|
'username' => Env::get('DB_USERNAME', 'siteworxpro'),
|
||||||
'password' => Env::get('DB_PASSWORD', 'password'),
|
'password' => Env::get('DB_PASSWORD', 'password'),
|
||||||
|
'port' => Env::get('DB_PORT', 5432, 'int'),
|
||||||
|
'charset' => Env::get('DB_CHARSET', 'utf8'),
|
||||||
|
'collation' => Env::get('DB_COLLATION', 'utf8_unicode_ci'),
|
||||||
|
'prefix' => Env::get('DB_PREFIX', ''),
|
||||||
|
'options' => [
|
||||||
|
// Add any additional PDO options here
|
||||||
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
||||||
'cors' => [
|
'cors' => [
|
||||||
'allowed_origins' => Env::get('CORS_ALLOWED_ORIGINS', 'localhost:3000'),
|
'allowed_origins' => Env::get('CORS_ALLOWED_ORIGINS', 'localhost:3000'),
|
||||||
'allow_credentials' => Env::get('CORS_ALLOW_CREDENTIALS', true, 'bool'),
|
'allow_credentials' => Env::get('CORS_ALLOW_CREDENTIALS', true, 'bool'),
|
||||||
@@ -34,5 +40,6 @@ return [
|
|||||||
'host' => Env::get('REDIS_HOST', 'localhost'),
|
'host' => Env::get('REDIS_HOST', 'localhost'),
|
||||||
'port' => Env::get('REDIS_PORT', 6379, 'int'),
|
'port' => Env::get('REDIS_PORT', 6379, 'int'),
|
||||||
'database' => Env::get('REDIS_DATABASE', 0, 'int'),
|
'database' => Env::get('REDIS_DATABASE', 0, 'int'),
|
||||||
|
'password' => Env::get('REDIS_PASSWORD'),
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
@@ -12,6 +12,24 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
PHP_IDE_CONFIG: serverName=localhost
|
PHP_IDE_CONFIG: serverName=localhost
|
||||||
|
|
||||||
|
migration-container:
|
||||||
|
volumes:
|
||||||
|
- ./db/migrations:/app/db/migrations
|
||||||
|
- ./bin:/app/bin
|
||||||
|
image: siteworxpro/migrate:v4.18.3
|
||||||
|
working_dir: /app
|
||||||
|
# entrypoint: "/bin/sh -c 'while true; do sleep 30; done;'"
|
||||||
|
entrypoint: /bin/sh -c '/app/bin/migrate.sh'
|
||||||
|
depends_on:
|
||||||
|
postgres:
|
||||||
|
condition: service_healthy
|
||||||
|
environment:
|
||||||
|
DB_USERNAME: ${DB_USERNAME:-siteworxpro}
|
||||||
|
DB_PASSWORD: ${DB_PASSWORD:-password}
|
||||||
|
DB_DATABASE: ${DB_DATABASE:-siteworxpro}
|
||||||
|
DB_HOST: ${DB_HOST-postgres}
|
||||||
|
DB_PORT: ${DB_PORT-5432}
|
||||||
|
|
||||||
dev-runtime:
|
dev-runtime:
|
||||||
ports:
|
ports:
|
||||||
- "9501:9501"
|
- "9501:9501"
|
||||||
@@ -29,6 +47,11 @@ services:
|
|||||||
|
|
||||||
redis:
|
redis:
|
||||||
image: redis:latest
|
image: redis:latest
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "redis-cli", "ping"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
ports:
|
ports:
|
||||||
- "6379:6379"
|
- "6379:6379"
|
||||||
volumes:
|
volumes:
|
||||||
@@ -36,6 +59,11 @@ services:
|
|||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:latest
|
image: postgres:latest
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME:-siteworxpro}"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: ${DB_USERNAME:-siteworxpro}
|
POSTGRES_USER: ${DB_USERNAME:-siteworxpro}
|
||||||
POSTGRES_PASSWORD: ${DB_PASSWORD:-password}
|
POSTGRES_PASSWORD: ${DB_PASSWORD:-password}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
FROM siteworxpro/migrate:v4.18.3
|
FROM siteworxpro/migrate:v4.18.3
|
||||||
|
|
||||||
ADD db/migrations /app/db/migrations
|
ADD db/migrations /app/db/migrations
|
||||||
|
ADD bin/migrate.sh /app/bin/migrate.sh
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENTRYPOINT ["/app/bin/migrate.sh"]
|
||||||
|
|||||||
@@ -28,6 +28,14 @@ abstract class Controller implements ControllerInterface
|
|||||||
throw new NotFoundException("not found");
|
throw new NotFoundException("not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws NotFoundException
|
||||||
|
*/
|
||||||
|
public function put(ServerRequest $request): ResponseInterface
|
||||||
|
{
|
||||||
|
throw new NotFoundException("not found");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws NotFoundException
|
* @throws NotFoundException
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ interface ControllerInterface
|
|||||||
*/
|
*/
|
||||||
public function post(ServerRequest $request): ResponseInterface;
|
public function post(ServerRequest $request): ResponseInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the request and return a response.
|
||||||
|
*
|
||||||
|
* @param ServerRequest $request The request data.
|
||||||
|
* @return ResponseInterface The response data.
|
||||||
|
*/
|
||||||
|
public function put(ServerRequest $request): ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the request and return a response.
|
* Handle the request and return a response.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -6,6 +6,12 @@ namespace Siteworxpro\App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model as ORM;
|
use Illuminate\Database\Eloquent\Model as ORM;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Model
|
||||||
|
*
|
||||||
|
* @package Siteworxpro\App\Models
|
||||||
|
*/
|
||||||
abstract class Model extends ORM
|
abstract class Model extends ORM
|
||||||
{
|
{
|
||||||
|
protected $dateFormat = 'Y-m-d H:i:s';
|
||||||
}
|
}
|
||||||
|
|||||||
52
src/Models/User.php
Normal file
52
src/Models/User.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Siteworxpro\App\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class User
|
||||||
|
*
|
||||||
|
* @property string $id
|
||||||
|
* @property string $first_name
|
||||||
|
* @property string $last_name
|
||||||
|
* @property string $email
|
||||||
|
* @property string $password
|
||||||
|
* @property Carbon $created_at
|
||||||
|
*
|
||||||
|
* @property-read string $full_name
|
||||||
|
* @property-read string $formatted_email
|
||||||
|
*/
|
||||||
|
class User extends Model
|
||||||
|
{
|
||||||
|
protected $casts = [
|
||||||
|
'created_at' => 'datetime',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $hidden = [
|
||||||
|
'password',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'first_name',
|
||||||
|
'last_name',
|
||||||
|
'email',
|
||||||
|
'password',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function getFullNameAttribute(): string
|
||||||
|
{
|
||||||
|
return "$this->first_name $this->last_name";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFormattedEmailAttribute(): string
|
||||||
|
{
|
||||||
|
return sprintf(
|
||||||
|
'%s <%s>',
|
||||||
|
$this->getFullNameAttribute(),
|
||||||
|
strtolower($this->email)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Siteworxpro\App;
|
namespace Siteworxpro\App;
|
||||||
|
|
||||||
use Illuminate\Container\Container;
|
use Illuminate\Container\Container;
|
||||||
|
use Illuminate\Database\Capsule\Manager;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use League\Route\Http\Exception\MethodNotAllowedException;
|
use League\Route\Http\Exception\MethodNotAllowedException;
|
||||||
use League\Route\Http\Exception\NotFoundException;
|
use League\Route\Http\Exception\NotFoundException;
|
||||||
@@ -120,18 +121,8 @@ class Server
|
|||||||
*/
|
*/
|
||||||
public function bootModelCapsule(): void
|
public function bootModelCapsule(): void
|
||||||
{
|
{
|
||||||
$capsule = new \Illuminate\Database\Capsule\Manager();
|
$capsule = new Manager();
|
||||||
$capsule->addConnection([
|
$capsule->addConnection(Config::get('db'));
|
||||||
'driver' => Config::get('db.driver'),
|
|
||||||
'host' => Config::get('db.host'),
|
|
||||||
'database' => Config::get('db.database'),
|
|
||||||
'username' => Config::get('db.username'),
|
|
||||||
'password' => Config::get('db.password'),
|
|
||||||
'charset' => 'utf8',
|
|
||||||
'collation' => 'utf8_unicode_ci',
|
|
||||||
'prefix' => '',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$capsule->setAsGlobal();
|
$capsule->setAsGlobal();
|
||||||
$capsule->bootEloquent();
|
$capsule->bootEloquent();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -278,10 +278,10 @@ class Facade
|
|||||||
/**
|
/**
|
||||||
* Set the application instance.
|
* Set the application instance.
|
||||||
*
|
*
|
||||||
* @param Container $container
|
* @param Container | null $container
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function setFacadeContainer(Container $container): void
|
public static function setFacadeContainer(Container | null $container): void
|
||||||
{
|
{
|
||||||
static::$container = $container;
|
static::$container = $container;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class RedisServiceProvider extends ServiceProvider
|
|||||||
'host' => Config::get('redis.host'),
|
'host' => Config::get('redis.host'),
|
||||||
'port' => Config::get('redis.port'),
|
'port' => Config::get('redis.port'),
|
||||||
'database' => Config::get('redis.database'),
|
'database' => Config::get('redis.database'),
|
||||||
|
'password' => Config::get('redis.password'),
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
16
tests/Controllers/AbstractController.php
Normal file
16
tests/Controllers/AbstractController.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Siteworxpro\Tests\Controllers;
|
||||||
|
|
||||||
|
use Nyholm\Psr7\ServerRequest;
|
||||||
|
use Siteworxpro\Tests\Unit;
|
||||||
|
|
||||||
|
abstract class AbstractController extends Unit
|
||||||
|
{
|
||||||
|
protected function getMockRequest(string $method = 'GET', string $uri = '/'): ServerRequest
|
||||||
|
{
|
||||||
|
return new ServerRequest($method, $uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
54
tests/Controllers/ControllerTest.php
Normal file
54
tests/Controllers/ControllerTest.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Siteworxpro\Tests\Controllers;
|
||||||
|
|
||||||
|
use Siteworxpro\App\Controllers\Controller;
|
||||||
|
|
||||||
|
class ControllerTest extends AbstractController
|
||||||
|
{
|
||||||
|
public function testNotFoundExceptions()
|
||||||
|
{
|
||||||
|
$testClass = new TestClass();
|
||||||
|
|
||||||
|
$this->expectException(\League\Route\Http\Exception\NotFoundException::class);
|
||||||
|
$testClass->get($this->getMockRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotFoundExceptionPost()
|
||||||
|
{
|
||||||
|
$testClass = new TestClass();
|
||||||
|
|
||||||
|
$this->expectException(\League\Route\Http\Exception\NotFoundException::class);
|
||||||
|
$testClass->post($this->getMockRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotFoundExceptionPut()
|
||||||
|
{
|
||||||
|
$testClass = new TestClass();
|
||||||
|
|
||||||
|
$this->expectException(\League\Route\Http\Exception\NotFoundException::class);
|
||||||
|
$testClass->put($this->getMockRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotFoundExceptionDelete()
|
||||||
|
{
|
||||||
|
$testClass = new TestClass();
|
||||||
|
|
||||||
|
$this->expectException(\League\Route\Http\Exception\NotFoundException::class);
|
||||||
|
$testClass->delete($this->getMockRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotFoundExceptionPatch()
|
||||||
|
{
|
||||||
|
$testClass = new TestClass();
|
||||||
|
|
||||||
|
$this->expectException(\League\Route\Http\Exception\NotFoundException::class);
|
||||||
|
$testClass->patch($this->getMockRequest());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestClass extends Controller // phpcs:ignore
|
||||||
|
{
|
||||||
|
}
|
||||||
25
tests/Controllers/IndexControllerTest.php
Normal file
25
tests/Controllers/IndexControllerTest.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Siteworxpro\Tests\Controllers;
|
||||||
|
|
||||||
|
use Siteworxpro\App\Controllers\IndexController;
|
||||||
|
|
||||||
|
class IndexControllerTest extends AbstractController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws \JsonException
|
||||||
|
*/
|
||||||
|
public function testGet(): void
|
||||||
|
{
|
||||||
|
$this->assertTrue(true);
|
||||||
|
|
||||||
|
$controller = new IndexController();
|
||||||
|
|
||||||
|
$response = $controller->get($this->getMockRequest());
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
$this->assertEquals('{"status_code":200,"message":"Server is running"}', (string)$response->getBody());
|
||||||
|
}
|
||||||
|
}
|
||||||
32
tests/Facades/AbstractFacade.php
Normal file
32
tests/Facades/AbstractFacade.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Siteworxpro\Tests\Facades;
|
||||||
|
|
||||||
|
use Siteworxpro\App\Services\Facade;
|
||||||
|
use Siteworxpro\Tests\Unit;
|
||||||
|
|
||||||
|
abstract class AbstractFacade extends Unit
|
||||||
|
{
|
||||||
|
abstract protected function getFacadeClass(): string;
|
||||||
|
abstract protected function getConcrete(): string;
|
||||||
|
|
||||||
|
public function testFacadeAccessor(): void
|
||||||
|
{
|
||||||
|
/** @var Facade | string $class */
|
||||||
|
$class = $this->getFacadeClass();
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
method_exists($class, 'getFacadeAccessor'),
|
||||||
|
sprintf('The class %s must implement the method getFacadeAccessor.', $class)
|
||||||
|
);
|
||||||
|
|
||||||
|
$facade = $class::getFacadeRoot();
|
||||||
|
|
||||||
|
$this->assertNotNull(
|
||||||
|
$facade,
|
||||||
|
sprintf('The facade %s is not properly initialized.', $this->getConcrete())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
21
tests/Facades/RedisTest.php
Normal file
21
tests/Facades/RedisTest.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Siteworxpro\Tests\Facades;
|
||||||
|
|
||||||
|
use Predis\Client;
|
||||||
|
use Siteworxpro\App\Services\Facades\Redis;
|
||||||
|
|
||||||
|
class RedisTest extends AbstractFacade
|
||||||
|
{
|
||||||
|
protected function getFacadeClass(): string
|
||||||
|
{
|
||||||
|
return Redis::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getConcrete(): string
|
||||||
|
{
|
||||||
|
return Client::class;
|
||||||
|
}
|
||||||
|
}
|
||||||
43
tests/ServiceProviders/AbstractServiceProvider.php
Normal file
43
tests/ServiceProviders/AbstractServiceProvider.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Siteworxpro\Tests\ServiceProviders;
|
||||||
|
|
||||||
|
use Illuminate\Container\Container;
|
||||||
|
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Siteworxpro\Tests\Unit;
|
||||||
|
|
||||||
|
abstract class AbstractServiceProvider extends Unit
|
||||||
|
{
|
||||||
|
abstract protected function getProviderClass(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws BindingResolutionException
|
||||||
|
*/
|
||||||
|
public function testProvider(): void
|
||||||
|
{
|
||||||
|
$container = new Container();
|
||||||
|
|
||||||
|
$providerClass = $this->getProviderClass();
|
||||||
|
|
||||||
|
/** @var ServiceProvider $providerClass */
|
||||||
|
$provider = new $providerClass($container);
|
||||||
|
|
||||||
|
$this->assertInstanceOf($providerClass, $provider);
|
||||||
|
$provider->register();
|
||||||
|
|
||||||
|
$bindings = $provider->bindings;
|
||||||
|
foreach ($bindings as $abstract => $concrete) {
|
||||||
|
$this->assertTrue($container->bound($abstract), "The $abstract is not bound in the container.");
|
||||||
|
$this->assertNotNull($container->make($abstract), "The $abstract could not be resolved.");
|
||||||
|
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
$concrete,
|
||||||
|
$container->make($abstract),
|
||||||
|
"The $abstract is not an instance of $concrete."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
tests/ServiceProviders/LoggerServiceProviderTest.php
Normal file
15
tests/ServiceProviders/LoggerServiceProviderTest.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Siteworxpro\Tests\ServiceProviders;
|
||||||
|
|
||||||
|
use Siteworxpro\App\Services\ServiceProviders\LoggerServiceProvider;
|
||||||
|
|
||||||
|
class LoggerServiceProviderTest extends AbstractServiceProvider
|
||||||
|
{
|
||||||
|
protected function getProviderClass(): string
|
||||||
|
{
|
||||||
|
return LoggerServiceProvider::class;
|
||||||
|
}
|
||||||
|
}
|
||||||
15
tests/ServiceProviders/RedisServiceProviderTest.php
Normal file
15
tests/ServiceProviders/RedisServiceProviderTest.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Siteworxpro\Tests\ServiceProviders;
|
||||||
|
|
||||||
|
use Siteworxpro\App\Services\ServiceProviders\RedisServiceProvider;
|
||||||
|
|
||||||
|
class RedisServiceProviderTest extends AbstractServiceProvider
|
||||||
|
{
|
||||||
|
protected function getProviderClass(): string
|
||||||
|
{
|
||||||
|
return RedisServiceProvider::class;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,21 +5,29 @@ declare(strict_types=1);
|
|||||||
namespace Siteworxpro\Tests;
|
namespace Siteworxpro\Tests;
|
||||||
|
|
||||||
use Illuminate\Container\Container;
|
use Illuminate\Container\Container;
|
||||||
use Illuminate\Support\Facades\Facade;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Siteworx\Config\Config as SWConfig;
|
||||||
|
use Siteworxpro\App\Services\Facade;
|
||||||
use Siteworxpro\App\Services\Facades\Config;
|
use Siteworxpro\App\Services\Facades\Config;
|
||||||
|
|
||||||
abstract class Unit extends TestCase
|
abstract class Unit extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @throws \ReflectionException
|
||||||
|
*/
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$container = new Container();
|
$container = new Container();
|
||||||
Facade::setFacadeApplication($container);
|
Facade::setFacadeContainer($container);
|
||||||
|
|
||||||
|
$container->bind(SWConfig::class, function () {
|
||||||
|
return SWConfig::load(__DIR__ . '/../config.php');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
Config::clearResolvedInstances();
|
Config::clearResolvedInstances();
|
||||||
Facade::setFacadeApplication(null);
|
Facade::setFacadeContainer(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user