diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e1babbe..5817a62 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: - name: Start docker 🔧 run: | - docker-compose -f docker-compose.yml -f .github/docker-compose.yml up -d + docker compose -f docker-compose.yml -f .github/docker-compose.yml up -d - name: Cache multiple paths uses: actions/cache@v2 @@ -23,16 +23,16 @@ jobs: - name: Install the dependencies 🔧 run: | - docker-compose exec -T application composer install --prefer-dist --no-interaction --no-progress - docker-compose exec -T application php -d zend_extension=xdebug.so ./bin/phpunit --configuration phpunit.xml.dist --dump-xdebug-filter phpunit-filter.php + docker compose exec -T application composer install --prefer-dist --no-interaction --no-progress + docker compose exec -T application php -d zend_extension=xdebug.so ./bin/phpunit --configuration phpunit.xml.dist --dump-xdebug-filter phpunit-filter.php - name: Execute the tests 🔧 run: | - docker-compose exec -T application php -d zend_extension=xdebug.so ./bin/phpunit --prepend phpunit-filter.php --configuration phpunit.xml.dist --colors=never --coverage-clover build/logs/clover.xml + docker compose exec -T application php -d zend_extension=xdebug.so ./bin/phpunit --prepend phpunit-filter.php --configuration phpunit.xml.dist --colors=never --coverage-clover build/logs/clover.xml - name: Upload results to Coveralls 🚀 env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_SECRET }} run: | - docker-compose exec -T application composer global require twinh/php-coveralls --prefer-dist --no-interaction --no-progress - docker-compose exec -T -e COVERALLS_REPO_TOKEN="$COVERALLS_REPO_TOKEN" application /home/application/.composer/vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v + docker compose exec -T application composer global require twinh/php-coveralls --prefer-dist --no-interaction --no-progress + docker compose exec -T -e COVERALLS_REPO_TOKEN="$COVERALLS_REPO_TOKEN" application /home/application/.composer/vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v diff --git a/Configuration/AbstractCsvGeneratorConfiguration.php b/Configuration/AbstractCsvGeneratorConfiguration.php index a17679d..de2aec9 100644 --- a/Configuration/AbstractCsvGeneratorConfiguration.php +++ b/Configuration/AbstractCsvGeneratorConfiguration.php @@ -32,6 +32,9 @@ abstract class AbstractCsvGeneratorConfiguration /** @var bool */ protected $withHeader; + /** @var bool */ + protected $withUtf8Bom; + protected function __construct() { } @@ -52,6 +55,7 @@ public function setSerializationGroups(array $serializationGroups): self return $this; } + private const UTF8_BOM = "\xEF\xBB\xBF"; public function getSerializationGroups(): array { @@ -106,6 +110,18 @@ public function isWithHeader(): bool return $this->withHeader; } + public function setWithUtf8Bom(bool $withUtf8Bom): self + { + $this->withUtf8Bom = $withUtf8Bom; + + return $this; + } + + public function isWithUtf8Bom(): bool + { + return $this->withUtf8Bom; + } + protected function initialize(string $class, iterable $objects): void { $this->class = $class; @@ -115,5 +131,6 @@ protected function initialize(string $class, iterable $objects): void $this->objectTransformerCallback = null; $this->delimiter = ';'; $this->withHeader = true; + $this->withUtf8Bom = true; } } diff --git a/Generator/CsvGenerator.php b/Generator/CsvGenerator.php index 4609ab2..da48c9e 100644 --- a/Generator/CsvGenerator.php +++ b/Generator/CsvGenerator.php @@ -21,6 +21,8 @@ */ class CsvGenerator implements CsvGeneratorInterface { + private const UTF8_BOM = "\xEF\xBB\xBF"; + /** @var SerializerInterface */ protected $serializer; @@ -45,6 +47,10 @@ public function getContent(AbstractCsvGeneratorConfiguration $configuration): st { $content = ''; + if ($configuration->isWithUtf8Bom()) { + $content .= self::UTF8_BOM; + } + if ($configuration->isWithHeader()) { $content .= $this->getHeaderContent($configuration); }