mirror of
https://gitlab.com/ruany/litebans-php.git
synced 2025-05-23 08:29:06 +00:00
[CI] Set up PHPUnit and first unit test
This commit is contained in:
parent
477ccd601a
commit
3d393e5719
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
.idea
|
||||
litebans-php.iml
|
||||
inc/test/vendor
|
||||
inc/test/composer.lock
|
||||
|
@ -1,10 +1,9 @@
|
||||
# This file is a template, and might need editing before it works on your project.
|
||||
# Select image from https://hub.docker.com/_/php/
|
||||
image: php:latest
|
||||
|
||||
# Select what we should cache between builds
|
||||
cache:
|
||||
paths:
|
||||
- inc/test/vendor/
|
||||
- vendor/
|
||||
|
||||
before_script:
|
||||
@ -23,16 +22,18 @@ before_script:
|
||||
- pecl install xdebug
|
||||
- docker-php-ext-enable xdebug
|
||||
# Install and run Composer
|
||||
#- curl -sS https://getcomposer.org/installer | php
|
||||
#- php composer.phar install
|
||||
- curl -sS https://getcomposer.org/installer | php
|
||||
- php composer.phar install
|
||||
- php composer.phar require --dev phpunit/phpunit ^9
|
||||
|
||||
# Bring in any services we need http://docs.gitlab.com/ee/ci/docker/using_docker_images.html#what-is-a-service
|
||||
# See http://docs.gitlab.com/ce/ci/services/README.html for examples.
|
||||
services:
|
||||
- mysql:5.7
|
||||
services: []
|
||||
# - mysql:5.7
|
||||
|
||||
# Set any variables we need
|
||||
variables:
|
||||
COMPOSER: 'inc/test/composer.json'
|
||||
# Configure mysql environment variables (https://hub.docker.com/r/_/mysql/)
|
||||
MYSQL_DATABASE: mysql_database
|
||||
MYSQL_ROOT_PASSWORD: mysql_strong_password
|
||||
@ -41,4 +42,4 @@ variables:
|
||||
# If Xdebug was installed you can generate a coverage report and see code coverage metrics.
|
||||
test:
|
||||
script:
|
||||
- vendor/bin/phpunit --configuration phpunit.xml --coverage-text --colors=never
|
||||
- ./vendor/bin/phpunit inc/test/php
|
||||
|
10
inc/test/composer.json
Normal file
10
inc/test/composer.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"inc/"
|
||||
]
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9"
|
||||
}
|
||||
}
|
23
inc/test/php/LangTest.php
Normal file
23
inc/test/php/LangTest.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class LangTest extends TestCase {
|
||||
public function testLanguages(): void {
|
||||
$langs = glob('./lang/*.php');
|
||||
foreach ($langs as $lang) {
|
||||
include_once $lang;
|
||||
$lang_class = $lang;
|
||||
$lang_class = substr($lang_class, 0, strpos($lang_class, ".")); // grab "lang/en_US" from "en_US.utf8.php"
|
||||
$lang_class = substr($lang_class, strlen("lang/")); // grab "en_US" from "lang/en_US"
|
||||
|
||||
$instance = new $lang_class;
|
||||
$this->assertTrue(is_array($instance->array));
|
||||
|
||||
$count = sizeof($instance->array);
|
||||
$this->assertTrue($count > 0);
|
||||
|
||||
echo "Language $lang_class is valid. $count messages defined.";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user