Skip to content

Commit

Permalink
Merge pull request #1 from EscolaLMS/feature/STAR-57
Browse files Browse the repository at this point in the history
Draft: Feature/star 57
  • Loading branch information
qunabu authored Feb 2, 2022
2 parents d1248e9 + 33f4999 commit 06faac9
Show file tree
Hide file tree
Showing 76 changed files with 3,595 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[{Makefile,makefile,**.mk}]
indent_style = tab
51 changes: 51 additions & 0 deletions .github/workflows/swagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Generate Swagger Documentation

on:
push:
branches:
- main

jobs:
swagger-gh-pages:
runs-on: ubuntu-latest
container:
image: escolalms/php:7.4

steps:
- name: Instantiate package
uses: actions/checkout@v2

- name: Setup environment
run: cp -r env/codecov/. .

- name: add Swagger main annotaion
run: php -r "file_put_contents('src/EscolaLmsNotificationsServiceProvider.php', str_replace('SWAGGER_VERSION', '@OA\Info(title=\"EscolaLMS\", version=\"0.0.1\")', file_get_contents('src/EscolaLmsNotificationsServiceProvider.php')));"

- name: Update composer
run: COMPOSER_ROOT_VERSION=0.9.9 composer update

- name: Require composer swagger package
run: composer require darkaonline/l5-swagger

- name: Discover packages
run: vendor/bin/testbench package:discover --ansi

- name: Generate YAML openapi
run: vendor/bin/openapi --format json -b env/openapi/config.php -o openapi.json src

- name: Swagger ui action
id: swagger-ui-action
uses: pjoc-team/[email protected]
with:
dir: "./"
pattern: "openapi.json"
debug: "true"

- name: Install git
run: apt-get install git -y

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: swagger-ui
66 changes: 66 additions & 0 deletions .github/workflows/test-cc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Tests Code Coverage

on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- main
- master
pull_request:

jobs:
phpunit-code-coverage:
runs-on: ubuntu-latest
container:
image: escolalms/php:7.4

services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: database
MYSQL_PASSWORD: password
MYSQL_USER: username
ports:
- 33306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Instantiate package
run: apt-get install git -y

- name: Instantiate package
uses: actions/checkout@v2

- name: Setup environment
run: cp -r env/codecov/. .

- name: Update composer
run: composer update

- name: Clear config
run: vendor/bin/testbench config:clear

- name: Publish things
run: vendor/bin/testbench migrate:fresh

- name: Run tests
run: XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover coverage.xml

- name: codecov upload
uses: codecov/codecov-action@v1

- name: Setup Code Climate test-reporter
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
- name: Convert
run: ./cc-test-reporter format-coverage coverage.xml -t clover -o codeclimate.0.json

- name: Upload
run: ./cc-test-reporter upload-coverage -i codeclimate.0.json
env:
CC_TEST_REPORTER_ID: 1efb33e7c45780f90265e4c97ef32b1ae760f21d9156a86448cb38a043eaa800
120 changes: 120 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Tests PHPUnit in environments

on:
# Trigger the workflow on push or pull request,
# but only for the main branch
push:
branches:
- main
- master
pull_request:


jobs:
php8-laravel-latest-phpunit-mysql:
runs-on: ubuntu-latest
container:
image: escolalms/php:8

services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: database
MYSQL_PASSWORD: password
MYSQL_USER: username
ports:
- 33306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Instantiate package
uses: actions/checkout@v2

- name: Setup environment
run: cp env/mysql/* .

- name: Update composer
run: composer update

- name: Clear config
run: vendor/bin/testbench config:clear

- name: Publish things
run: vendor/bin/testbench migrate:fresh

- name: Run tests
run: vendor/bin/phpunit

php74-laravel-latest-phpunit-mysql:
runs-on: ubuntu-latest
container:
image: escolalms/php:7.4

services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: database
MYSQL_PASSWORD: password
MYSQL_USER: username
ports:
- 33306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Instantiate package
uses: actions/checkout@v2

- name: Setup environment
run: cp env/mysql/* .

- name: Update composer
run: composer update

- name: Clear config
run: vendor/bin/testbench config:clear

- name: Publish things
run: vendor/bin/testbench migrate:fresh

- name: Run tests
run: vendor/bin/phpunit

php74-laravel-latest-phpunit-postgres:
runs-on: ubuntu-latest
container:
image: escolalms/php:7.4

services:
postgres:
image: postgres:12
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
TZ: Europe/Warsaw
ports:
- 5432:5432

steps:
- name: Instantiate package
uses: actions/checkout@v2

- name: Update composer
run: composer update

- name: Setup environment
run: cp env/postgres/* .

- name: Clear config
run: vendor/bin/testbench config:clear

- name: Publish things
run: vendor/bin/testbench migrate:fresh

- name: Run tests
run: vendor/bin/phpunit
### TODO add behat tests here
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
./.env
./phpunit.xml
./testbench.yaml
.env
.idea/
.phpunit.result.cache
composer.lock
src/oa_version.php
tags
vendor/
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# Questionnaire
# Questionnaire

Questionnaire package

[![swagger](https://img.shields.io/badge/documentation-swagger-green)](https://escolalms.github.io/questionnaire/)
[![codecov](https://codecov.io/gh/EscolaLMS/questionnaire/branch/main/graph/badge.svg?token=gBzpyNK8DQ)](https://codecov.io/gh/EscolaLMS/questionnaire)
[![phpunit](https://github.com/EscolaLMS/questionnaire/actions/workflows/test.yml/badge.svg)](https://github.com/EscolaLMS/questionnaire/actions/workflows/test.yml)
[![downloads](https://img.shields.io/packagist/dt/escolalms/questionnaire)](https://packagist.org/packages/escolalms/questionnaire)
[![downloads](https://img.shields.io/packagist/v/escolalms/questionnaire)](https://packagist.org/packages/escolalms/questionnaire)
[![downloads](https://img.shields.io/packagist/l/escolalms/questionnaire)](https://packagist.org/packages/escolalms/questionnaire)

###

This package is used for creating Questionnaire.
43 changes: 43 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "escolalms/questionnaire",
"description": "Escola LMS Questionnaire",
"type": "package",
"require": {
"php": ">=7.4|>=8",
"laravel/framework": ">=8.0",
"escolalms/core": "^1"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"orchestra/testbench": ">=5.0",
"escolalms/courses": "^0"
},
"license": "Apache-2.0",
"authors": [
{
"name": "Krzysztof Dziedziech",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"EscolaLms\\Questionnaire\\": "src",
"EscolaLms\\Questionnaire\\Database\\Seeders\\": "database/seeders",
"EscolaLms\\Questionnaire\\Database\\Factories\\": "database/factories",
"EscolaLms\\Questionnaire\\Tests\\": "tests"
}
},
"extra": {
"laravel": {
"providers": [
"EscolaLms\\Questionnaire\\EscolaLmsQuestionnaireServiceProvider"
]
}
},
"config": {
"preferred-install": "dist",
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
51 changes: 51 additions & 0 deletions database/factories/QuestionAnswerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace EscolaLms\Questionnaire\Database\Factories;

use EscolaLms\Core\Models\User;
use EscolaLms\Questionnaire\Models\Question;
use EscolaLms\Questionnaire\Models\QuestionAnswer;
use EscolaLms\Questionnaire\Models\QuestionnaireModel;
use Illuminate\Database\Eloquent\Factories\Factory;

class QuestionAnswerFactory extends Factory
{
protected $model = QuestionAnswer::class;

public function definition()
{
/** @var Question $question */
$question = Question::query()->inRandomOrder()->first();
if (empty($question)) {
Question::factory()
->count(1)
->create();
$question = Question::query()->inRandomOrder()->first();
}

/** @var QuestionnaireModel $questionnaireModel */
$questionnaireModel = QuestionnaireModel::query()->inRandomOrder()->first();
if (empty($questionnaireModel)) {
QuestionnaireModel::factory()
->count(1)
->create();
$questionnaireModel = QuestionnaireModel::query()->inRandomOrder()->first();
}

/** @var User $user */
$user = User::query()->inRandomOrder()->first();
if (empty($user)) {
User::factory()
->count(1)
->create();
$user = User::query()->inRandomOrder()->first();
}

return [
'questionnaire_model_id' => $questionnaireModel->id,
'question_id' => $question->id,
'user_id' => $user->id,
'rate' => $this->faker->numberBetween(1, 5),
];
}
}
Loading

0 comments on commit 06faac9

Please sign in to comment.