diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000000..b9f1d7155c --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,62 @@ +name: Deploy + +on: + pull_request: + types: + - labeled + +jobs: + deploy: + if: github.event.label.name == 'REDELIVRE' + runs-on: ubuntu-latest + + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + # list of Docker images to use as base name for tags + images: | + docker.io/hacklab/mapasculturais + # ghcr.io/username/app + # generate Docker tags based on the following events/attributes + tags: | + type=ref,event=branch + type=sha,format=long + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to Docker Hub + # if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v4 + with: + file: ./docker/Dockerfile + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Inject slug/short variables + uses: rlespinasse/github-slug-action@v4 + with: + prefix: RL_ + - + name: deploy to cluster + uses: steebchen/kubectl@v2.0.0 + with: # defaults to latest kubectl binary version + config: ${{ secrets.KUBE_CONFIG_DATA }} + command: set image --record deployment/mapasculturais -nredelivre-mapas-dev mapas=docker.io/hacklab/mapasculturais:sha-${{ github.sha }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..00d9d84fe6 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,89 @@ +name: Testing + +on: + push: + branches: + - "master" + - "develop" + pull_request: + branches: + - "develop" + +jobs: + php: + strategy: + matrix: + operating-system: [ubuntu-latest] + php-versions: ['8.2'] + runs-on: ${{ matrix.operating-system }} + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Composer Install + run: docker run --rm -v $PWD:/app composer:latest install + - + name: Docker Compose + uses: KengoTODA/actions-setup-docker-compose@v1 + with: + version: '2.14.2' # the full version of `docker-compose` command + - run: docker compose up -d + - + name: Database Migrations + run: sleep 5 && docker compose run --rm migrations + - + name: Phpunit Coverage + run: docker compose exec backend ./vendor/bin/phpunit --coverage-text + # - + # name: deploy to cluster + # uses: steebchen/kubectl@v2.0.0 + # with: # defaults to latest kubectl binary version + # config: ${{ secrets.KUBE_CONFIG_DATA }} + # command: set image --record deployment/mapasculturais -nredelivre-mapas-dev container=${{ github.repository }}:${{ github.sha }} + + # Docs: https://github.com/shivammathur/setup-php + # - + # name: Setup PHP + # uses: shivammathur/setup-php@v2 + # with: + # php-version: ${{ matrix.php-versions }} + # extensions: mbstring, dom, pdo_pgsql, gd, intl, zip, opcache, xml, curl, iconv, xmlwriter, simplexml + # coverage: none # xdebug + # tools: composer + # - + # name: Get composer cache directory + # id: composer-cache + # run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + # - + # name: Cache composer dependencies + # uses: actions/cache@v3 + # with: + # path: ${{ steps.composer-cache.outputs.dir }} + # # Use composer.json for key, if composer.lock is not committed. + # # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + # restore-keys: ${{ runner.os }}-composer- + # - + # name: Install dependencies + # run: composer install --no-progress --prefer-dist --optimize-autoloader + # - + # name: Add hosts to /etc/hosts + # run: | + # sudo echo "127.0.0.1 db redis" | sudo tee -a /etc/hosts + # - + # name: Docker compose up + # uses: isbang/compose-action@v1.5.1 + # with: + # compose-file: "./docker-compose.yml" + # down-flags: "--volumes" + # services: | + # db + # redis + # migrations + # - + # name: Test with phpunit + # run: docker compose exec backend ls ./vendor/ + # - + # name: Test with phpunit + # run: docker compose exec backend ./vendor/bin/phpunit --coverage-text diff --git a/.gitignore b/.gitignore index d2f64a715e..0288c2aa9d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,9 @@ src/themes/BaseV1/assets/css/main.css.map .idea .phpunit.result.cache .php-cs-fixer.cache -docker-data \ No newline at end of file +public/assets/ +docker-data/ +src/.phpdoc +.phpunit* +.phpdocs* +.env diff --git a/README.md b/README.md index bd90728cf9..2e554be969 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,47 @@ Temos muito a agradecer tudo que foi construído até a versão XXX, e a partir --- +## Instalação rápida com docker compose + +`docker compose up -d` + +### Ferramentas + +#### PHP Composer + +`docker run --rm -it -v $PWD:/app composer:latest install` + +#### Migração do Banco de Dados + +`docker compose exec backend php src/tools/apply-updates.php` +`docker compose exec backend php src/tools/apply-multicore-db-update.php` + +#### Frontend + +`nvm use 18 && cd src && pnpm install --recursive && pnpm build` + +npx oxlint@latest + +#### Phpdoc + +`docker run --rm -v ${PWD}/src:/data phpdoc/phpdoc:3` + +#### Phpunit + +`docker compose exec backend ./vendor/bin/phpunit` + +#### Phpcs + +`docker compose exec backend ./vendor/bin/phpcs -d memory_limit=1024M src/**/*.php` + +#### Phplint + +`docker run --rm -it -v $PWD:/app overtrue/phplint:latest /app/src/` + +#### HTTP Endpoints + +`egrep -r "function API_|function GET_|function POST_|function PATCH_|function PUT_|function DELETE_|function ALL_" src` + ## Instalação A maneira mais simples e segura para instalar o MapaCultural é seguindo [Este tutorial]() diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000000..62b407aff3 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,17 @@ + + + Slim coding standard + + + + + + + + + + + + src/ + tests/src/ + \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000000..3b67fe023e --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,14 @@ + + + + + + ./tests/src/ + + + + + ./src/ + + + diff --git a/tests/src/APITest.php b/tests/src/APITest.php index 88dbbfdcfe..b745fc1b47 100644 --- a/tests/src/APITest.php +++ b/tests/src/APITest.php @@ -1,4 +1,5 @@ $proc){ $response = $this->apiFindOne($class, "@select={$props}&id=EQ({$entity->id})"); $_entity = $proc($entity, $props); + $_entity['@entityType'] = strtolower($class); + $this->assertEquals($_entity, $response, "asserting {$class} api findOne to \$user"); } diff --git a/tests/src/ModuleAgendaSingleTest.php b/tests/src/AgendaSingleTest.php similarity index 100% rename from tests/src/ModuleAgendaSingleTest.php rename to tests/src/AgendaSingleTest.php diff --git a/tests/src/CreateEntitiesForDoctrineProxyTest.php b/tests/src/CreateEntitiesForDoctrineProxyTest.php index 4d0dc4a872..4c15e81840 100644 --- a/tests/src/CreateEntitiesForDoctrineProxyTest.php +++ b/tests/src/CreateEntitiesForDoctrineProxyTest.php @@ -1,5 +1,5 @@ authUid = 'fakes'; + $user->authProvider = 3; $user->email = 'user@doamain.com'; $user->save(true); @@ -91,4 +92,3 @@ function testURLs(){ } } } -*/ \ No newline at end of file diff --git a/tests/src/DoctrineFunctionTest.php b/tests/src/DoctrineFunctionTest.php index 32b2164a60..caca3e833b 100644 --- a/tests/src/DoctrineFunctionTest.php +++ b/tests/src/DoctrineFunctionTest.php @@ -49,7 +49,7 @@ function NOTCOMPLETE_DISABLED_testEventOccurrence(){ 'date_to' => $date_to )); $result = $query->getResult(); - var_dump($result); + // var_dump($result); } } diff --git a/tests/src/EntityTest.php b/tests/src/EntityTests.php similarity index 99% rename from tests/src/EntityTest.php rename to tests/src/EntityTests.php index 200a679818..ce3569fd31 100644 --- a/tests/src/EntityTest.php +++ b/tests/src/EntityTests.php @@ -2,8 +2,6 @@ require_once 'bootstrap.php'; -require 'Entity.inc.TestEntities.php'; - class EntityTests extends MapasCulturais_TestCase { function testValidations() { diff --git a/tests/src/MetadataTest.php b/tests/src/MetadataTests.php similarity index 100% rename from tests/src/MetadataTest.php rename to tests/src/MetadataTests.php diff --git a/tests/src/ProjectTest.php b/tests/src/ProjectTests.php similarity index 100% rename from tests/src/ProjectTest.php rename to tests/src/ProjectTests.php diff --git a/tests/src/TaxonomiesTest.php b/tests/src/TaxonomiesTests.php similarity index 100% rename from tests/src/TaxonomiesTest.php rename to tests/src/TaxonomiesTests.php diff --git a/tests/src/bootstrap.php b/tests/src/bootstrap.php index e8f5ebf45f..72ec8d3a22 100644 --- a/tests/src/bootstrap.php +++ b/tests/src/bootstrap.php @@ -1,45 +1,99 @@ 'get', - 'PATH_INFO' => '/', - 'SERVER_NAME' => 'local.dev', -))); +// \Slim\Environment::mock(array_merge(array( +// 'REQUEST_METHOD' => 'get', +// 'PATH_INFO' => '/', +// 'SERVER_NAME' => 'local.dev', +// ))); -$config = include __DIR__ . '/../src/protected/application/conf/conf-test.php'; +// $config = include __DIR__ . '/../src/protected/application/conf/conf-test.php'; -if(isset($_ENV['MAPASCULTURAIS_CONFIG_FILE'])){ - $config = include __DIR__ . '/../src/protected/application/conf/'. $_ENV['MAPASCULTURAIS_CONFIG_FILE']; -}else if(isset($_SERVER['MAPASCULTURAIS_CONFIG_FILE'])){ - $config = include __DIR__ . '/../src/protected/application/conf/' . $_SERVER['MAPASCULTURAIS_CONFIG_FILE']; -} +// if(isset($_ENV['MAPASCULTURAIS_CONFIG_FILE'])){ +// $config = include __DIR__ . '/../src/protected/application/conf/'. $_ENV['MAPASCULTURAIS_CONFIG_FILE']; +// }else if(isset($_SERVER['MAPASCULTURAIS_CONFIG_FILE'])){ +// $config = include __DIR__ . '/../src/protected/application/conf/' . $_SERVER['MAPASCULTURAIS_CONFIG_FILE']; +// } + + +$config = require_once("config.php"); + +// require_once(__DIR__ . "/../../src/load-translation.php"); // create the App instance -$app = App::i()->init($config); -$app->register(); +$app = \MapasCulturais\App::i()->init($config); +// $app->register(); require __DIR__ . '/classes/TestCase.php'; require __DIR__ . '/classes/TestFactory.php'; diff --git a/tests/src/Entity.inc.TestEntities.php b/tests/src/classes/TestEntity.php similarity index 100% rename from tests/src/Entity.inc.TestEntities.php rename to tests/src/classes/TestEntity.php diff --git a/tests/docker/config.php b/tests/src/config.php similarity index 73% rename from tests/docker/config.php rename to tests/src/config.php index 34a4a2c7ff..70cd3a4803 100644 --- a/tests/docker/config.php +++ b/tests/src/config.php @@ -1,14 +1,17 @@ 'SpCultura', + 'themes.active' => '\MapasCulturais\Themes\BaseV2', 'base.url' => 'http://localhost:8888/', 'site.url' => 'http://localhost:8888/', 'app.log.translations' => false, - 'slim.log.level' => Log::DEBUG, + 'slim.log.level' => 3, 'slim.log.enabled' => false, // 'app.log.query' => true, 'slim.debug' => false, @@ -24,14 +27,6 @@ 'doctrine.isDev' => false, - 'doctrine.database' => array( - 'dbname' => 'mapas', - 'user' => 'mapas', - 'password' => 'mapas', - 'host' => 'db', - - ), - 'userIds' => array( 'superAdmin' => array(1,2), // 'admin' => 2, @@ -44,9 +39,10 @@ ), // disable cache + 'db.host' => 'db', 'app.usePermissionsCache' => false, - 'app.chace' => new \Doctrine\Common\Cache\ArrayCache() + 'app.chace' => new \Symfony\Component\Cache\Adapter\ArrayAdapter() // 'app.cache' => function_exists('apc_store') ? new \Doctrine\Common\Cache\ApcCache() : new \Doctrine\Common\Cache\ArrayCache(), ) );