Skip to content

Commit

Permalink
[MetricsPower] Added unit and feature tests, Added LoggerOptions attr…
Browse files Browse the repository at this point in the history
…ibute
  • Loading branch information
fractalzombie committed Mar 27, 2024
1 parent c86ed0f commit 1ba72b6
Show file tree
Hide file tree
Showing 71 changed files with 1,616 additions and 969 deletions.
1 change: 1 addition & 0 deletions .docker/php/cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ RUN chmod a+x /usr/local/bin/start-consumer && \
# Configure PHP
COPY conf/docker-php-ext-xdebug.ini ${PHP_INI_DIR}/conf.d/docker-php-ext-xdebug.ini
COPY conf/docker-php-ext-opcache.ini ${PHP_INI_DIR}/conf.d/docker-php-ext-opcache.ini
COPY conf/docker-php-ext-opcache.ini ${PHP_INI_DIR}/conf.d/docker-php-ext-apcu.ini
COPY conf/php.production.ini ${PHP_INI_DIR}/php.ini

RUN apk add --no-cache sudo && \
Expand Down
4 changes: 4 additions & 0 deletions .docker/php/cli/conf/docker-php-ext-apcu.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[apcu]
zend_extension=apcu.so

apc.enabled=1
2 changes: 1 addition & 1 deletion .docker/php/cli/conf/docker-php-ext-opcache.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ zend_extension=opcache.so
opcache.enable=0
opcache.jit=tracing
opcache.jit_buffer_size=512M
opcache.preload_user=www-data
opcache.preload_user=www-dataa
opcache.preload=/var/www/html/config/preload.php
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SENTRY_PROFILE_SAMPLE_RATE=1.0

###> prometheus ###
PROMETHEUS_NAMESPACE=project-name
PROMETHEUS_STORAGE=in-memory
PROMETHEUS_REDIS_HOST=redis
PROMETHEUS_REDIS_PORT=6379
PROMETHEUS_REDIS_DATABASE=0
Expand Down
34 changes: 34 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# In all environments, the following files are loaded if they exist,
# the later taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration

###> sentry ###
SENTRY_DSN=https://KEY@INSTANCE.ingest.us.sentry.io/NAMESPACE
SENTRY_ENVIRONMENT=${APP_ENV}
SENTRY_TRACES_SAMPLE_RATE=1.0
SENTRY_PROFILE_SAMPLE_RATE=1.0
###< sentry ###

###> prometheus ###
PROMETHEUS_NAMESPACE=project-name
PROMETHEUS_STORAGE=in-memory
PROMETHEUS_REDIS_HOST=redis
PROMETHEUS_REDIS_PORT=6379
PROMETHEUS_REDIS_DATABASE=0
PROMETHEUS_REDIS_TIMEOUT=0.1
PROMETHEUS_REDIS_READ_TIMEOUT=10
PROMETHEUS_REDIS_PERSISTENT_CONNECTIONS=false
PROMETHEUS_REDIS_PASSWORD=secret
PROMETHEUS_REDIS_URL=redis://${PROMETHEUS_REDIS_PASSWORD}@${PROMETHEUS_REDIS_HOST}
###< prometheus ###
119 changes: 119 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Build

on:
push:
branches:
- main
- develop
- 'releases/**'
paths-ignore:
- '**/*.md'
- '**/*.gitignore'
- '**/*.gitattributes'

pull_request:
types:
- published
- created
- edited
- opened
- synchronize
- reopened
paths-ignore:
- '**/*.md'
- '**/*.gitignore'
- '**/*.gitattributes'

jobs:
build:
name: PHP
runs-on: ubuntu-latest

strategy:
matrix:
php:
- "8.1"
- "8.2"
- "8.3"
include:
- php-version: "8.1"
composer-options: "--ignore-platform-reqs"
- php-version: "8.2"
composer-options: "--ignore-platform-reqs"
- php-version: "8.3"
composer-options: "--ignore-platform-reqs"

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
extensions: mbstring, intl
coverage: xdebug
tools: pecl, phpunit, composer
ini-values: post_max_size=256M

- name: Setup composer
uses: ramsey/composer-install@v1
with:
composer-options: "${{ matrix.composer-options }}"

- name: Validate composer files
run: composer validate

- name: Cache composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --prefer-dist --no-progress

- name: Setup tests directories
run: mkdir -p build/logs

- name: Execute unit tests
run: ./vendor/bin/pest --colors=always --configuration phpunit.xml.dist

- name: Push to Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: php-${{ matrix.php-versions }}
run: |
composer global require php-coveralls/php-coveralls
php-coveralls -v
finish:
needs: [ build ]
runs-on: ubuntu-latest

steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true

sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
84 changes: 0 additions & 84 deletions .github/workflows/ci.yml

This file was deleted.

9 changes: 5 additions & 4 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@
'@PHP82Migration' => true,
'@PHP83Migration' => true,
'@PHPUnit100Migration:risky' => true,
'date_time_immutable' => true,
'single_line_throw' => true,
'date_time_immutable' => true,
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
'php_unit_internal_class' => false,
'phpdoc_align' => ['align' => 'left'],
'php_unit_test_case_static_method_calls' => false,
'php_unit_test_class_requires_covers' => false,
'comment_to_phpdoc' => ['ignored_tags' => ['scrutinizer']],
'phpdoc_to_comment' => ['ignored_tags' => ['scrutinizer']],
'php_unit_test_case_static_method_calls' => false,
'operator_linebreak' => ['position' => 'beginning'],
'curly_braces_position' => ['anonymous_classes_opening_brace' => 'next_line_unless_newline_at_signature_end'],
'phpdoc_line_span' => ['const' => 'single', 'property' => 'single', 'method' => 'single'],
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => true],
'header_comment' => [
Expand Down
4 changes: 2 additions & 2 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ build:
tests:
override:
- php-scrutinizer-run

environment:
php: 8.1.9
php: 8.2

filter:
excluded_paths:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@
* file that was distributed with this source code.
*/

namespace FRZB\Component\MetricsPower\Exception;
namespace FRZB\Component\MetricsPower\Attribute;

use JetBrains\PhpStorm\Immutable;

#[Immutable]
final class MessageBusException extends \RuntimeException
#[\Attribute(\Attribute::TARGET_CLASS)]
final class LoggerOptions implements OptionsInterface
{
public static function fromThrowable(\Throwable $previous): self
{
return new self($previous->getMessage(), (int) $previous->getCode(), $previous);
}
public function __construct() {}
}
6 changes: 2 additions & 4 deletions DependencyInjection/Compiler/CollectorRegistryPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ public function process(ContainerBuilder $container): void
$container
->getDefinition(CollectorRegistry::class)
->setPublic($isPublic)
->setArgument('$storageAdapter', $container->getDefinition(Adapter::class))
;
->setArgument('$storageAdapter', $container->getDefinition(Adapter::class));

$container
->setDefinition(RegistryInterface::class, $container->getDefinition(CollectorRegistry::class))
->setPublic($isPublic)
;
->setPublic($isPublic);
}

private static function getConfiguration(ContainerBuilder $container): array
Expand Down
12 changes: 4 additions & 8 deletions DependencyInjection/Compiler/SentryPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ public function process(ContainerBuilder $container): void

$container
->setDefinition(HubAdapter::class, $hubDefinition)
->setPublic($isPublic)
;
->setPublic($isPublic);

$container
->setAlias(HubInterface::class, HubAdapter::class)
;
->setAlias(HubInterface::class, HubAdapter::class);
}

public static function configureHub(array $config): Definition
Expand All @@ -50,14 +48,12 @@ public static function configureHub(array $config): Definition
$clientBuilder = (new Definition(ClientBuilder::class, [$clientOptions]))->setPublic($isPublic);
$client = (new Definition(ClientInterface::class))
->setPublic($isPublic)
->setFactory([$clientBuilder, 'getClient'])
;
->setFactory([$clientBuilder, 'getClient']);

return (new Definition(HubInterface::class))
->setFactory([HubAdapter::class, 'getInstance'])
->addMethodCall('bindClient', [$client])
->setPublic($isPublic)
;
->setPublic($isPublic);
}

private static function getConfiguration(ContainerBuilder $container): array
Expand Down
3 changes: 1 addition & 2 deletions DependencyInjection/Compiler/StorageAdapterPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public function process(ContainerBuilder $container): void
->getDefinition(Adapter::class)
->setFactory([PrometheusStorageAdapterFactory::class, 'createStorageAdapter'])
->setArgument('$configuration', self::getConfiguration($container))
->setPublic($isPublic)
;
->setPublic($isPublic);
}

private static function getConfiguration(ContainerBuilder $container): array
Expand Down
8 changes: 4 additions & 4 deletions Enum/StorageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ enum StorageType: string
use WithEnumValues;

case Apc = 'apc';
case ApcNg = 'apc_ng';
case ApcNg = 'apc-ng';
case Redis = 'redis';
case RedisNg = 'redis_ng';
case InMemory = 'in_memory';
case RedisNg = 'redis-ng';
case InMemory = 'in-memory';
public const APC = 'apc';
public const APC_NG = 'apc_ng';
public const REDIS = 'redis';
public const REDIS_NG = 'redis_ng';
public const IN_MEMORY = 'in_memory';
public const IN_MEMORY = 'in-memory';
}
Loading

0 comments on commit 1ba72b6

Please sign in to comment.