Add phpunit.xml.dist + phpunit GH action

pull/3904/head
Julio Montoya 4 years ago
parent d1c3e432db
commit ad8d4a1e41
  1. 12
      .env.test
  2. 57
      .github/workflows/phpunit.yml
  3. 1
      ecs.php
  4. 39
      phpunit.xml.dist
  5. 2
      tests/CoreBundle/Controller/IndexControllerTest.php
  6. 16
      tests/CoreBundle/Repository/Node/AccessUrlRepositoryTest.php

@ -0,0 +1,12 @@
# define your env variables for the test env here
KERNEL_CLASS='Chamilo\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
DATABASE_HOST='127.0.0.1'
DATABASE_PORT='3306'
DATABASE_NAME='chamilo_test'
DATABASE_USER='chamilo'
DATABASE_PASSWORD='chamilo'

@ -0,0 +1,57 @@
name: PHPUnit ✏🐛
on: [push, pull_request]
jobs:
build:
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['8.0']
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, xml, ctype, iconv, intl, pdo, pdo_mysql, dom, gd, json, soap, zip, bcmath
ini-values: post_max_size=256M, max_execution_time=600, memory_limit=4096M
- name: Start mysql service
run: |
sudo /etc/init.d/mysql start
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v2
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 with composer
run: composer install --prefer-dist --no-progress --optimize-autoloader
- name: Install PHPUnit
run: vendor/bin/simple-phpunit --version
- name: Setup test database
run: |
php bin/console --env=test cache:clear
php bin/console --env=test doctrine:database:create
php bin/console --env=test doctrine:schema:create
php bin/console --env=test doctrine:fixtures:load
- name: Run PHPUnit tests
run: php bin/phpunit

@ -99,7 +99,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
__DIR__.'/src/CoreBundle/Component/HTMLPurifier/Filter/AllowIframes.php',
__DIR__.'/src/CoreBundle/Traits/*',
__DIR__.'/src/CourseBundle/Component/*',
__DIR__.'/src/DataFixtures/*',
IncrementStyleFixer::class => 'post',
PropertyTypeHintSniff::class.'.'.PropertyTypeHintSniff::CODE_MISSING_TRAVERSABLE_TYPE_HINT_SPECIFICATION,
PropertyTypeHintSniff::class.'.'.PropertyTypeHintSniff::CODE_MISSING_NATIVE_TYPE_HINT,

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="tests/bootstrap.php"
>
<php>
<ini name="error_reporting" value="-1" />
<server name="APP_ENV" value="test" force="true" />
<server name="SHELL_VERBOSITY" value="-1" />
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<extensions>
<extension class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension"/>
<!-- Run `composer require symfony/panther` before enabling this extension -->
<!--
<extension class="Symfony\Component\Panther\ServerExtension" />
-->
</extensions>
</phpunit>

@ -17,7 +17,7 @@ class IndexControllerTest extends WebTestCase
$this->assertEquals(Response::HTTP_OK, $client->getResponse()->getStatusCode());
}*/
public function testLogin()
public function testLoginPage()
{
$client = static::createClient();
$client->request('GET', '/login');

@ -0,0 +1,16 @@
<?php
namespace Chamilo\Tests\CoreBundle\Repository\Node;
use Chamilo\CoreBundle\Repository\Node\AccessUrlRepository;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class AccessUrlRepositoryTest extends KernelTestCase
{
public function testCount()
{
self::bootKernel();
$count = self::getContainer()->get(AccessUrlRepository::class)->count([]);
$this->assertEquals(1, $count);
}
}
Loading…
Cancel
Save