From 8d3b2d9115009738c7c04307dfcc91ead34448d5 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Mon, 27 Feb 2023 11:54:00 -0800 Subject: [PATCH 01/20] adds meaningful test, PHP matrix --- .github/workflows/php.yml | 32 ++++++++++---------------------- composer.json | 5 ++++- tests/CSVResponseTest.php | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 26 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 1ffa2e1..740722e 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -7,29 +7,17 @@ on: branches: [ main ] jobs: - build: - + run: runs-on: ubuntu-latest - + strategy: + matrix: + php-versions: ['7.1', '7.4', '8.0', '8.1'] steps: - - uses: actions/checkout@v2 - - - name: Validate composer.json and composer.lock - run: composer validate --strict + - uses: actions/checkout@v3 - - name: Cache Composer packages - id: composer-cache - uses: actions/cache@v2 - with: - path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-php- + - uses: php-actions/composer@v6 - - name: Install dependencies - run: composer install --prefer-dist --no-progress --no-suggest - - - name: PHPUnit (php-actions) - uses: php-actions/phpunit@v2 - with: - configuration: ./phpunit.xml + - name: PHPUnit Tests + uses: php-actions/phpunit@v3 + with: + php_version: ${{ matrix.php-versions }} diff --git a/composer.json b/composer.json index 35bace7..5c42cd3 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require": { "php": ">=7.1.3", - "symfony/symfony": "4.4.*" + "symfony/symfony": "^4.4 || ^6" }, "require-dev": { "phpunit/phpunit": "^8.0 || ^9.0" @@ -35,5 +35,8 @@ "psr-4" : { "Ilbee\\CSVResponse\\Tests\\" : "tests/" } + }, + "scripts": { + "test": "./vendor/bin/phpunit" } } diff --git a/tests/CSVResponseTest.php b/tests/CSVResponseTest.php index f20ba45..a200134 100644 --- a/tests/CSVResponseTest.php +++ b/tests/CSVResponseTest.php @@ -3,13 +3,41 @@ namespace Ilbee\CSVResponse\Tests; - +use Ilbee\CSVResponse\CSVResponse; use PHPUnit\Framework\TestCase; +/** + * @covers \Ilbee\CSVResponse\CSVResponse + */ class CSVResponseTest extends TestCase { - public function testReadData(): void + protected function getData(): array + { + $data = []; + $data[] = [ + 'firstName' => 'Marcel', + 'lastName' => 'TOTO', + ]; + $data[] = [ + 'firstName' => 'Maurice', + 'lastName' => 'TATA', + ]; + return $data; + } + + public function testResponse(): void { - $this->assertTrue(true); + // Defaults to semicolon. + $response = new CSVResponse($this->getData()); + $this->assertSame( + "firstName;lastName\nMarcel;TOTO\nMaurice;TATA\n", + $response->getContent() + ); + // Use a comma to separate values. + $response = new CSVResponse($this->getData(), null, CSVResponse::COMMA); + $this->assertSame( + "firstName,lastName\nMarcel,TOTO\nMaurice,TATA\n", + $response->getContent() + ); } } \ No newline at end of file From 24950155d53b023ff43dd4c54ae6236b6c46b6da Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Mon, 27 Feb 2023 11:57:34 -0800 Subject: [PATCH 02/20] limit php version for composer step --- .github/workflows/php.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 740722e..857961e 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -16,6 +16,8 @@ jobs: - uses: actions/checkout@v3 - uses: php-actions/composer@v6 + with: + php_version: ${{ matrix.php-versions }} - name: PHPUnit Tests uses: php-actions/phpunit@v3 From ffab7d9137ac65ad421afdb2a745d148741fd7a9 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Mon, 27 Feb 2023 12:00:56 -0800 Subject: [PATCH 03/20] composer --- .github/workflows/php.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 857961e..5515b7d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -11,12 +11,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['7.1', '7.4', '8.0', '8.1'] + php-versions: ['7.2', '7.4', '8.0', '8.1'] steps: - uses: actions/checkout@v3 - uses: php-actions/composer@v6 with: + command: update php_version: ${{ matrix.php-versions }} - name: PHPUnit Tests From a6964998ba93a3ca8e573e75503802995c5d6739 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Tue, 28 Feb 2023 08:49:02 -0800 Subject: [PATCH 04/20] matrix symfony --- .github/workflows/php.yml | 19 ++++++++++++++----- composer.json | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5515b7d..9844322 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -11,16 +11,25 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['7.2', '7.4', '8.0', '8.1'] + symfony-versions: ['^4.4', '^5.0', '^6.0'] + php-versions: ['8.0'] # ['7.2', '7.4', '8.0', '8.1'] steps: - uses: actions/checkout@v3 - - uses: php-actions/composer@v6 + - name: Install dependencies + uses: php-actions/composer@v6 with: - command: update php_version: ${{ matrix.php-versions }} - - name: PHPUnit Tests - uses: php-actions/phpunit@v3 + - name: Update Symfony + uses: php-actions/composer@v6 with: + command: require + args: ${{ matrix.symfony-versions }} -W php_version: ${{ matrix.php-versions }} + + - name: PHPUnit (php-actions) + uses: php-actions/phpunit@v2 + with: + php_version: ${{ matrix.php-versions }} + configuration: ./phpunit.xml diff --git a/composer.json b/composer.json index 5c42cd3..0e68f4f 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "symfony/symfony": "^4.4 || ^6" }, "require-dev": { - "phpunit/phpunit": "^8.0 || ^9.0" + "phpunit/phpunit": ">=8.0.0 <10.0.0" }, "autoload": { "psr-4": { From 0a64fe01604a6cdca4823c4fc1ecc8a08d2c4f87 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Tue, 28 Feb 2023 08:50:56 -0800 Subject: [PATCH 05/20] needs the name --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 9844322..1e8446a 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -25,7 +25,7 @@ jobs: uses: php-actions/composer@v6 with: command: require - args: ${{ matrix.symfony-versions }} -W + args: symfony/symfony:${{ matrix.symfony-versions }} -W php_version: ${{ matrix.php-versions }} - name: PHPUnit (php-actions) From ecfaa3ccb8effadec182c1533e229216b71f167b Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Tue, 28 Feb 2023 08:57:06 -0800 Subject: [PATCH 06/20] 7.4? --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 1e8446a..0c508e2 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: symfony-versions: ['^4.4', '^5.0', '^6.0'] - php-versions: ['8.0'] # ['7.2', '7.4', '8.0', '8.1'] + php-versions: ['7.4'] # ['7.2', '7.4', '8.0', '8.1'] steps: - uses: actions/checkout@v3 From ef50ebe0833f5b4f9dcf3362962c3fc2126cf34f Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Tue, 28 Feb 2023 09:07:17 -0800 Subject: [PATCH 07/20] 8.0 --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 0c508e2..1e8446a 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: symfony-versions: ['^4.4', '^5.0', '^6.0'] - php-versions: ['7.4'] # ['7.2', '7.4', '8.0', '8.1'] + php-versions: ['8.0'] # ['7.2', '7.4', '8.0', '8.1'] steps: - uses: actions/checkout@v3 From f4487ac1d5f0382ffc2023b96ce0daa4f9594281 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Tue, 28 Feb 2023 09:45:32 -0800 Subject: [PATCH 08/20] vendored path --- .github/workflows/php.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 1e8446a..adfeba4 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -32,4 +32,5 @@ jobs: uses: php-actions/phpunit@v2 with: php_version: ${{ matrix.php-versions }} + vendored_phpunit_path: ./vendor/bin/phpunit configuration: ./phpunit.xml From be4557f216fc5ca670e1486c7a6c0c1b7acbf97d Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Tue, 28 Feb 2023 09:54:00 -0800 Subject: [PATCH 09/20] newer php-action --- .github/workflows/php.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index adfeba4..da4207c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -29,8 +29,8 @@ jobs: php_version: ${{ matrix.php-versions }} - name: PHPUnit (php-actions) - uses: php-actions/phpunit@v2 + uses: php-actions/phpunit@v3.0.3 with: php_version: ${{ matrix.php-versions }} - vendored_phpunit_path: ./vendor/bin/phpunit + vendored_phpunit_path: vendor/bin/phpunit configuration: ./phpunit.xml From c5c8bd31b0fbe1fdcf56162c49781888ecbdd6b3 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Tue, 28 Feb 2023 10:22:45 -0800 Subject: [PATCH 10/20] comments --- .github/workflows/php.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index da4207c..894dea8 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -32,5 +32,6 @@ jobs: uses: php-actions/phpunit@v3.0.3 with: php_version: ${{ matrix.php-versions }} + # TODO: https://github.com/php-actions/phpunit/issues/51 vendored_phpunit_path: vendor/bin/phpunit configuration: ./phpunit.xml From 3fd114bd65b1ff7797e0c35938c3ad43706f553a Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Wed, 1 Mar 2023 09:10:01 -0800 Subject: [PATCH 11/20] dev branch of github action --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 894dea8..594e238 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -29,7 +29,7 @@ jobs: php_version: ${{ matrix.php-versions }} - name: PHPUnit (php-actions) - uses: php-actions/phpunit@v3.0.3 + uses: php-actions/phpunit@chmod-permission with: php_version: ${{ matrix.php-versions }} # TODO: https://github.com/php-actions/phpunit/issues/51 From 6e84945df7d5fdbfb06579dc12150bddbbae5462 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Wed, 8 Mar 2023 13:17:39 -0800 Subject: [PATCH 12/20] tighten phpunit constraint --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 0e68f4f..7ee4e74 100644 --- a/composer.json +++ b/composer.json @@ -21,10 +21,10 @@ }, "require": { "php": ">=7.1.3", - "symfony/symfony": "^4.4 || ^6" + "symfony/symfony": "^6" }, "require-dev": { - "phpunit/phpunit": ">=8.0.0 <10.0.0" + "phpunit/phpunit": "^9.6" }, "autoload": { "psr-4": { From 948bb09be8f8e6945926d298a19cbf954cbe90b0 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Wed, 8 Mar 2023 13:22:38 -0800 Subject: [PATCH 13/20] readme, test headers --- README.md | 2 +- tests/CSVResponseTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 068e913..0c0c39e 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ CSVResponse [![SymfonyInsight](https://insight.symfony.com/projects/98a48652-16bb-4100-89bd-e4ef7579c429/mini.svg)](https://insight.symfony.com/projects/98a48652-16bb-4100-89bd-e4ef7579c429) ![Php Composer](https://github.com/ilbee/csv-response/actions/workflows/php.yml/badge.svg) -Add a CSV export Response in your [Symfony] 4 controller. +Add a CSV export Response in your [Symfony] controller. Installation ------------ diff --git a/tests/CSVResponseTest.php b/tests/CSVResponseTest.php index a200134..366ee0e 100644 --- a/tests/CSVResponseTest.php +++ b/tests/CSVResponseTest.php @@ -27,7 +27,7 @@ protected function getData(): array public function testResponse(): void { - // Defaults to semicolon. + // Defaults to semicolon separator. $response = new CSVResponse($this->getData()); $this->assertSame( "firstName;lastName\nMarcel;TOTO\nMaurice;TATA\n", @@ -39,5 +39,6 @@ public function testResponse(): void "firstName,lastName\nMarcel,TOTO\nMaurice,TATA\n", $response->getContent() ); + $this->assertEquals('text/csv', $response->headers->get('content-type')); } } \ No newline at end of file From 46ef63fb3ec928a687efe25c2cab10f4e4fb2a28 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 10 Mar 2023 12:45:41 -0800 Subject: [PATCH 14/20] wider array of symfony --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7ee4e74..3696f9a 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require": { "php": ">=7.1.3", - "symfony/symfony": "^6" + "symfony/symfony": "^4 || ^5 || ^6" }, "require-dev": { "phpunit/phpunit": "^9.6" From c3ff48397eefc45704cca18ce006d10760580733 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 10 Mar 2023 13:03:33 -0800 Subject: [PATCH 15/20] run tests --- .github/workflows/php.yml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 594e238..f2b977e 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: symfony-versions: ['^4.4', '^5.0', '^6.0'] - php-versions: ['8.0'] # ['7.2', '7.4', '8.0', '8.1'] + php-versions: ['7.2', '7.4', '8.0', '8.1'] steps: - uses: actions/checkout@v3 @@ -24,14 +24,17 @@ jobs: - name: Update Symfony uses: php-actions/composer@v6 with: + php_version: ${{ matrix.php-versions }} command: require args: symfony/symfony:${{ matrix.symfony-versions }} -W - php_version: ${{ matrix.php-versions }} - - name: PHPUnit (php-actions) - uses: php-actions/phpunit@chmod-permission - with: - php_version: ${{ matrix.php-versions }} - # TODO: https://github.com/php-actions/phpunit/issues/51 - vendored_phpunit_path: vendor/bin/phpunit - configuration: ./phpunit.xml + - name: PHPUnit (script) + run: ./vendor/bin/phpunit + +# - name: PHPUnit (php-actions) +# uses: php-actions/phpunit@v3 +# with: +# php_version: ${{ matrix.php-versions }} +# # TODO: https://github.com/php-actions/phpunit/issues/51 +# vendored_phpunit_path: vendor/bin/phpunit +# configuration: ./phpunit.xml From 493498f69362bd36e9b5c994be12261d4c1565f6 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 10 Mar 2023 13:06:23 -0800 Subject: [PATCH 16/20] fewer php versions --- .github/workflows/php.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index f2b977e..beb2dae 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: symfony-versions: ['^4.4', '^5.0', '^6.0'] - php-versions: ['7.2', '7.4', '8.0', '8.1'] + php-versions: ['8.1', '8.0', '7.4'] steps: - uses: actions/checkout@v3 diff --git a/composer.json b/composer.json index 3696f9a..9ab7ec1 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "issues": "https://github.com/ilbee/csv-response/issues" }, "require": { - "php": ">=7.1.3", + "php": ">=7.4 <9", "symfony/symfony": "^4 || ^5 || ^6" }, "require-dev": { From 7142cd5df215b4969c0d98bb485821d4755620a3 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 10 Mar 2023 13:15:44 -0800 Subject: [PATCH 17/20] exclude version mismatches --- .github/workflows/php.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index beb2dae..cf6254d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -13,6 +13,10 @@ jobs: matrix: symfony-versions: ['^4.4', '^5.0', '^6.0'] php-versions: ['8.1', '8.0', '7.4'] + exclude: + - symfony-versions: '^6.0' + php-versions: '7.4' + steps: - uses: actions/checkout@v3 From 9855cc126bd20b7640f695d232218a21731106ae Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 10 Mar 2023 13:23:58 -0800 Subject: [PATCH 18/20] tooling --- composer.json | 5 ++++- phpcs.xml | 11 +++++++++++ src/CSVResponse.php | 16 ++++++++-------- tests/Bootstrap.php | 4 ++-- tests/CSVResponseTest.php | 2 +- 5 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 phpcs.xml diff --git a/composer.json b/composer.json index 9ab7ec1..6bdacf3 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "symfony/symfony": "^4 || ^5 || ^6" }, "require-dev": { - "phpunit/phpunit": "^9.6" + "phpunit/phpunit": "^9.6", + "squizlabs/php_codesniffer": "^3.7" }, "autoload": { "psr-4": { @@ -37,6 +38,8 @@ } }, "scripts": { + "phpcbf": "./vendor/bin/phpcbf", + "phpcs": "./vendor/bin/phpcs", "test": "./vendor/bin/phpunit" } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..1ec24b2 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,11 @@ + + + PHP CodeSniffer configuration. + + src + tests + + + + + diff --git a/src/CSVResponse.php b/src/CSVResponse.php index dd12163..f2c5ae2 100644 --- a/src/CSVResponse.php +++ b/src/CSVResponse.php @@ -17,7 +17,7 @@ public function __construct(array $data, ?string $fileName = null, ?string $sepa parent::__construct(); $this->separator = $separator; - if ( $fileName ) { + if ($fileName) { $this->fileName = $fileName; } @@ -29,7 +29,7 @@ public function __construct(array $data, ?string $fileName = null, ?string $sepa private function initContent($data): string { $fp = fopen('php://temp', 'w'); - foreach ( $this->prepareData($data) as $fields) { + foreach ($this->prepareData($data) as $fields) { fputcsv($fp, $fields, $this->separator); } @@ -44,19 +44,19 @@ private function prepareData(array $data): array { $i = 0; $output = []; - foreach ( $data as $row ) { - if ( $i === 0 ) { + foreach ($data as $row) { + if ($i === 0) { $head = []; - foreach ( $row as $key => $value ) { + foreach ($row as $key => $value) { $head[] = $key; } $output[] = $head; } $line = []; - foreach ( $row as $key => $value ) { - if ( is_object($value) ) { - if ( get_class($value) == 'DateTime' ) { + foreach ($row as $key => $value) { + if (is_object($value)) { + if (get_class($value) == 'DateTime') { $value = $value->format('Y-m-d H:i:s'); } } diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 33e9817..daac00a 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -1,5 +1,5 @@ assertEquals('text/csv', $response->headers->get('content-type')); } -} \ No newline at end of file +} From 1ad225f64edd69a58e5f0ecdd9e10592ef08cf6e Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 10 Mar 2023 15:38:09 -0800 Subject: [PATCH 19/20] hundred percent --- composer.json | 8 ++++++-- phpcs.xml | 1 + phpunit.xml | 9 ++++++++- rector.php | 22 ++++++++++++++++++++++ src/CSVResponse.php | 8 ++++---- tests/CSVResponseTest.php | 12 +++++++++++- 6 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 rector.php diff --git a/composer.json b/composer.json index 6bdacf3..5ec75a0 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ }, "require-dev": { "phpunit/phpunit": "^9.6", - "squizlabs/php_codesniffer": "^3.7" + "squizlabs/php_codesniffer": "^3.7", + "rector/rector": "^0.15.21" }, "autoload": { "psr-4": { @@ -40,6 +41,9 @@ "scripts": { "phpcbf": "./vendor/bin/phpcbf", "phpcs": "./vendor/bin/phpcs", - "test": "./vendor/bin/phpunit" + "rector": "./vendor/bin/rector process", + "rector-dry-run": "./vendor/bin/rector process --dry-run", + "test": "./vendor/bin/phpunit", + "test-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html ./coverage" } } diff --git a/phpcs.xml b/phpcs.xml index 1ec24b2..92a5179 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -4,6 +4,7 @@ src tests + rector.php diff --git a/phpunit.xml b/phpunit.xml index 827a35b..570e620 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,12 @@ - + + + + src + + tests diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..ad1219e --- /dev/null +++ b/rector.php @@ -0,0 +1,22 @@ +paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_74, + ]); + + $rectorConfig->skip([ + JsonThrowOnErrorRector::class, + ]); +}; diff --git a/src/CSVResponse.php b/src/CSVResponse.php index f2c5ae2..8895e37 100644 --- a/src/CSVResponse.php +++ b/src/CSVResponse.php @@ -6,11 +6,11 @@ class CSVResponse extends Response { - private $fileName = 'CSVExport'; - private $separator; + private string $fileName = 'CSVExport'; + private ?string $separator = null; - const COMMA = ','; - const SEMICOLON = ';'; + public const COMMA = ','; + public const SEMICOLON = ';'; public function __construct(array $data, ?string $fileName = null, ?string $separator = self::SEMICOLON) { diff --git a/tests/CSVResponseTest.php b/tests/CSVResponseTest.php index 914b1d6..e1f465d 100644 --- a/tests/CSVResponseTest.php +++ b/tests/CSVResponseTest.php @@ -34,11 +34,21 @@ public function testResponse(): void $response->getContent() ); // Use a comma to separate values. - $response = new CSVResponse($this->getData(), null, CSVResponse::COMMA); + $response = new CSVResponse($this->getData(), 'my-file-name', CSVResponse::COMMA); $this->assertSame( "firstName,lastName\nMarcel,TOTO\nMaurice,TATA\n", $response->getContent() ); $this->assertEquals('text/csv', $response->headers->get('content-type')); + $this->assertEquals('attachment; filename="my-file-name.csv"', $response->headers->get('content-disposition')); + } + + public function testDateTime(): void + { + $now = new \DateTime(); + $response = new CSVResponse([ + ['datetime' => $now], + ]); + $this->assertStringContainsString($now->format('Y-m-d H:i:s'), $response->getContent()); } } From d488945d7fd74dd8ca639b76ede0f12ed03dc1be Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 10 Mar 2023 15:52:10 -0800 Subject: [PATCH 20/20] cosmetic --- .github/workflows/php.yml | 1 + phpunit.xml | 2 +- tests/CSVResponseTest.php | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index cf6254d..0d15637 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -13,6 +13,7 @@ jobs: matrix: symfony-versions: ['^4.4', '^5.0', '^6.0'] php-versions: ['8.1', '8.0', '7.4'] + # Exclude combinations that are not installable. exclude: - symfony-versions: '^6.0' php-versions: '7.4' diff --git a/phpunit.xml b/phpunit.xml index 570e620..055df7f 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,6 @@ diff --git a/tests/CSVResponseTest.php b/tests/CSVResponseTest.php index e1f465d..d796bef 100644 --- a/tests/CSVResponseTest.php +++ b/tests/CSVResponseTest.php @@ -39,8 +39,14 @@ public function testResponse(): void "firstName,lastName\nMarcel,TOTO\nMaurice,TATA\n", $response->getContent() ); - $this->assertEquals('text/csv', $response->headers->get('content-type')); - $this->assertEquals('attachment; filename="my-file-name.csv"', $response->headers->get('content-disposition')); + $this->assertEquals( + 'text/csv', + $response->headers->get('content-type') + ); + $this->assertEquals( + 'attachment; filename="my-file-name.csv"', + $response->headers->get('content-disposition') + ); } public function testDateTime(): void @@ -49,6 +55,9 @@ public function testDateTime(): void $response = new CSVResponse([ ['datetime' => $now], ]); - $this->assertStringContainsString($now->format('Y-m-d H:i:s'), $response->getContent()); + $this->assertStringContainsString( + $now->format('Y-m-d H:i:s'), + $response->getContent() + ); } }