Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Add Docker files and documentation #840

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$config = PhpCsFixer\Config::create()
$config = (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
Expand All @@ -13,13 +13,14 @@
'declare_equal_normalize' => ['space' => 'single'],
'heredoc_to_nowdoc' => true,
'increment_style' => ['style' => 'post'],
'is_null' => ['use_yoda_style' => false],
'method_argument_space' => ['ensure_fully_multiline' => true],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline'
],
'modernize_types_casting' => true,
'no_break_comment' => ['comment_text' => 'do nothing'],
'no_empty_phpdoc' => false,
'no_null_property_initialization' => true,
'no_short_echo_tag' => true,
'echo_tag_syntax' => false,
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => false,
'no_unneeded_control_parentheses' => ['statements' => ['break', 'clone', 'continue', 'echo_print', 'switch_case', 'yield']],
Expand All @@ -37,7 +38,7 @@
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'phpdoc_separation' => false,
'protected_to_private' => true,
'psr4' => true,
'psr_autoloading' => true,
'return_type_declaration' => ['space_before' => 'one'],
'semicolon_after_instruction' => true,
'simplified_null_return' => false,
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ before_script:
script:
- |
if [[ "$WITH_CS" == "true" ]]; then
vendor/bin/php-cs-fixer fix --config=.php_cs.dist --verbose --diff --dry-run --diff-format=udiff
vendor/bin/php-cs-fixer fix --verbose --diff --dry-run --diff-format=udiff
fi
- |
if [[ "$WITH_PHPUNIT" == "true" ]]; then
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM php:7.2-cli

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
libzip-dev \
locales \
locales-all \
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add locales for comma separator tests

zip \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip

COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
RUN chmod +x /usr/local/bin/composer
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ For information, the performance tests take about 10 minutes to run (processing

> Performance tests status: [![Build Status](https://travis-ci.org/box/spout.svg?branch=perf-tests)](https://travis-ci.org/box/spout)

### Running test with Docker

First install the dependencies with docker-compose

```bash
docker-compose run --rm -u ${UID} php composer install
```

Then launch the PHPUnit tests

```bash
docker-compose run --rm php vendor/bin/phpunit
```

Same for CS Fixer tests

```bash
docker-compose run --rm php vendor/bin/php-cs-fixer fix --verbose --diff --dry-run --diff-format=udiff
```

## Support

Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3'
services:
php:
build: .
working_dir: /srv/spout
volumes:
- $PWD:/srv/spout
- $PWD/tests/generated/resources/unwritable:/srv/spout/tests/resources/generated/unwritable:ro
9 changes: 7 additions & 2 deletions tests/Spout/Writer/ODS/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,17 @@ public function testAddRowShouldSupportFloatValuesInDifferentLocale()
// Installed locales differ from one system to another, so we can't pick
// a given locale.
$supportedLocales = explode("\n", shell_exec('locale -a'));
$foundCommaLocale = false;
foreach ($supportedLocales as $supportedLocale) {
\setlocale(LC_ALL, $supportedLocale);
if (\localeconv()['decimal_point'] === ',') {
$foundCommaLocale = true;
break;
}
}
if (!$foundCommaLocale) {
$this->markTestSkipped('No locale with comma decimal separator');
}
Comment on lines +302 to +304
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can happen on system without comma separator

$this->assertEquals(',', \localeconv()['decimal_point']);

$fileName = 'test_add_row_should_support_float_values_in_different_locale.xlsx';
Expand All @@ -306,8 +311,8 @@ public function testAddRowShouldSupportFloatValuesInDifferentLocale()

$this->writeToODSFile($dataRows, $fileName);

$this->assertValueWasNotWrittenToSheet($fileName, 1, "1234,5");
$this->assertValueWasWrittenToSheet($fileName, 1, "1234.5");
$this->assertValueWasNotWrittenToSheet($fileName, 1, '1234,5');
$this->assertValueWasWrittenToSheet($fileName, 1, '1234.5');
} finally {
// reset locale
\setlocale(LC_ALL, $previousLocale);
Expand Down
9 changes: 7 additions & 2 deletions tests/Spout/Writer/XLSX/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,17 @@ public function testAddRowShouldSupportFloatValuesInDifferentLocale()
// Installed locales differ from one system to another, so we can't pick
// a given locale.
$supportedLocales = explode("\n", shell_exec('locale -a'));
$foundCommaLocale = false;
foreach ($supportedLocales as $supportedLocale) {
\setlocale(LC_ALL, $supportedLocale);
if (\localeconv()['decimal_point'] === ',') {
$foundCommaLocale = true;
break;
}
}
if (!$foundCommaLocale) {
$this->markTestSkipped('No locale with comma decimal separator');
}
$this->assertEquals(',', \localeconv()['decimal_point']);

$fileName = 'test_add_row_should_support_float_values_in_different_locale.xlsx';
Expand All @@ -421,8 +426,8 @@ public function testAddRowShouldSupportFloatValuesInDifferentLocale()

$this->writeToXLSXFile($dataRows, $fileName, $shouldUseInlineStrings = false);

$this->assertInlineDataWasNotWrittenToSheet($fileName, 1, "1234,5");
$this->assertInlineDataWasWrittenToSheet($fileName, 1, "1234.5");
$this->assertInlineDataWasNotWrittenToSheet($fileName, 1, '1234,5');
$this->assertInlineDataWasWrittenToSheet($fileName, 1, '1234.5');
} finally {
// reset locale
\setlocale(LC_ALL, $previousLocale);
Expand Down