Skip to content

Commit

Permalink
Adiciona testes
Browse files Browse the repository at this point in the history
  • Loading branch information
lpirola committed May 15, 2024
1 parent 9174404 commit 03eb0d5
Show file tree
Hide file tree
Showing 17 changed files with 329 additions and 50 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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 }}
89 changes: 89 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ src/themes/BaseV1/assets/css/main.css.map
.idea
.phpunit.result.cache
.php-cs-fixer.cache
docker-data
public/assets/
docker-data/
src/.phpdoc
.phpunit*
.phpdocs*
.env
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]()

Expand Down
17 changes: 17 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<ruleset name="Slim coding standard">
<description>Slim coding standard</description>

<!-- display progress -->
<arg value="p"/>
<!-- use colors in output -->
<arg name="colors"/>

<!-- inherit rules from: -->
<rule ref="PSR12"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>

<!-- Paths to check -->
<file>src/</file>
<file>tests/src/</file>
</ruleset>
14 changes: 14 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutChangesToGlobalState="true" beStrictAboutOutputDuringTests="true" colors="true" processIsolation="false" stopOnFailure="false" bootstrap="tests/src/bootstrap.php" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage/>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests/src/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src/</directory>
</include>
</source>
</phpunit>
3 changes: 3 additions & 0 deletions tests/src/APITest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

require_once __DIR__ . '/bootstrap.php';

class APITest extends MapasCulturais_TestCase {
Expand Down Expand Up @@ -67,6 +68,8 @@ function testFindOneMethod() {
foreach($cps as $props => $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");
}
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/src/CreateEntitiesForDoctrineProxyTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/*

require_once __DIR__.'/bootstrap.php';

use MapasCulturais\App;
Expand All @@ -20,6 +20,7 @@ function testAll() {

$user = new User;
$user->authUid = 'fakes';
$user->authProvider = 3;
$user->email = 'user@doamain.com';
$user->save(true);

Expand Down Expand Up @@ -91,4 +92,3 @@ function testURLs(){
}
}
}
*/
2 changes: 1 addition & 1 deletion tests/src/DoctrineFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function NOTCOMPLETE_DISABLED_testEventOccurrence(){
'date_to' => $date_to
));
$result = $query->getResult();
var_dump($result);
// var_dump($result);
}

}
2 changes: 0 additions & 2 deletions tests/src/EntityTest.php → tests/src/EntityTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

require_once 'bootstrap.php';

require 'Entity.inc.TestEntities.php';

class EntityTests extends MapasCulturais_TestCase {

function testValidations() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 03eb0d5

Please sign in to comment.