Skip to content

Commit

Permalink
Add PHP Tests, Renamed Main Class
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Sep 16, 2023
1 parent 178a23e commit 0edd1ae
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 84 deletions.
95 changes: 44 additions & 51 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,60 @@
# name: Build
name: Build

# on:
# push:
# branches: ['*']
# pull_request:
# branches: ['*']
on:
push:
branches: ['*']
pull_request:
branches: ['*']
# schedule:
# - cron: "0 0 * * 5"

# jobs:
# PHPUnit-Memory:
jobs:
PHPUnit-Memory:

# strategy:
# fail-fast: false
# matrix:
# php_versions: ['8.0', '8.1', '8.2']
strategy:
fail-fast: false
matrix:
php_versions: ['8.0', '8.1', '8.2']
node_version: ['18']

# runs-on: ubuntu-latest
# name: PHPUnit - PHP ${{ matrix.php_versions }} - Memory SQLite
runs-on: ubuntu-latest
name: PHP ${{ matrix.php_versions }} - Node ${{ matrix.node_version }} - Memory SQLite

# steps:
# - uses: actions/checkout@v3
steps:
- uses: actions/checkout@v4

# - name: Setup PHP, with composer and extensions
# uses: shivammathur/setup-php@v2
# with:
# php-version: ${{ matrix.php_versions }}
# extensions: mbstring, dom, fileinfo, gd, memcached, redis, pdo_sqlite
# coverage: xdebug
# tools: pecl, composer

# - uses: actions/setup-node@v2
# with:
# node-version: 14

# - name: Setup Redis-server
# uses: supercharge/redis-github-action@1.1.0
# with:
# redis-version: 6
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_versions }}
extensions: mbstring, dom, fileinfo, gd, memcached, redis, pdo_sqlite
coverage: xdebug
tools: pecl, composer

- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.php_versions }}

# - name: Setup Memcached
# uses: niden/actions-memcached@v7

# - name: Install Dependencies
# run: composer install --prefer-dist --no-progress
- name: Install Dependencies
run: composer install --prefer-dist --no-progress

# - name: Npm Install
# run: npm install
- name: Npm Install
run: npm install

# - name: Run Webpack
# run: npm run dev
- name: Run Webpack
run: npm run dev

# - name: Execute tests
# run: |
# echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
# vendor/bin/phpunit
- name: Execute tests
run: |
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
vendor/bin/phpunit
# - name: Upload coverage to Codecov
# if: github.event_name != 'schedule'
# uses: codecov/codecov-action@v3
# with:
# file: ./_meta/coverage.xml
# fail_ci_if_error: true
- name: Upload coverage to Codecov
if: github.event_name != 'schedule'
uses: codecov/codecov-action@v3
with:
file: ./_meta/coverage.xml
fail_ci_if_error: true

# PHPUnit-MySQL:

Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/PHPStan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: PHPStan

on:
push:
branches: ['*']
pull_request:
branches: ['*']
workflow_dispatch:

jobs:
PHPStan:

strategy:
fail-fast: false
matrix:
php_versions: ['8.0', '8.1', '8.2']

runs-on: ubuntu-latest
name: PHPStan - ${{ matrix.php_versions }}

steps:
- uses: actions/checkout@v4

- name: Setup PHP,with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_versions }}

- name: Install Dependencies
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

- name: Run PHPStan
run: vendor/bin/phpstan analyse app/src/ app/tests/
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
![PHP Version](https://img.shields.io/badge/php-%5E8.0-brightgreen)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md)
[![Join the chat at https://chat.userfrosting.com/channel/support](https://chat.userfrosting.com/api/v1/shield.svg?name=UserFrosting)](https://chat.userfrosting.com/channel/support)
[![Build](https://github.com/userfrosting/demo-vue/workflows/Build/badge.svg?branch=main)](https://github.com/userfrosting/demo-vue/actions?query=workflow%3ABuild)
[![Codecov](https://codecov.io/gh/userfrosting/demo-vue/branch/main/graph/badge.svg)](https://codecov.io/gh/userfrosting/demo-vue)
[![Style](https://github.styleci.io/repos/689461212/shield?branch=main&style=flat)](https://github.styleci.io/repos/689461212)
[![PHPStan](https://img.shields.io/github/actions/workflow/status/userfrosting/demo-vue/PHPStan.yml?branch=main&label=PHPStan)](https://github.com/userfrosting/demo-vue/actions/workflows/PHPStan.yml)
[![Donate](https://img.shields.io/badge/Donate-Buy%20Me%20a%20Coffee-blue.svg)](https://ko-fi.com/lcharette)
<!-- [![Latest Version](https://img.shields.io/github/v/release/userfrosting/userfrosting?include_prereleases&sort=semver)](https://github.com/userfrosting/UserFrosting/releases) -->
<!-- [![Build](https://github.com/userfrosting/userfrosting/workflows/Build/badge.svg?branch=develop-5.0)](https://github.com/userfrosting/userfrosting/actions?query=workflow%3ABuild) -->
<!-- [![Codecov](https://codecov.io/gh/userfrosting/userfrosting/branch/develop-5.0/graph/badge.svg)](https://codecov.io/gh/userfrosting/userfrosting) -->
<!-- [![Style](https://github.styleci.io/repos/18148206/shield?branch=develop-5.0&style=flat)](https://github.styleci.io/repos/18148206) -->
<!-- [![Backers on Open Collective](https://opencollective.com/userfrosting/backers/badge.svg)](#backers) -->
<!-- [![Sponsors on Open Collective](https://opencollective.com/userfrosting/sponsors/badge.svg)](#sponsors) -->
<!-- [![Donate](https://img.shields.io/badge/Open%20Collective-Donate-blue.svg)](https://opencollective.com/userfrosting#backer) -->
Expand Down
18 changes: 9 additions & 9 deletions app/src/Controller/AppController.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

/*
* UserFrosting (http://www.userfrosting.com)
* UserFrosting Vue Demo (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/UserFrosting
* @copyright Copyright (c) 2021 Alexander Weissman & Louis Charette
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
* @link https://github.com/userfrosting/demo-vue
* @copyright Copyright (c) 2023 Louis Charette
* @license https://github.com/userfrosting/demo-vue/blob/main/LICENSE.md (MIT License)
*/

namespace UserFrosting\Demo\Controller;
Expand Down Expand Up @@ -33,27 +33,27 @@ public function api(Response $response): Response
[
'url' => 'https://getbootstrap.com/docs/5.3/getting-started/introduction/',
'title' => 'Bootstrap quick start guide',
'number' => rand(1, 100)
'number' => rand(1, 100),
],
[
'url' => 'https://getbootstrap.com/docs/5.3/getting-started/webpack/',
'title' => 'Bootstrap Webpack guide',
'number' => rand(1, 100)
'number' => rand(1, 100),
],
[
'url' => 'https://getbootstrap.com/docs/5.3/getting-started/parcel/',
'title' => 'Bootstrap Parcel guide',
'number' => rand(1, 100)
'number' => rand(1, 100),
],
[
'url' => 'https://getbootstrap.com/docs/5.3/getting-started/vite/',
'title' => 'Bootstrap Vite guide',
'number' => rand(1, 100)
'number' => rand(1, 100),
],
[
'url' => 'https://getbootstrap.com/docs/5.3/getting-started/contribute/',
'title' => 'Contributing to Bootstrap',
'number' => rand(1, 100)
'number' => rand(1, 100),
],
];

Expand Down
10 changes: 5 additions & 5 deletions app/src/UiKitTheme.php → app/src/Demo.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php

/*
* UserFrosting (http://www.userfrosting.com)
* UserFrosting Vue Demo (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/UserFrosting
* @copyright Copyright (c) 2021 Alexander Weissman & Louis Charette
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
* @link https://github.com/userfrosting/demo-vue
* @copyright Copyright (c) 2023 Louis Charette
* @license https://github.com/userfrosting/demo-vue/blob/main/LICENSE.md (MIT License)
*/

namespace UserFrosting\Demo;

use UserFrosting\Sprinkle\Core\Core;
use UserFrosting\Sprinkle\SprinkleRecipe;

class UiKitTheme implements SprinkleRecipe
class Demo implements SprinkleRecipe
{
/**
* {@inheritdoc}
Expand Down
8 changes: 4 additions & 4 deletions app/src/Routes.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

/*
* UserFrosting (http://www.userfrosting.com)
* UserFrosting Vue Demo (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/UserFrosting
* @copyright Copyright (c) 2021 Alexander Weissman & Louis Charette
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
* @link https://github.com/userfrosting/demo-vue
* @copyright Copyright (c) 2023 Louis Charette
* @license https://github.com/userfrosting/demo-vue/blob/main/LICENSE.md (MIT License)
*/

namespace UserFrosting\Demo;
Expand Down
20 changes: 16 additions & 4 deletions app/tests/Controller/AppControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@

namespace UserFrosting\Tests\Demo\Controller;

use UserFrosting\App\MyApp;
use UserFrosting\Demo\Demo;
use UserFrosting\Testing\TestCase;

/**
* Tests for AppController Class.
*
* N.B.: THIS FILE IS SAFE TO EDIT OR DELETE.
*/
class AppControllerTest extends TestCase
{
protected string $mainSprinkle = MyApp::class;
protected string $mainSprinkle = Demo::class;

/**
* Test index (`/`) page.
Expand All @@ -35,4 +33,18 @@ public function testPageIndex(): void
$this->assertResponseStatus(200, $response);
$this->assertNotSame('', (string) $response->getBody());
}

/**
* Test api (`/api`) page.
*/
public function testApiIndex(): void
{
// Create request with method and url and fetch response
$request = $this->createRequest('GET', '/api');
$response = $this->handleRequest($request);

// Asserts
$this->assertResponseStatus(200, $response);
$this->assertJson((string) $response->getBody());
}
}
4 changes: 2 additions & 2 deletions bakery
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
}

use UserFrosting\Bakery\Bakery;
use UserFrosting\Demo\UiKitTheme;
use UserFrosting\Demo\Demo;

/**
* Get and run CLI App
*/
$bakery = new Bakery(UiKitTheme::class);
$bakery = new Bakery(Demo::class);
$bakery->run();
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/phpstan": "^1.1",
"mockery/mockery": "^1.2",
"phpunit/phpunit": "^9.5"
},
"minimum-stability": "dev",
Expand Down
12 changes: 6 additions & 6 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

/*
* UserFrosting (http://www.userfrosting.com)
* UserFrosting Vue Demo (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/UserFrosting
* @copyright Copyright (c) 2021 Alexander Weissman & Louis Charette
* @license https://github.com/userfrosting/UserFrosting/blob/master/LICENSE.md (MIT License)
* @link https://github.com/userfrosting/demo-vue
* @copyright Copyright (c) 2023 Louis Charette
* @license https://github.com/userfrosting/demo-vue/blob/main/LICENSE.md (MIT License)
*/

/**
Expand All @@ -21,8 +21,8 @@
$_SERVER['SCRIPT_NAME'] = '/index.php';
}

use UserFrosting\Demo\UiKitTheme;
use UserFrosting\Demo\Demo;
use UserFrosting\UserFrosting;

$uf = new UserFrosting(UiKitTheme::class);
$uf = new UserFrosting(Demo::class);
$uf->run();

0 comments on commit 0edd1ae

Please sign in to comment.