Skip to content

Commit 2fd7b74

Browse files
authored
Option to listen to postRemove event (#96)
* Option to listen to postRemove event * Add more testing * Fix cs * Update code style * Add phpstan * Remove deprecated composer option * Dependabot config for updating github action versions, add phpstan to checks * Rename linter * Test if deleting is async and test needs to wait * 2 seconds wait might be enough * Fix cs * Fix comparison * Fix cs
1 parent f259799 commit 2fd7b74

33 files changed

+251
-262
lines changed

.editorconfig

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,7 @@ trim_trailing_whitespace = true
77
insert_final_newline = true
88
end_of_line = lf
99
charset = utf-8
10-
tab_width = 4
1110
indent_style = space
12-
13-
[*.php]
14-
indent_size = 4
15-
16-
[*{.xml, .dist}]
1711
indent_size = 4
12+
max_line_length = 120
1813

19-
[*.md]
20-
max_line_length = 80
21-
22-
[*{.yaml, .yml}]
23-
indent_size = 4
24-
25-
[*.json]
26-
indent_size = 4

.github/dependabot.yml

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
version: 2
2+
23
updates:
3-
- package-ecosystem: composer
4-
directory: "/"
5-
schedule:
6-
interval: daily
7-
time: "04:00"
8-
open-pull-requests-limit: 10
9-
labels:
10-
- dependencies
11-
- skip-changelog
12-
rebase-strategy: disabled
4+
- package-ecosystem: composer
5+
directory: "/"
6+
schedule:
7+
interval: daily
8+
time: "04:00"
9+
open-pull-requests-limit: 10
10+
labels:
11+
- dependencies
12+
- skip-changelog
13+
rebase-strategy: disabled
14+
15+
- package-ecosystem: "github-actions"
16+
directory: "/"
17+
schedule:
18+
interval: daily
19+
time: "04:00"
20+
commit-message:
21+
include: "scope"
22+
prefix: "github-actions"
23+
labels:
24+
- dependencies
25+
- skip-changelog
26+
open-pull-requests-limit: 10

.github/workflows/tests.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,33 @@ jobs:
2525
- name: Validate composer.json and composer.lock
2626
run: composer validate
2727
- name: Install dependencies
28-
run: composer install --prefer-dist --no-progress --no-suggest
28+
run: composer install --prefer-dist --no-progress --quiet
2929
- name: MeiliSearch setup with Docker
3030
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey --no-analytics=true
31+
- name: Check
32+
run: curl http://127.0.0.1:7700
3133
- name: Run test suite
3234
run: composer test:unit
3335

34-
linter:
36+
code-style:
3537
runs-on: ubuntu-latest
36-
name: linter-check
38+
name: 'Code style'
3739
steps:
3840
- uses: actions/checkout@v2
41+
3942
- name: Install PHP
4043
uses: shivammathur/setup-php@v2
4144
with:
4245
php-version: '7.4'
46+
4347
- name: Validate composer.json and composer.lock
4448
run: composer validate
49+
4550
- name: Install dependencies
46-
run: composer install --prefer-dist --no-progress --no-suggest
47-
- name: Run linter
51+
run: composer install --prefer-dist --no-progress --quiet
52+
53+
- name: PHP CS Fixer
4854
run: composer lint:check
55+
56+
- name: PHPstan
57+
run: composer phpstan

.gitignore

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
.idea
2-
/composer.lock
2+
3+
composer.lock
34
/vendor/
4-
.phpunit.result.cache
55
/var/
6+
7+
# Meilisearch
8+
/data.ms/*
9+
10+
# PhpUnit
11+
.phpunit.result.cache
612
.php-cs-fixer.cache
13+
/tests/coverage

.php-cs-fixer.dist.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22

33
declare(strict_types=1);
44

5-
if (!file_exists(__DIR__.'/src')) {
6-
exit(0);
7-
}
8-
95
$finder = PhpCsFixer\Finder::create()
106
->in(__DIR__.'/src')
117
->in(__DIR__.'/tests')
128
->append([__FILE__]);
139
$config = new PhpCsFixer\Config();
10+
1411
$config->setRules([
1512
'@Symfony' => true,
16-
'declare_strict_types' => true,
13+
'@PHP80Migration:risky' => true,
1714
'global_namespace_import' => [
1815
'import_classes' => false,
1916
'import_functions' => false,

composer.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
"doctrine/orm": "^2.9",
3232
"friendsofphp/php-cs-fixer": "^3.0",
3333
"nyholm/psr7": "^1.3",
34+
"phpstan/extension-installer": "^1.1",
35+
"phpstan/phpstan": "^0.12.90",
36+
"phpstan/phpstan-doctrine": "^0.12.39",
37+
"phpstan/phpstan-phpunit": "^0.12.20",
38+
"phpstan/phpstan-symfony": "^0.12.37",
39+
"phpunit/php-code-coverage": "^9.2",
3440
"phpunit/phpunit": "^9.5",
3541
"symfony/doctrine-bridge": "^4.0 || ^5.0",
3642
"symfony/http-client": "^4.0 || ^5.0",
@@ -51,8 +57,10 @@
5157
"sort-packages": true
5258
},
5359
"scripts": {
54-
"test:unit": "phpunit --colors=always --verbose",
55-
"lint:check": "php-cs-fixer fix -v --using-cache=no --dry-run",
56-
"lint:fix": "php-cs-fixer fix -v --using-cache=no"
60+
"phpstan": "./vendor/bin/phpstan --memory-limit=128 --ansi",
61+
"test:unit": "./vendor/bin/phpunit --colors=always --verbose",
62+
"test:unit:coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --colors=always --coverage-html=tests/coverage",
63+
"lint:check": "./vendor/bin/php-cs-fixer fix -v --using-cache=no --dry-run",
64+
"lint:fix": "./vendor/bin/php-cs-fixer fix -v --using-cache=no"
5765
}
5866
}

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
level: 5
3+
paths:
4+
- src
5+
- tests

phpunit.xml.dist

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" convertDeprecationsToExceptions="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage>
4-
<include>
5-
<directory>src/</directory>
6-
</include>
7-
<exclude>
8-
<file>src/DependencyInjection/MeiliSearchExtension.php</file>
9-
<file>src/Services/NullSearchService.php</file>
10-
</exclude>
11-
</coverage>
12-
<php>
13-
<env name="KERNEL_CLASS" value="MeiliSearch\Bundle\Test\Kernel"/>
14-
<env name="APP_ENV" value="test"/>
15-
<env name="APP_DEBUG" value="false"/>
16-
<env name="MEILISEARCH_PREFIX" value="sf_phpunit_"/>
17-
<env name="MEILISEARCH_URL" value="http://127.0.0.1:7700"/>
18-
<env name="MEILISEARCH_API_KEY" value="masterKey"/>
19-
<env name="TRAVIS_JOB_NUMBER" value=""/>
20-
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
21-
</php>
22-
<testsuites>
23-
<testsuite name="TestCase">
24-
<directory suffix=".php">tests/TestCase/</directory>
25-
</testsuite>
26-
</testsuites>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php"
3+
convertDeprecationsToExceptions="false"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd">
5+
<coverage>
6+
<include>
7+
<directory>src/</directory>
8+
</include>
9+
</coverage>
10+
<php>
11+
<env name="KERNEL_CLASS" value="MeiliSearch\Bundle\Test\Kernel"/>
12+
<env name="APP_ENV" value="test"/>
13+
<env name="APP_DEBUG" value="false"/>
14+
<env name="MEILISEARCH_PREFIX" value="sf_phpunit_"/>
15+
<env name="MEILISEARCH_URL" value="http://127.0.0.1:7700"/>
16+
<env name="MEILISEARCH_API_KEY" value="masterKey"/>
17+
<env name="TRAVIS_JOB_NUMBER" value=""/>
18+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
19+
</php>
20+
<testsuites>
21+
<testsuite name="Integration">
22+
<directory suffix=".php">tests/Integration</directory>
23+
</testsuite>
24+
<testsuite name="Unit">
25+
<directory suffix=".php">tests/Unit</directory>
26+
</testsuite>
27+
</testsuites>
2728
</phpunit>

src/Command/IndexCommand.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $o
4242

4343
if ($indexList = $input->getOption('indices')) {
4444
$list = \explode(',', $indexList);
45-
$indexNames = collect($list)->transform(function (string $item) {
45+
$indexNames = collect($list)->transform(function (string $item): string {
4646
// Check if the given index name already contains the prefix
4747
if (false === strpos($item, $this->prefix)) {
4848
return $this->prefix.$item;
@@ -64,8 +64,6 @@ protected function getEntitiesFromArgs(InputInterface $input, OutputInterface $o
6464
);
6565
}
6666

67-
return collect($this->getIndices())->reject(function (array $item) use ($indexNames) {
68-
return !in_array($item['name'], $indexNames->toArray(), true);
69-
});
67+
return collect($this->getIndices())->reject(fn (array $item) => !in_array($item['name'], $indexNames->toArray(), true));
7068
}
7169
}

src/Command/MeiliSearchClearCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class MeiliSearchClearCommand extends IndexCommand
1515
{
1616
protected static $defaultName = 'meili:clear';
1717

18-
protected function configure()
18+
protected function configure(): void
1919
{
2020
$this
2121
->setDescription('Clear the index documents')
@@ -26,7 +26,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
2626
{
2727
$indexToClear = $this->getEntitiesFromArgs($input, $output);
2828

29-
/** @var array $index */
29+
/** @var array<string, mixed> $index */
3030
foreach ($indexToClear as $index) {
3131
$indexName = $index['name'];
3232
$className = $index['class'];

0 commit comments

Comments
 (0)