2 Commits

Author SHA1 Message Date
54c656551e feat: add abstract classes for controllers, facades, and service providers with unit tests
Some checks failed
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Has started running
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Has been cancelled
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Has been cancelled
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Has been cancelled
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Has been cancelled
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Has been cancelled
2025-10-15 19:44:57 -04:00
a7c86343e4 Added .idea 2025-10-15 12:17:05 -04:00
16 changed files with 104 additions and 125 deletions

View File

@@ -1,5 +1,2 @@
.idea/
.DS_Store
vendor/ vendor/
.phpunit.cache/ .phpunit.cache/
tests/

View File

@@ -246,23 +246,10 @@ 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
uses: addnab/docker-run-action@v3 run: |
with: docker run --rm \
username: ${{ secrets.DOCKER_USERNAME }} --volumes-from ${{ env.JOB_CONTAINER_NAME }} \
password: ${{ secrets.DOCKER_PASSWORD }} -w ${{ github.workspace }} \
image: siteworxpro/composer siteworxpro/composer \
options: --volumes-from ${{ env.JOB_CONTAINER_NAME }} -w ${{ gitea.workspace }} run tests:unit
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

5
.gitignore vendored
View File

@@ -1,6 +1,3 @@
.idea/ .idea/
.DS_Store
vendor/ vendor/
.phpunit.cache/ .phpunit.cache/
tests/reports/

5
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,5 @@
include:
- local: .gitlab/ci/stages.yml
- local: .gitlab/ci/tests.yml
- local: .gitlab/ci/libraries.yml

15
.gitlab/ci/libraries.yml Normal file
View File

@@ -0,0 +1,15 @@
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

3
.gitlab/ci/stages.yml Normal file
View File

@@ -0,0 +1,3 @@
stages:
- libraries
- tests

65
.gitlab/ci/tests.yml Normal file
View File

@@ -0,0 +1,65 @@
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

View File

@@ -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.4 AS roadrunner FROM ghcr.io/roadrunner-server/roadrunner:2025.1.1 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.14-alpine AS php FROM php:8.4.6-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 \

View File

@@ -1,4 +0,0 @@
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

View File

@@ -12,24 +12,6 @@ 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"
@@ -47,11 +29,6 @@ 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:
@@ -59,11 +36,6 @@ 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}

View File

@@ -1,8 +1,5 @@
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"]

View File

@@ -6,12 +6,6 @@ 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';
} }

View File

@@ -1,52 +0,0 @@
<?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)
);
}
}

View File

@@ -49,6 +49,8 @@ class ControllerTest extends AbstractController
} }
} }
class TestClass extends Controller // phpcs:ignore // @ignore
class TestClass extends Controller
{ {
} }

View File

@@ -29,4 +29,4 @@ abstract class AbstractFacade extends Unit
sprintf('The facade %s is not properly initialized.', $this->getConcrete()) sprintf('The facade %s is not properly initialized.', $this->getConcrete())
); );
} }
} }

View File

@@ -11,6 +11,7 @@ use Siteworxpro\Tests\Unit;
abstract class AbstractServiceProvider extends Unit abstract class AbstractServiceProvider extends Unit
{ {
abstract protected function getProviderClass(): string; abstract protected function getProviderClass(): string;
/** /**