Skip to content

Commit

Permalink
Setup for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusa87 committed Dec 15, 2024
1 parent 12effbb commit 74e2d6a
Show file tree
Hide file tree
Showing 50 changed files with 688 additions and 97 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

name: "Coding Standards"

on:
pull_request:
branches:
- "*"
push:
branches:
- "*"

jobs:
coding-standards:
name: "Coding Standards"
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: true
matrix:
php-version:
- "8.3"
- "8.4"
operating-system: [ubuntu-24.04]
composer-versions:
- lowest
- highest

steps:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "xdebug"
php-version: "#{{ matrix.php-version }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.composer-versions}}"
- name: "Run PHPCS"
run: |
composer run test-phpcs
- name: "Run rector"
run: |
composer run test-rector
- name: "Run phpstan"
run: |
composer run phpstan
- name: "Run phpunit"
run: |
composer run phpunit
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
vendor/
composer.lock
phpunit.xml
phpunit.xml
.php-cs-fixer.php
.php-cs-fixer.cache
.phpunit.result.cache
tests/coverage
!tests/coverage/.gitkeep
.phpunit.cache
24 changes: 24 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* @see https://cs.symfony.com/doc/rules/index.html
*/
$finder = PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
;

return (new PhpCsFixer\Config('typesense-bundle'))
->setRules([
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'none'],
'phpdoc_align' => ['align' => 'vertical'],
'yoda_style' => false, // Disable Yoda conditions for readability
'no_unused_imports' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'single_line_throw' => false,
])
->setLineEnding(PHP_EOL)
->setFinder($finder)
;
17 changes: 14 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
FROM php:8.2-cli
COPY --from=composer /usr/bin/composer /usr/bin/composer
FROM php:8.3-cli
RUN apt-get update && apt-get install -y git unzip && rm -Rf /var/lib/apt/lists/*

COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN mkdir -p /.composer/cache/ && chown -R 1000:1000 /.composer/cache/
USER 1000:1000

ENV XDEBUG_MODE=off
COPY --from=ghcr.io/mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions xdebug
RUN echo ' \n\
[xdebug] \n\
xdebug.enable=1 \n\
xdebug.idekey=PHPSTORM \n\
xdebug.client_host=host.docker.internal\n ' >> /usr/local/etc/php/conf.d/xdebug.ini

USER www-data
USER 1000:1000
45 changes: 31 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@
"name": "biblioteca/typesense-bundle",
"description": "This bundle provides integration with Typesense in Symfony",
"type": "symfony-bundle",
"minimum-stability": "dev",
"minimum-stability": "stable",
"require": {
"php": ">=8.2",
"php-http/discovery": "^1.20",
"psr/http-client": "^1.0",
"psr/http-client-implementation": "*",
"psr/log": "^1.1",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/http-client": "*",
"symfony/http-client": "^7.2",
"symfony/http-kernel": "^6.4|^7.0",
"typesense/typesense-php": "^4.9"
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.0",
"doctrine/orm": "^3.0",
"friendsofphp/php-cs-fixer": "dev-master",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-symfony": "^2.0",
"phpunit/phpunit": "^11.5",
"rector/rector": "^2.0"
"rector/rector": "^2.0",
"symfony/phpunit-bridge": "^7.0",
"symfony/yaml": "^7.0"
},
"conflict": {
"php-http/httplug": "<1.5"
},
"config": {
"sort-packages": true,
Expand All @@ -29,6 +41,7 @@
},
"autoload-dev": {
"psr-4": {
"Biblioteca\\TypesenseBundle\\Tests\\": "tests"
}
},
"scripts": {
Expand All @@ -38,31 +51,35 @@

"phpstan": [
"Composer\\Config::disableProcessTimeout",
"env XDEBUG_MODE=off ./vendor/bin/phpstan analyse --memory-limit=-1"
"./vendor/bin/phpstan analyse --memory-limit=-1"
],
"test-phpcs": [
"Composer\\Config::disableProcessTimeout",
"./vendor/bin/php-cs-fixer fix --dry-run --verbose -vv"
],
"phpcs": [
"Composer\\Config::disableProcessTimeout",
"env XDEBUG_MODE=off ./vendor/bin/php-cs-fixer fix --dry-run --verbose -vv"
"./vendor/bin/php-cs-fixer fi --verbose -vv"
],
"test-rector": [
"Composer\\Config::disableProcessTimeout",
"env XDEBUG_MODE=off ./vendor/bin/rector --dry-run"
"./vendor/bin/rector --dry-run"
],
"rector": [
"Composer\\Config::disableProcessTimeout",
"env XDEBUG_MODE=off ./vendor/bin/rector"
"./vendor/bin/rector"
],
"test-phpunit": [
"phpunit": [
"Composer\\Config::disableProcessTimeout",
"env XDEBUG_MODE=off php -d memory_limit=-1 ./vendor/bin/phpunit --colors=always"
"php -d memory_limit=-1 ./vendor/bin/phpunit --colors=always"
],
"test-phpunit-coverage": [
"phpunit-coverage": [
"Composer\\Config::disableProcessTimeout",
"env XDEBUG_MODE=coverage php -d memory_limit=-1 ./vendor/bin/phpunit --colors=always --coverage-html=tests/coverage"
],
"test-phpunit-xdebug": [
"phpunit-xdebug": [
"Composer\\Config::disableProcessTimeout",
"env XDEBUG_MODE=debug XDEBUG_TRIGGER=1 php -d memory_limit=-1 ./vendor/bin/phpunit --colors=always"
"env XDEBUG_MODE=debug,coverage XDEBUG_TRIGGER=1 php -d memory_limit=-1 ./vendor/bin/phpunit --colors=always"
],
"lint": [
"@rector",
Expand All @@ -71,9 +88,9 @@
],
"test": [
"@test-phpcs",
"@test-phpstan",
"@phpstan",
"@test-rector",
"@test-phpunit"
"@phpunit"
]
}
}
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ services:
- .:/var/www/html
stdin_open: true
tty: true
environment:
- PHP_IDE_CONFIG=serverName=typesensebundle
extra_hosts:
- host.docker.internal:host-gateway
networks:
- default
# typesense:
Expand Down
41 changes: 32 additions & 9 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
set shell := ["docker", "compose", "run", "-it", "--user=1000", "--rm", "php", "/usr/bin/composer"]
composer *args:
{{args}}
set shell := ["docker", "compose", "run", "--entrypoint", "/bin/sh", "-it", "--user=1000", "--rm", "php", "-c"]
composer *args="":
/usr/bin/composer {{args}}

sh *args="":
sh {{args}}

php *args="":
php {{args}}

install:
install
composer install

tests:
test
update:
update
composer run test

update *args="":
composer update {{args}}

lint:
lint
composer run lint

rector:
rector
rector

test-phpcs:
composer run test-phpcs

phpcs:
composer run phpcs

phpunit *args="":
env XDEBUG_MODE=coverage composer run phpunit -- {{args}}

phpunit-xdebug *args="":
composer phpunit-xdebug -- {{args}}

phpstan *args="":
composer phpstan -- {{args}}
17 changes: 17 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
parameters:
tipsOfTheDay: false
level: max
paths:
- src/
- tests/
ignoreErrors:
- '#(.*)no value type specified in iterable type array#'
-
identifier: 'method.notFound'
path: src/BibliotecaTypesenseBundle.php
-
identifier: 'method.nonObject'
path: src/BibliotecaTypesenseBundle.php
-
identifier: 'argument.type'
path: src/BibliotecaTypesenseBundle.php
35 changes: 35 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd" bootstrap="./tests/bootstrap.php" backupGlobals="false" colors="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="TypesenseBundle">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage pathCoverage="false"
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="true">
<report>
<html outputDirectory="tests/coverage/html-coverage" lowUpperBound="50" highLowerBound="90"/>
<text outputFile="tests/coverage/coverage.txt" showUncoveredFiles="false" showOnlySummary="true"/>
</report>

</coverage>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="ignoreFile=./tests/baseline-ignore"/>
</php>

<logging>
<junit outputFile="tests/coverage/junit.xml"/>
<testdoxHtml outputFile="tests/coverage/testdox.html"/>
<testdoxText outputFile="tests/coverage/testdox.txt"/>
</logging>
<source>
<exclude>
<directory suffix=".php">vendor</directory>
</exclude>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
7 changes: 6 additions & 1 deletion src/BibliotecaTypesenseBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
$builder->registerForAutoconfiguration(MapperInterface::class)
->addTag(MapperInterface::TAG_NAME);

foreach ($config['typesense'] as $key => $value) {
/** @var iterable<string,mixed> $typesenseConfig */
$typesenseConfig = $config['typesense'];
foreach ($typesenseConfig as $key => $value) {
$container->parameters()->set('biblioteca_typesense.config.'.$key, $value);
}

Expand All @@ -74,6 +76,9 @@ public function loadExtension(array $config, ContainerConfigurator $container, C

public function loadCollection(array $collections, ContainerConfigurator $container, ContainerBuilder $builder): void
{
/**
* @var array{entity: string} $collection
*/
foreach ($collections as $name => $collection) {
$id = 'biblioteca_typesense.collection.'.$name;
$container->services()
Expand Down
8 changes: 7 additions & 1 deletion src/Client/ClientAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Typesense\Aliases;
use Typesense\Analytics;
use Typesense\Client;
use Typesense\Collection;
use Typesense\Collections;
use Typesense\Debug;
use Typesense\Health;
Expand All @@ -21,7 +22,7 @@ public function __construct(
) {
}

public function __call($name, $arguments)
public function __call(mixed $name, mixed $arguments): mixed
{
return $this->client->$name(...$arguments);
}
Expand Down Expand Up @@ -75,4 +76,9 @@ public function getAnalytics(): Analytics
{
return $this->client->getAnalytics();
}

public function getCollection(string $name): Collection
{
return $this->client->getCollections()[$name];
}
}
Loading

0 comments on commit 74e2d6a

Please sign in to comment.