Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 74 additions & 22 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,91 @@
name: PHP Composer
name: CI

on:
push:
branches: [ "main" ]
branches: ["main", "feature/**"]
pull_request:
branches: [ "main" ]
branches: ["main"]

permissions:
contents: read

jobs:
build:

test:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: ["8.4"]

env:
# Collect coverage only on PRs and pushes to main — keeps all other runs fast
LOG_COVERAGE: "${{ fromJSON('{true: \"1\", false: \"\"}')[matrix.php == '8.4' && (github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main'))] }}"

steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pdo, pdo_mysql, mbstring, xml
coverage: ${{ env.LOG_COVERAGE && 'pcov' || 'none' }}

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Validate composer.json and composer.lock
run: composer validate --strict
- name: Cache Composer packages
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php }}-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ runner.os }}-php-${{ matrix.php }}-

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: |
composer install --prefer-dist --no-progress --no-interaction
if [ -n "$LOG_COVERAGE" ]; then mkdir -p coverage; fi

- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Run tests
run: |
vendor/bin/phpunit \
--no-progress \
--fail-on-warning \
--fail-on-risky \
--fail-on-notice \
--fail-on-deprecation \
--display-notices \
--display-deprecations \
--display-phpunit-deprecations \
--display-warnings \
--display-errors \
$(if [ -n "$LOG_COVERAGE" ]; then echo "--coverage-clover coverage/clover.xml --coverage-text"; else echo "--no-coverage"; fi)

# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md
- name: Enforce 80% line coverage
if: env.LOG_COVERAGE
run: |
php -r "
\$xml = simplexml_load_file('coverage/clover.xml');
\$m = \$xml->project->metrics;
\$total = (int)\$m['statements'];
\$covered = (int)\$m['coveredstatements'];
\$pct = \$total > 0 ? round(\$covered / \$total * 100, 2) : 0;
echo \"Line coverage: {\$pct}%\n\";
if (\$pct < 80) {
echo \"FAIL: {\$pct}% is below the required 80%.\n\";
exit(1);
}
echo \"PASS\n\";
"

# - name: Run test suite
# run: composer run-script test
- name: Upload coverage to Codecov
if: env.LOG_COVERAGE
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage/clover.xml
fail_ci_if_error: true
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
.env
.DS_Store
composer.lock
/vendor
/vendor
/coverage
CLAUDE.md
/.claude
/app
/database
.phpunit.result.cache
21 changes: 21 additions & 0 deletions bin/ef
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php

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

use Symfony\Component\Console\Application;
use EntityForge\Console\GenerateCommand;
use EntityForge\Console\GenerateAllCommand;
use EntityForge\Console\MigrateCommand;
use EntityForge\Console\RollbackCommand;
use EntityForge\Console\TenantCreateCommand;

$application = new Application('EntityForge CLI', '1.0');

$application->addCommand(new GenerateCommand());
$application->addCommand(new GenerateAllCommand());
$application->addCommand(new MigrateCommand());
$application->addCommand(new RollbackCommand());
$application->addCommand(new TenantCreateCommand());

$application->run();
41 changes: 19 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
{
"name": "entity-forge/entity-forge",
"version": "1.0",
"description": "EntityForge — a simple PHP library to generate and manage entity models",
"description": "A configuration-driven PHP framework for generating entity models and building multi-tenant SaaS applications.",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Vedavith Ravula",
"email": "vedavithravula1996@gmail.com"
"autoload": {
"psr-4": {
"EntityForge\\": "src/",
"App\\": "app/"
}
],
},
"require": {
"php": ">=8.0",
"symfony/console": "^v6.4.8",
"ext-pdo": "*",
"symfony/dependency-injection": "^v7.1.1"
"php": "^8.4",
"symfony/yaml": "^8.1",
"symfony/console": "^8.1",
"ext-pdo": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.6"
"phpunit/phpunit": "^13.0",
"mockery/mockery": "^1.6"
},
"autoload": {
"psr-4": {
"EntityForge\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"EntityForge\\Tests\\": "tests/"
}
}

"bin": [
"bin/ef"
],

"minimum-stability": "stable",
"prefer-stable": true
}
16 changes: 16 additions & 0 deletions config/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
application:
name: entity-forge-app

tenancy:
enabled: true
resolver: header
header_key: X-Tenant-ID
strategy: database # shared | database

database:
driver: mysql
host: localhost
port: 3306
username: root
password: root
database: entity_forge
10 changes: 10 additions & 0 deletions config/entities/User.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"entity": "User",
"multiTenant": true,
"timestamps": true,
"fields": {
"id": "int",
"name": "string",
"email": "string"
}
}
4 changes: 4 additions & 0 deletions config/saas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tenancy:
enabled: true
strategy: shared_table
tenant_id_column: tenant_id
Loading
Loading