Skip to content

Commit

Permalink
Merge 3dab989 into ae5aa22
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Apr 9, 2024
2 parents ae5aa22 + 3dab989 commit f2594b9
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ build
vendor
phpunit.xml
/docker/preload.php
/docker/random_data.csv
*.cache
*.phar
.version
28 changes: 18 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,25 @@ RUN cd /app \
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY ./docker/php.ini /usr/local/etc/php/conf.d/docker-z99-php.ini

# Prepare opcode caches
RUN php /app/docker/build-preloader.php \
&& php /app/docker/preload.php
# && echo "opcache.preload=/app/docker/preload.php" >> /usr/local/etc/php/conf.d/docker-z99-php.ini

# Test and warm up caches
RUN time /app/csv-blueprint validate:csv -h \
&& time /app/csv-blueprint validate:schema \
--schema=/app/schema-examples/*.yml \
--schema=/app/schema-examples/*.php \
--schema=/app/schema-examples/*.json -vvv \
# time php /app/docker/build-preloader.php \
# && time php /app/docker/preload.php \
# && echo "opcache.preload=/app/docker/preload.php" >> /usr/local/etc/php/conf.d/docker-z99-php.ini \
# && time /app/csv-blueprint validate:csv -h \
# && time /app/csv-blueprint validate:schema \
# --schema=/app/schema-examples/*.yml \
# --schema=/app/schema-examples/*.php \
# --schema=/app/schema-examples/*.json -vvv \
# && echo "Warm up is ready!" \

RUN time php /app/docker/random-csv.php \
&& time /app/csv-blueprint validate:csv \
--schema=/app/schema-examples/full.yml \
--csv=/app/docker/random_data.csv \
--apply-all=yes \
--report=text --mute-errors > /dev/null \
&& echo "Tests are ready!" \
&& rm /app/docker/random_data.csv \
&& du -sh /app/docker

ENTRYPOINT ["/app/csv-blueprint"]
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ presets: # Include another schema and define an a
# This allows you to pre-validate the file name before processing its contents.
# Feel free to check parent directories as well.
# See: https://www.php.net/manual/en/reference.pcre.pattern.syntax.php
filename_pattern: /demo(-\d+)?\.csv$/i
filename_pattern: /\.csv$/i
# preset: my-preset # See README.md for details.

# Here are default values to parse CSV file.
Expand Down Expand Up @@ -519,12 +519,12 @@ columns:
# Validates whether the input is a country code in ISO 3166-1 standard.
# Available options: "alpha-2" (Ex: "US"), "alpha-3" (Ex: "USA"), "numeric" (Ex: "840").
# The rule uses data from iso-codes: https://salsa.debian.org/iso-codes-team/iso-codes.
is_country_code: alpha-2 # Country code in ISO 3166-1 standard. Examples: "US", "USA", "840"
country_code: alpha-2 # Country code in ISO 3166-1 standard. Examples: "US", "USA", "840"

# Validates whether the input is language code based on ISO 639.
# Available options: "alpha-2" (Ex: "en"), "alpha-3" (Ex: "eng").
# See: https://en.wikipedia.org/wiki/ISO_639.
is_language_code: alpha-2 # Examples: "en", "eng"
language_code: alpha-2 # Examples: "en", "eng"

# Filesystem (with IO!)
is_file_exists: true # Check if file exists on the filesystem (It's FS IO operation!).
Expand Down Expand Up @@ -908,9 +908,11 @@ columns:
rules:
not_empty: true

- name: third_column
rules:
not_empty: true
- name: inherited_column_login
preset: my-preset/login

- name: inherited_column_full_name
preset: my-preset/full_name
```
<!-- auto-update:/full-yml -->

Expand Down
14 changes: 7 additions & 7 deletions docker/php.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@

; Opcache
opcache.enable = 1
opcache.enable_cli = 1
opcache.enable_cli = 0
opcache.interned_strings_buffer = 32
opcache.max_accelerated_files = 10000
opcache.fast_shutdown = 1

; Save opcache data as files on disk
opcache.memory_consumption = 0
opcache.memory_consumption = 100
opcache.save_comments = 1
opcache.lockfile_path = /app/docker/opcache.lock
opcache.file_cache = /app/docker/
opcache.file_cache_only = 1
;opcache.lockfile_path = /app/docker/opcache.lock
;opcache.file_cache = /app/docker/
;opcache.file_cache_only = 1

; Enable aggressive opcache optimization
opcache.validate_timestamps = 0
Expand All @@ -37,8 +37,8 @@ opcache.enable_file_override = 0


; JIT
opcache.jit_buffer_size=100M
opcache.jit=1205
opcache.jit_buffer_size=200M
opcache.jit=tracing


; Base limits
Expand Down
42 changes: 42 additions & 0 deletions docker/random-csv.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* JBZoo Toolbox - Csv-Blueprint.
*
* This file is part of the JBZoo Toolbox project.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT
* @copyright Copyright (C) JBZoo.com, All rights reserved.
* @see https://github.com/JBZoo/Csv-Blueprint
*/

declare(strict_types=1);

$rows = 1000;

$filePath = __DIR__ . '/random_data.csv';

$fileHandle = \fopen($filePath, 'w');

if ($fileHandle === false) {
exit('Error opening the file');
}

$columns = ['Column Name (header)', 'another_column', 'inherited_column_login', 'inherited_column_full_name'];
\fputcsv($fileHandle, $columns);

for ($i = 0; $i < $rows; $i++) {
$rowData = [];

for ($j = 0; $j < \count($columns); $j++) {
$rowData[] = \random_int(1, 10000);
}

\fputcsv($fileHandle, $rowData);
}

\fclose($fileHandle);

echo "CSV file created: {$filePath}.\n";
14 changes: 9 additions & 5 deletions schema-examples/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"my-preset" : ".\/preset_users.yml"
},

"filename_pattern" : "\/demo(-\\d+)?\\.csv$\/i",
"filename_pattern" : "\/\\.csv$\/i",

"csv" : {
"preset" : "my-preset",
Expand Down Expand Up @@ -148,8 +148,8 @@
"is_cardinal_direction" : true,
"is_usa_market_name" : true,

"is_country_code" : "alpha-2",
"is_language_code" : "alpha-2",
"country_code" : "alpha-2",
"language_code" : "alpha-2",

"is_file_exists" : true,
"is_dir_exists" : true,
Expand Down Expand Up @@ -429,8 +429,12 @@
"rules" : {"not_empty" : true}
},
{
"name" : "third_column",
"rules" : {"not_empty" : true}
"name" : "inherited_column_login",
"preset" : "my-preset\/login"
},
{
"name" : "inherited_column_full_name",
"preset" : "my-preset\/full_name"
}
]
}
14 changes: 9 additions & 5 deletions schema-examples/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'my-preset' => './preset_users.yml',
],

'filename_pattern' => '/demo(-\\d+)?\\.csv$/i',
'filename_pattern' => '/\\.csv$/i',

'csv' => [
'preset' => 'my-preset',
Expand Down Expand Up @@ -169,8 +169,8 @@
'is_cardinal_direction' => true,
'is_usa_market_name' => true,

'is_country_code' => 'alpha-2',
'is_language_code' => 'alpha-2',
'country_code' => 'alpha-2',
'language_code' => 'alpha-2',

'is_file_exists' => true,
'is_dir_exists' => true,
Expand Down Expand Up @@ -452,8 +452,12 @@
'rules' => ['not_empty' => true],
],
[
'name' => 'third_column',
'rules' => ['not_empty' => true],
'name' => 'inherited_column_login',
'preset' => 'my-preset/login',
],
[
'name' => 'inherited_column_full_name',
'preset' => 'my-preset/full_name',
],
],
];
14 changes: 8 additions & 6 deletions schema-examples/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ presets: # Include another schema and define an a
# This allows you to pre-validate the file name before processing its contents.
# Feel free to check parent directories as well.
# See: https://www.php.net/manual/en/reference.pcre.pattern.syntax.php
filename_pattern: /demo(-\d+)?\.csv$/i
filename_pattern: /\.csv$/i
# preset: my-preset # See README.md for details.

# Here are default values to parse CSV file.
Expand Down Expand Up @@ -230,12 +230,12 @@ columns:
# Validates whether the input is a country code in ISO 3166-1 standard.
# Available options: "alpha-2" (Ex: "US"), "alpha-3" (Ex: "USA"), "numeric" (Ex: "840").
# The rule uses data from iso-codes: https://salsa.debian.org/iso-codes-team/iso-codes.
is_country_code: alpha-2 # Country code in ISO 3166-1 standard. Examples: "US", "USA", "840"
country_code: alpha-2 # Country code in ISO 3166-1 standard. Examples: "US", "USA", "840"

# Validates whether the input is language code based on ISO 639.
# Available options: "alpha-2" (Ex: "en"), "alpha-3" (Ex: "eng").
# See: https://en.wikipedia.org/wiki/ISO_639.
is_language_code: alpha-2 # Examples: "en", "eng"
language_code: alpha-2 # Examples: "en", "eng"

# Filesystem (with IO!)
is_file_exists: true # Check if file exists on the filesystem (It's FS IO operation!).
Expand Down Expand Up @@ -619,6 +619,8 @@ columns:
rules:
not_empty: true

- name: third_column
rules:
not_empty: true
- name: inherited_column_login
preset: my-preset/login

- name: inherited_column_full_name
preset: my-preset/full_name
14 changes: 8 additions & 6 deletions schema-examples/full_clean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ description: |
presets:
my-preset: ./preset_users.yml

filename_pattern: '/demo(-\d+)?\.csv$/i'
filename_pattern: /\.csv$/i

csv:
preset: my-preset
Expand Down Expand Up @@ -162,8 +162,8 @@ columns:
is_geohash: true
is_cardinal_direction: true
is_usa_market_name: true
is_country_code: alpha-2
is_language_code: alpha-2
country_code: alpha-2
language_code: alpha-2

is_file_exists: true
is_dir_exists: true
Expand Down Expand Up @@ -442,6 +442,8 @@ columns:
rules:
not_empty: true

- name: third_column
rules:
not_empty: true
- name: inherited_column_login
preset: my-preset/login

- name: inherited_column_full_name
preset: my-preset/full_name
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Respect\Validation\Rules\CountryCode as RespectCountryCode;
use Respect\Validation\Validator;

class IsCountryCode extends AbstractCellRule
class CountryCode extends AbstractCellRule
{
public function getHelpMeta(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Respect\Validation\Rules\LanguageCode as RespectLanguageCode;
use Respect\Validation\Validator;

class IsLanguageCode extends AbstractCellRule
class LanguageCode extends AbstractCellRule
{
public function getHelpMeta(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

namespace JBZoo\PHPUnit\Rules\Cell;

use JBZoo\CsvBlueprint\Rules\Cell\IsCountryCode;
use JBZoo\CsvBlueprint\Rules\Cell\CountryCode;
use JBZoo\PHPUnit\Rules\TestAbstractCellRule;
use Respect\Validation\Rules\CountryCode as RespectCountryCode;

use function JBZoo\PHPUnit\isSame;

final class IsCountryCodeTest extends TestAbstractCellRule
final class CountryCodeTest extends TestAbstractCellRule
{
protected string $ruleClass = IsCountryCode::class;
protected string $ruleClass = CountryCode::class;

public function testPositive(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

namespace JBZoo\PHPUnit\Rules\Cell;

use JBZoo\CsvBlueprint\Rules\Cell\IsLanguageCode;
use JBZoo\CsvBlueprint\Rules\Cell\LanguageCode;
use JBZoo\PHPUnit\Rules\TestAbstractCellRule;

use function JBZoo\PHPUnit\isSame;

final class IsLanguageCodeTest extends TestAbstractCellRule
final class LanguageCodeTest extends TestAbstractCellRule
{
protected string $ruleClass = IsLanguageCode::class;
protected string $ruleClass = LanguageCode::class;

public function testPositive(): void
{
Expand Down
5 changes: 3 additions & 2 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testGetFinenamePattern(): void
isSame(null, $schemaEmpty->getFilenamePattern());

$schemaFull = new Schema(Tools::SCHEMA_FULL_YML);
isSame('/demo(-\d+)?\.csv$/i', $schemaFull->getFilenamePattern());
isSame('/\.csv$/i', $schemaFull->getFilenamePattern());
}

public function testScvStruture(): void
Expand Down Expand Up @@ -77,7 +77,8 @@ public function testColumns(): void
isSame([
0 => 'Column Name (header)',
1 => 'another_column',
2 => 'third_column',
2 => 'inherited_column_login',
3 => 'inherited_column_full_name',
], $schemaFull->getSchemaHeader());
}

Expand Down

0 comments on commit f2594b9

Please sign in to comment.