Skip to content

Commit

Permalink
Better installator (#128)
Browse files Browse the repository at this point in the history
* Restructures installer directory
- Adds generators
- Adds internal composer for running tests
- Prepares code for using in tests

* Splits Installer and Configurator into logical parts, which only are responsible for specific tasks.

* Adds Output DTO to use in Generators for sending output to the application.

* Puts console and exception generators into right place

* Fixes queue connection in config

* Adds link to the database configuration docs

* Adds unit tests

* Starts working on application installation tests

* Fixes bugs and improves installer in tests

* Fixes bugs and improves installer in tests

* Adds events storage for logging all installation events and use them for assertions

Adds first application test with assertions

* Update twig templates

* Fix namespaces in the composer.json

* Fix ViewRenderer

* Fix CS

* Fix CS

* Fix Exception Skeleton generator

* Fix repository binding

* Add middlewares generator in validators

* Add CycleInterceptor

* Add GuardInterceptor to the web app

* Add data grid

* Update dependencies

* Add translator module

* Fix CS

* Check verbosity

* Fix dependent questions

* Fix RoadRunnerConfigGeneratorTest, remove test app after test fails

* Fix locale in the twig template

* Improve deleting directories, fix copy module files

* Fix RoadRunnerBridge resources, fix tests deprecations

* Add phpunit gh workflow

* AppBootloader and RoutesBootloader is not required

* Fix gh workflow

* Add name, description to the composer.json

* Add allow-plugins to the composer.json

* Disable code coverage

* Remove .github directory after installation

* Add spiral/roadrunner-cli

* Install dependencies in the test app

* Run application tests

* Improve WebTest, fix assertBootloaderRegistered

* Add Plain PHP template engine

* Add ConsoleTest, remove unused resources

* Fix cs

* Rename method from findById to getById

* Fix PHPUnit schema

* Add docs links

* Add spiral/nyholm-bridge to the gRPC app

* Fix grpc resources

* Add spiral/nyholm-bridge

* Remove AppBootloader from gRPC app

* Add gRPC application test

* Add requires from composer.json

* Add grpc config with service

* Temporarily enable tests output

* Add grpc extension

* Disable tests output

* Add the ability to test modules

* Add getResourcesPath to the ModuleInterface

* Add test modules

* Add template engines tests

* Add validators, temporal bridge, translator tests

* Fixes `error_reporting` argument - deactivate deprecations

* Some improvements

* Improves readme generator.
Now it generates only information for selected packages and provide put information into different sections.

* CS fix

* Adds scaffolder for RoadRunner bridge package

* Adds readme for Web and Cli applications

---------

Co-authored-by: Maxim Smakouz <[email protected]>
  • Loading branch information
butschster and msmakouz authored Aug 21, 2023
1 parent 2179398 commit 2106ec0
Show file tree
Hide file tree
Showing 417 changed files with 12,101 additions and 3,446 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: phpunit

on:
push:
branches:
- installer
pull_request:
branches:
- installer

workflow_dispatch:

defaults:
run:
working-directory: ./installer

jobs:
phpunit:
name: PHP ${{ matrix.php }}-${{ matrix.os }}, ${{ matrix.stability }})

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2']
os: ['ubuntu-latest']
stability: ['prefer-lowest', 'prefer-stable']

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

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pdo, pdo_sqlite, sockets, grpc
tools: pecl

- name: Validate Composer
run: composer validate

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Restore Composer Cache
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer

- name: Install Dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress

- name: Execute Tests
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ rr*
protoc-gen-php-grpc*
.env
.phpunit.result.cache
.phpunit.cache
.deptrac.cache
.phpunit.cache/
5 changes: 3 additions & 2 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ enabled:
- trailing_comma_in_multiline_array
finder:
exclude:
- "tests"
- "public"
- "Tests"
- "installer/Application/Common/resources/tests"
- "installer/Module/RoadRunnerBridge/resources/config"
24 changes: 0 additions & 24 deletions cleanup.sh

This file was deleted.

26 changes: 10 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
},
"require": {
"php": ">=8.1",
"ext-sockets": "*",
"spiral/roadrunner-cli": "^2.4",
"spiral/framework": "^3.7"
"spiral/framework": "^3.7",
"spiral/roadrunner-cli": "^2.5"
},
"require-dev": {
"phpunit/phpunit": "^10.0",
"spiral/testing": "^2.2",
"symfony/var-dumper": "^6.1",
"vimeo/psalm": "^5.8",
"composer/composer": "^2.4"
"composer/composer": "^2.4",
"spiral/testing": "^2.3",
"vimeo/psalm": "^5.9"
},
"autoload": {
"psr-4": {
Expand All @@ -41,10 +38,10 @@
}
},
"scripts": {
"pre-install-cmd": "Installer\\Installer::install",
"pre-update-cmd": "Installer\\Installer::install",
"post-install-cmd": "Installer\\Configurator::configure",
"post-update-cmd": "Installer\\Configurator::configure",
"pre-install-cmd": "Installer\\Internal\\Installer::install",
"pre-update-cmd": "Installer\\Internal\\Installer::install",
"post-install-cmd": "Installer\\Internal\\Configurator::configure",
"post-update-cmd": "Installer\\Internal\\Configurator::configure",
"post-create-project-cmd": [
"php app.php encrypt:key -m .env",
"php app.php configure --quiet",
Expand All @@ -55,10 +52,7 @@
"rr:download-protoc": "rr download-protoc-binary",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage",
"psalm:config": "psalm",
"deptrack": [
"deptrac analyze --report-uncovered"
]
"psalm:config": "psalm"
},
"minimum-stability": "dev",
"prefer-stable": true
Expand Down
4 changes: 4 additions & 0 deletions installer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
composer.lock
vendor
Tests/App
build
66 changes: 0 additions & 66 deletions installer/AbstractInstaller.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

declare(strict_types=1);

namespace Installer\Question;
namespace Installer\Application;

use Installer\Question\Option\BooleanOption;
use Installer\Question\Option\OptionInterface;
use Installer\Internal\Question\AbstractQuestion;
use Installer\Internal\Question\Option\BooleanOption;
use Installer\Internal\Question\Option\OptionInterface;

final class ApplicationSkeleton extends AbstractQuestion
{
Expand All @@ -31,9 +32,9 @@ public function __construct(
public function getHelp(): ?string
{
return <<<'HELP'
Selecting this option will create a default application structure and demo data for your project. This includes a home
controller, an example console command, an example queue job, views, and locales. The demo data is intended to provide
you with a quick starting point for your application and can be modified or removed as needed.
HELP;
Selecting this option will create a default application structure and demo data for your project. This includes a home
controller, an example console command, an example queue job, views, and locales. The demo data is intended to provide
you with a quick starting point for your application and can be modified or removed as needed.
HELP;
}
}
92 changes: 92 additions & 0 deletions installer/Application/Cli/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

declare(strict_types=1);

namespace Installer\Application\Cli;

use Composer\Package\PackageInterface;
use Installer\Application\Cli\Generator\Bootloaders;
use Installer\Application\Cli\Generator\Skeleton;
use Installer\Internal\Application\AbstractApplication;
use Installer\Internal\Generator\GeneratorInterface;
use Installer\Internal\Package;
use Installer\Internal\Question\QuestionInterface;
use Installer\Internal\Readme\Block\FileBlock;
use Installer\Internal\Readme\Section;
use Installer\Module\Console\Generator\Skeleton as ConsoleSkeleton;
use Installer\Module\Dumper\Package as DumperPackage;
use Installer\Module\Exception\Generator\Skeleton as ExceptionSkeleton;
use Installer\Module\ExtMbString\Package as ExtMbStringPackage;
use Installer\Module\Psr7Implementation\Nyholm\Package as NyholmPsr7Implementation;
use Installer\Module\RoadRunnerBridge\Common\RoadRunnerCliPackage;

/**
* @psalm-import-type AutoloadRules from PackageInterface
* @psalm-import-type DevAutoloadRules from PackageInterface
*/
final class Application extends AbstractApplication
{
/**
* @param Package[] $packages
* @param AutoloadRules $autoload
* @param DevAutoloadRules $autoloadDev
* @param GeneratorInterface[] $generators
* @param QuestionInterface[] $questions
*/
public function __construct(
string $name = 'Cli',
array $packages = [
new ExtMbStringPackage(),
new NyholmPsr7Implementation(),
new DumperPackage(),
new RoadRunnerCliPackage(),
],
array $autoload = [
'psr-4' => [
'App\\' => 'app/src',
],
],
array $autoloadDev = [
'psr-4' => [
'Tests\\' => 'tests',
],
],
array $questions = [],
array $generators = [
new Bootloaders(),
new Skeleton(),
new ConsoleSkeleton(),
new ExceptionSkeleton(),
],
array $resources = [
':common:' => '',
],
array $commands = [],
array $instructions = []
) {
parent::__construct(
name: $name,
packages: $packages,
autoload: $autoload,
autoloadDev: $autoloadDev,
questions: $questions,
resources: $resources,
generators: $generators,
commands: $commands,
readme: $instructions
);
}

protected function getDefaultReadme(): array
{
return \array_merge(parent::getDefaultReadme(), [
Section::Usage->value => [
new FileBlock(__DIR__ . '/readme/usage.md'),
],

Section::ConsoleCommands->value => [
new FileBlock(__DIR__ . '/readme/commands.md'),
],
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace Installer\Application\Generator;
namespace Installer\Application\Cli\Generator;

use Installer\Generator\Context;
use Installer\Generator\GeneratorInterface;
use Installer\Internal\Generator\Context;
use Installer\Internal\Generator\GeneratorInterface;
use Spiral\Bootloader\Security;

final class CliApplicationBootloaders implements GeneratorInterface
final class Bootloaders implements GeneratorInterface
{
public function process(Context $context): void
{
Expand Down
22 changes: 22 additions & 0 deletions installer/Application/Cli/Generator/Skeleton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Installer\Application\Cli\Generator;

use Installer\Internal\Generator\Context;
use Installer\Internal\Generator\GeneratorInterface;

final class Skeleton implements GeneratorInterface
{
public function process(Context $context): void
{
if (!$context->application->hasSkeleton()) {
return;
}

if (\file_exists($context->applicationRoot . 'tests/Feature/.gitignore')) {
\unlink($context->applicationRoot . 'tests/Feature/.gitignore');
}
}
}
Loading

0 comments on commit 2106ec0

Please sign in to comment.