Skip to content

Commit

Permalink
ISSUE-337: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
tatevikg1 committed Dec 16, 2024
1 parent ff1e96c commit a3e3f93
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 180 deletions.
25 changes: 8 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
DB_DATABASE: phplist
DB_USERNAME: root
DB_PASSWORD: phplist
BROADCAST_DRIVER: log
BROADCAST_DRIVER: log
services:
mysql:
image: mysql:5.7
Expand All @@ -22,17 +22,21 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0']
# dependencies: ['latest', 'oldest']
php-versions: ['8.1']
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, mysql
coverage: xdebug #optional
- name: Install Symfony CLI
run: |
curl -sS https://get.symfony.com/cli/installer | bash
mv $HOME/.symfony*/bin/symfony /usr/local/bin/symfony
symfony version
- name: Start mysql service
run: sudo /etc/init.d/mysql start
- name: Verify MySQL connection on host
Expand All @@ -44,36 +48,23 @@ jobs:
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 the latest dependencies
run: composer install
continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
# - name: Install lowest dependencies from
# run: composer update --with-dependencies --prefer-stable --prefer-dist --prefer-lowest
# if: ${{ matrix.dependencies }} == "oldest"
- name: Set up database schema
run: mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -u${{ env.DB_USERNAME }} -p${{ env.DB_PASSWORD }} ${{ env.DB_DATABASE }} < vendor/phplist/core/resources/Database/Schema.sql
continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
- name: Validating composer.json
run: composer validate --no-check-all --no-check-lock --strict;
continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
- name: Linting all php files
run: find src/ tests/ public/ -name ''*.php'' -print0 | xargs -0 -n 1 -P 4 php -l; php -l;
- name: Running integration tests with phpunit
run: vendor/bin/phpunit tests/Integration/;
continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
- name: Running the system tests
run: vendor/bin/phpunit tests/System/;
continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
- name: Running static analysis
run: vendor/bin/phpstan analyse -l 5 src/ tests/;
continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
- name: Running PHPMD
run: vendor/bin/phpmd src/ text vendor/phplist/core/config/PHPMD/rules.xml;
continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
- name: Running PHP_CodeSniffer
run: vendor/bin/phpcs --standard=vendor/phplist/core/config/PhpCodeSniffer/ src/ tests/;
continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
/public/
/var/
/vendor/
.phpunit.result.cache
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ This project adheres to [Semantic Versioning](https://semver.org/).

### Fixed

## 5.0.0-alpha1

### Changed
- updated to php8.1

## 4.0.0-alpha2

### Added
Expand Down
19 changes: 5 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
"phplist/core": "dev-ISSUE-337"
},
"require-dev": {
"phpunit/phpunit": "^9.5.2",
"phpunit/phpunit-mock-objects": "^6.1.2",
"phpunit/phpunit": "^9.5",
"guzzlehttp/guzzle": "^7.2.0",
"squizlabs/php_codesniffer": "^3.5.8",
"phpstan/phpstan": " ^0.12.57",
"phpstan/phpstan": "^1.10",
"nette/caching": "^3.1.0",
"nikic/php-parser": "^v4.10.4",
"phpmd/phpmd": "^2.9.1"
"phpmd/phpmd": "^2.9.1",
"symfony/process": "^6.4"
},
"autoload": {
"psr-4": {
Expand All @@ -52,15 +52,6 @@
"PhpList\\WebFrontend\\Tests\\": "tests/"
}
},
"repositories": [
{
"type": "path",
"url": "../core",
"options": {
"symlink": true
}
}
],
"scripts": {
"list-modules": [
"PhpList\\Core\\Composer\\ScriptHandler::listModules"
Expand All @@ -87,7 +78,7 @@
},
"extra": {
"branch-alias": {
"dev-ISSUE-337": "v5.0.x-dev"
"dev-ISSUE-337": "5.0.x-dev"
},
"symfony-app-dir": "bin",
"symfony-bin-dir": "bin",
Expand Down
136 changes: 29 additions & 107 deletions tests/Integration/Composer/ScriptsTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace PhpList\WebFrontend\Tests\Integration\Composer;
Expand All @@ -12,148 +13,69 @@
*/
class ScriptsTest extends TestCase
{
/**
* @test
*/
public function publicDirectoryHasBeenCreated()
{
static::assertDirectoryExists($this->getAbsolutePublicDirectoryPath());
}

/**
* @return string
*/
private function getAbsolutePublicDirectoryPath(): string
{
return dirname(__DIR__, 3) . '/public/';
}

/**
* @return string[][]
*/
public function publicDirectoryFilesDataProvider(): array
{
return [
'production entry point' => ['app.php'],
'development entry point' => ['app_dev.php'],
'testing entry point' => ['app_test.php'],
'.htaccess' => ['.htaccess'],
];
}

/**
* @test
* @param string $fileName
* @dataProvider publicDirectoryFilesDataProvider
*/
public function publicDirectoryFilesExist(string $fileName)
{
static::assertFileExists($this->getAbsolutePublicDirectoryPath() . $fileName);
}

/**
* @test
*/
public function binariesDirectoryHasBeenCreated()
private function getBundleConfigurationFilePath(): string
{
static::assertDirectoryExists($this->getAbsoluteBinariesDirectoryPath());
return dirname(__DIR__, 3) . '/config/bundles.yml';
}

/**
* @return string
*/
private function getAbsoluteBinariesDirectoryPath(): string
public function testBundleConfigurationFileExists(): void
{
return dirname(__DIR__, 3) . '/bin/';
self::assertFileExists($this->getBundleConfigurationFilePath());
}

/**
* @return string[][]
*/
public function binariesDataProvider(): array
public function bundleClassNameDataProvider(): array
{
return [
'Symfony console' => ['console'],
'Symfony framework bundle' => ['Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'],
'Doctrine bundle' => ['Doctrine\\Bundle\\DoctrineBundle\\DoctrineBundle'],
'empty start page bundle' => ['PhpList\\Core\\EmptyStartPageBundle\\EmptyStartPageBundle'],
];
}

/**
* @test
* @param string $fileName
* @dataProvider binariesDataProvider
* @dataProvider bundleClassNameDataProvider
*/
public function binariesExist(string $fileName)
public function testBundleConfigurationFileContainsModuleBundles(string $bundleClassName): void
{
static::assertFileExists($this->getAbsoluteBinariesDirectoryPath() . $fileName);
$fileContents = file_get_contents($this->getBundleConfigurationFilePath());
self::assertStringContainsString($bundleClassName, $fileContents);
}

/**
* @return string
*/
private function getBundleConfigurationFilePath(): string
private function getModuleRoutesConfigurationFilePath(): string
{
return dirname(__DIR__, 3) . '/config/bundles.yml';
return dirname(__DIR__, 3) . '/config/routing_modules.yml';
}

/**
* @test
*/
public function bundleConfigurationFileExists()
public function testModuleRoutesConfigurationFileExists(): void
{
static::assertFileExists($this->getBundleConfigurationFilePath());
self::assertFileExists($this->getModuleRoutesConfigurationFilePath());
}

/**
* @return string[][]
*/
public function bundleClassNameDataProvider(): array
public function moduleRoutingDataProvider(): array
{
return [
'framework bundle' => ['Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'],
'route name' => ['phplist/core.homepage'],
'resource' => ["resource: '@EmptyStartPageBundle/Controller/'"],
'type' => ['type: attribute'],
];
}

/**
* @test
* @param string $bundleClassName
* @dataProvider bundleClassNameDataProvider
*/
public function bundleConfigurationFileContainsModuleBundles(string $bundleClassName)
{
$fileContents = file_get_contents($this->getBundleConfigurationFilePath());

static::assertContains($bundleClassName, $fileContents);
}

/**
* @return string
*/
private function getModuleRoutesConfigurationFilePath(): string
{
return dirname(__DIR__, 3) . '/config/routing_modules.yml';
}

/**
* @test
* @dataProvider moduleRoutingDataProvider
*/
public function moduleRoutesConfigurationFileExists()
public function testModuleRoutesConfigurationFileContainsModuleRoutes(string $routeSearchString): void
{
static::assertFileExists($this->getModuleRoutesConfigurationFilePath());
$fileContents = file_get_contents($this->getModuleRoutesConfigurationFilePath());
self::assertStringContainsString($routeSearchString, $fileContents);
}

/**
* @test
*/
public function parametersConfigurationFileExists()
public function testParametersConfigurationFileExists(): void
{
static::assertFileExists(dirname(__DIR__, 3) . '/config/parameters.yml');
self::assertFileExists(dirname(__DIR__, 3) . '/config/parameters.yml');
}

/**
* @test
*/
public function modulesConfigurationFileExists()
public function testModulesConfigurationFileExists(): void
{
static::assertFileExists(dirname(__DIR__, 3) . '/config/config_modules.yml');
self::assertFileExists(dirname(__DIR__, 3) . '/config/config_modules.yml');
}
}
60 changes: 18 additions & 42 deletions tests/System/ApplicationBundle/PhpListApplicationBundleTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace PhpList\WebFrontend\Tests\System\ApplicationBundle;
Expand All @@ -16,57 +17,32 @@ class PhpListApplicationBundleTest extends TestCase
{
use SymfonyServerTrait;

/**
* @var Client
*/
private $httpClient = null;
private ?Client $httpClient = null;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->httpClient = new Client(['http_errors' => false]);
}

protected function tearDown()
protected function tearDown(): void
{
$this->stopSymfonyServer();
$this->httpClient = null;
parent::tearDown();
}

/**
* @return string[][]
*/
public function environmentDataProvider(): array
{
return [
'test' => ['test'],
'dev' => ['dev'],
];
}

/**
* @test
* @param string $environment
* @dataProvider environmentDataProvider
*/
public function homepageReturnsSuccess(string $environment)
public function testHomepageReturnsSuccess(): void
{
$this->startSymfonyServer($environment);

$response = $this->httpClient->get('/', ['base_uri' => $this->getBaseUrl()]);

static::assertSame(200, $response->getStatusCode());
}

/**
* @test
* @param string $environment
* @dataProvider environmentDataProvider
*/
public function homepageReturnsContent(string $environment)
{
$this->startSymfonyServer($environment);

$response = $this->httpClient->get('/', ['base_uri' => $this->getBaseUrl()]);

static::assertNotEmpty($response->getBody()->getContents());
$this->startSymfonyServer();
$response = $this->httpClient->get('/api/v2', [
'base_uri' => $this->getBaseUrl(),
]);

self::assertSame(200, $response->getStatusCode());
self::assertStringContainsString(
'This page has been intentionally left empty.',
$response->getBody()->getContents()
);
}
}

0 comments on commit a3e3f93

Please sign in to comment.