From cf9c0b66badf33862a7ccafc4c333a45de700f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Fri, 4 Dec 2020 09:00:40 +0100 Subject: [PATCH 01/16] fix float conversion issue when using strict mode --- src/ArrayDiffMultidimensional.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArrayDiffMultidimensional.php b/src/ArrayDiffMultidimensional.php index a30ed6d..98eae00 100644 --- a/src/ArrayDiffMultidimensional.php +++ b/src/ArrayDiffMultidimensional.php @@ -49,7 +49,7 @@ public static function compare($array1, $array2, $strict = true) $value1 = $value; $value2 = $array2[$key]; - if (is_float($value1) || is_float($value2)) { + if ($strict ? is_float($value1) && is_float($value2) : is_float($value1) || is_float($value2)) { $value1 = (string) $value1; $value2 = (string) $value2; } From 7aea1c5f740b7737f185aaa28937b2bed917ea3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Fri, 4 Dec 2020 09:01:02 +0100 Subject: [PATCH 02/16] epsilon test --- tests/ArrayCompareTest.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/ArrayCompareTest.php b/tests/ArrayCompareTest.php index 7bfafe0..09623ea 100644 --- a/tests/ArrayCompareTest.php +++ b/tests/ArrayCompareTest.php @@ -275,4 +275,40 @@ public function it_does_not_detect_loose_changes_without_strict_mode() $this->assertEquals(0, count($diff->looseComparison($new, $old))); $this->assertFalse(isset($diff->looseComparison($new, $old)['c'])); } + + /** @test */ + public function it_detects_epsilon_change_with_strict_mode() + { + if (defined('PHP_FLOAT_EPSILON')) { + $diff = new ArrayDiffMultidimensional(); + + $new = [123]; + $old = [PHP_FLOAT_EPSILON + 123]; + + $this->assertEquals(1, count($diff->compare($new, $old))); + $this->assertTrue(isset($diff->compare($new, $old)[0])); + $this->assertTrue(is_int($diff->compare($new, $old)[0])); + $this->assertEquals(123, $diff->compare($new, $old)[0]); + } else { + var_dump('Skipped since current PHP version does not have PHP_FLOAT_EPSILON defined'); + $this->assertTrue(true); + } + } + + /** @test */ + public function it_does_not_detect_epsilon_change_with_strict_mode() + { + if (defined('PHP_FLOAT_EPSILON')) { + $diff = new ArrayDiffMultidimensional(); + + $new = [123]; + $old = [PHP_FLOAT_EPSILON + 123]; + + $this->assertEquals(0, count($diff->looseComparison($new, $old))); + $this->assertFalse(isset($diff->looseComparison($new, $old)[0])); + } else { + var_dump('Skipped since current PHP version does not have PHP_FLOAT_EPSILON defined'); + $this->assertTrue(true); + } + } } From 902bd5f0d47051c597d4b2c809e00c22a2de17ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Thu, 10 Dec 2020 17:46:09 +0100 Subject: [PATCH 03/16] Update config.yml --- .circleci/config.yml | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index af8f9b2..93ad66d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,28 +1,17 @@ -# PHP CircleCI 2.0 configuration file -# -# Check https://circleci.com/docs/2.0/language-php/ for more details -# -version: 2 +# https://circleci.com/docs/2.0/testing-ios/#using-multiple-executor-types-macos--docker +version: 2.1 jobs: - build: - docker: - # Specify the version you desire here - - image: circleci/php:7.4-apache - - # Specify service dependencies here if necessary - # CircleCI maintains a library of pre-built images - # documented at https://circleci.com/docs/2.0/circleci-images/ - # Using the RAM variation mitigates I/O contention - # for database intensive operations. - # - image: circleci/mysql:5.7-ram - # - # - image: redis:2.8.19 - + build-and-test: + macos: + xcode: 11.3.0 + environment: + HOMEBREW_NO_AUTO_UPDATE: 1 steps: - checkout - - run: sudo apt-get update -y # PHP CircleCI 2.0 Configuration File# PHP CircleCI 2.0 Configuration File sudo apt install zlib1g-dev libsqlite3-dev - - run: sudo docker-php-ext-install zip + - run: brew install php curl + + - run: curl https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer # Download and cache dependencies - restore_cache: @@ -32,18 +21,11 @@ jobs: # fallback to using the latest cache if no exact match is found - v1-dependencies- - - run: composer selfupdate && composer install -n --prefer-dist + - run: composer install - save_cache: key: v1-dependencies-{{ checksum "composer.json" }} paths: - ./vendor - # prepare the database - # - run: touch storage/testing.sqlite - # - run: php artisan migrate --env=testing --database=sqlite_testing --force - - # run tests with phpunit or codecept - run: ./vendor/bin/phpunit - # - run: ./vendor/bin/codecept build - # - run: ./vendor/bin/codecept run From 6bf64c1d551ce227db7690a1f8f77e899e02da46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Thu, 10 Dec 2020 17:47:22 +0100 Subject: [PATCH 04/16] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 93ad66d..b39c6a9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,7 @@ # https://circleci.com/docs/2.0/testing-ios/#using-multiple-executor-types-macos--docker version: 2.1 jobs: - build-and-test: + build: macos: xcode: 11.3.0 environment: From 43a6b49a6b52e2fd8dff0a481227d6d9781838de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Thu, 10 Dec 2020 17:51:44 +0100 Subject: [PATCH 05/16] OSX is disabled on Free CircleCI layer --- .circleci/config.yml | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b39c6a9..af8f9b2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,17 +1,28 @@ -# https://circleci.com/docs/2.0/testing-ios/#using-multiple-executor-types-macos--docker -version: 2.1 +# PHP CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-php/ for more details +# +version: 2 jobs: build: - macos: - xcode: 11.3.0 - environment: - HOMEBREW_NO_AUTO_UPDATE: 1 + docker: + # Specify the version you desire here + - image: circleci/php:7.4-apache + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # Using the RAM variation mitigates I/O contention + # for database intensive operations. + # - image: circleci/mysql:5.7-ram + # + # - image: redis:2.8.19 + steps: - checkout - - run: brew install php curl - - - run: curl https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer + - run: sudo apt-get update -y # PHP CircleCI 2.0 Configuration File# PHP CircleCI 2.0 Configuration File sudo apt install zlib1g-dev libsqlite3-dev + - run: sudo docker-php-ext-install zip # Download and cache dependencies - restore_cache: @@ -21,11 +32,18 @@ jobs: # fallback to using the latest cache if no exact match is found - v1-dependencies- - - run: composer install + - run: composer selfupdate && composer install -n --prefer-dist - save_cache: key: v1-dependencies-{{ checksum "composer.json" }} paths: - ./vendor + # prepare the database + # - run: touch storage/testing.sqlite + # - run: php artisan migrate --env=testing --database=sqlite_testing --force + + # run tests with phpunit or codecept - run: ./vendor/bin/phpunit + # - run: ./vendor/bin/codecept build + # - run: ./vendor/bin/codecept run From 50a95c45c9af599291f67cd861872b34322af79e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Fri, 18 Dec 2020 18:10:46 +0100 Subject: [PATCH 06/16] fix duplication --- src/ArrayDiffMultidimensional.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/ArrayDiffMultidimensional.php b/src/ArrayDiffMultidimensional.php index 98eae00..1e924e6 100644 --- a/src/ArrayDiffMultidimensional.php +++ b/src/ArrayDiffMultidimensional.php @@ -26,10 +26,6 @@ public static function compare($array1, $array2, $strict = true) $result = array(); - if (!is_array($array2)) { - return $array1; - } - foreach ($array1 as $key => $value) { if (!array_key_exists($key, $array2)) { $result[$key] = $value; From c5beb1e722e020c080a61751d212fcf8942f9826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Fri, 18 Dec 2020 18:10:59 +0100 Subject: [PATCH 07/16] stop on first failure --- phpunit.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml b/phpunit.xml index 6989de4..2988c53 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,5 @@ - + ./tests/ From 57b92e8edcc151f894c8a6572caf850100af7122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Fri, 18 Dec 2020 18:11:07 +0100 Subject: [PATCH 08/16] wip test --- tests/ArrayCompareTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/ArrayCompareTest.php b/tests/ArrayCompareTest.php index 09623ea..e732dae 100644 --- a/tests/ArrayCompareTest.php +++ b/tests/ArrayCompareTest.php @@ -311,4 +311,21 @@ public function it_does_not_detect_epsilon_change_with_strict_mode() $this->assertTrue(true); } } + + /** @test */ + public function it_detects_empty_array_change_with_strict_mode() + { + $diff = new ArrayDiffMultidimensional(); + + $new = [[]]; + $old = [1]; + + var_dump($diff->compare($new, $old)); + // $this->assertEquals(1, count($diff->compare($new, $old))); + //($this->assertTrue(isset($diff->compare($new, $old)[0])); + //($this->assertTrue(is_int($diff->compare($new, $old)[0])); + //($this->assertEquals(123, $diff->compare($new, $old)[0]); + + $this->assertTrue(true); + } } From a13fccdf03dbdfb66e96337fc4c0370bbfc8fa1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Sat, 19 Dec 2020 12:41:31 +0100 Subject: [PATCH 09/16] better message --- src/ArrayDiffMultidimensional.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArrayDiffMultidimensional.php b/src/ArrayDiffMultidimensional.php index 1e924e6..61744a9 100644 --- a/src/ArrayDiffMultidimensional.php +++ b/src/ArrayDiffMultidimensional.php @@ -17,7 +17,7 @@ class ArrayDiffMultidimensional public static function compare($array1, $array2, $strict = true) { if (!is_array($array1)) { - throw new \InvalidArgumentException('array1 must be an array!'); + throw new \InvalidArgumentException('$array1 must be an array!'); } if (!is_array($array2)) { From 48b36437c967f8bf743e0d983b4db8a1e6fbdafa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Sat, 19 Dec 2020 12:42:05 +0100 Subject: [PATCH 10/16] github actions wip --- .github/workflows/pull_request.yml | 55 ++++++++++++++++++++++++++++++ .travis.yml | 25 -------------- appveyor.yml | 51 --------------------------- 3 files changed, 55 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/pull_request.yml delete mode 100644 .travis.yml delete mode 100644 appveyor.yml diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..dee48fb --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,55 @@ +name: pull_request + +on: [pull_request] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + php: [8.0, 7.4, 7.3, 7.2, 7.1, 7.0, 5.6, 5.5] + + name: PHP ${{ matrix.php }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@2.9.0 + with: + php-version: ${{ matrix.php }} + extensions: zip, xdebug + coverage: xdebug + + - name: Update composer + run: composer selfupdate + + - name: Install dependencies + run: composer update --prefer-dist --no-interaction + + - name: Execute tests + run: vendor/bin/phpunit + + - name: Make sure Sonar Scanner is available + if: ${{ matrix.os == 'ubuntu-latest' && matrix.php == '8.0' }} + run: composer require rogervila/php-sonarqube-scanner --dev + + - name: Configure sonar-project.properties + if: ${{ matrix.os == 'ubuntu-latest' && matrix.php == '8.0' }} + run: | + echo "# SonarQube Properties" > sonar-project.properties + echo "sonar.host.url=https://sonarcloud.io" >> sonar-project.properties + echo "sonar.login=${{ secrets.SONAR_TOKEN }}" >> sonar-project.properties + echo "sonar.projectKey=rogervila_array-diff-multidimensional" >> sonar-project.properties + echo "sonar.organization=rogervila-github" >> sonar-project.properties + echo "sonar.sources=." >> sonar-project.properties + echo "sonar.exclusions=tmp/**, vendor/**, tests/**" >> sonar-project.properties + echo "sonar.php.tests.reportPath=junit-logfile.xml" >> sonar-project.properties + echo "sonar.php.coverage.reportPaths=clover.xml" >> sonar-project.properties + + - name: Run Sonar Scanner + if: ${{ matrix.os == 'ubuntu-latest' && matrix.php == '8.0' }} + run: vendor/bin/sonar-scanner diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c28ea00..0000000 --- a/.travis.yml +++ /dev/null @@ -1,25 +0,0 @@ -env: - global: - - COMPOSER_MEMORY_LIMIT=-1 - - XDEBUG_MODE=coverage - -language: php - -php: - - 5.6 - - 7.0 - - 7.1 - - 7.2 - - 7.3 - - 7.4 - - nightly - -cache: - directories: - - $HOME/.composer/cache - -before_script: - - composer selfupdate - - composer install - -script: vendor/bin/phpunit diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 8e4cd15..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,51 +0,0 @@ -build: false -version: appveyor-{branch}-{build} -shallow_clone: false -clone_folder: C:\projects\app - -environment: - matrix: - - php_ver: 8.0.0 - - php_ver: 7.4.13 - - php_ver: 7.3.25 - - php_ver: 7.2.34 - - php_ver: 7.1.33 - - php_ver: 7.0.33 - - php_ver: 5.6.40 - - php_ver: 5.5.38 - # - php_ver: 5.4.45 - # - php_ver: 5.3.29 - -cache: - - '%APPDATA%\Composer' - - '%LOCALAPPDATA%\Composer' - - C:\tools\php -> .appveyor.yml - - C:\tools\composer.phar -> .appveyor.yml - -init: - - SET PATH=C:\tools\php;%PATH% - -install: - - ps: Set-Service wuauserv -StartupType Manual - - IF NOT EXIST C:\tools\php (choco install --yes --allow-empty-checksums php --version %php_ver% --params '/InstallDir:C:\tools\php') - - cd C:\tools\php - - copy php.ini-production php.ini - - echo date.timezone="UTC" >> php.ini - - echo memory_limit=512M >> php.ini - - echo extension_dir=ext >> php.ini - - echo extension=php_curl.dll >> php.ini - - echo extension=php_openssl.dll >> php.ini - - echo extension=php_mbstring.dll >> php.ini - - IF NOT EXIST C:\tools\composer.phar (cd C:\tools && appveyor DownloadFile https://getcomposer.org/composer.phar) - - php C:\tools\composer.phar --version - - cd C:\projects\app - -before_test: - - cd C:\projects\app - - php C:\tools\composer.phar selfupdate - - php C:\tools\composer.phar update --optimize-autoloader --no-interaction --no-progress --prefer-stable --no-ansi - - php C:\tools\composer.phar info -D | sort - -test_script: - - cd C:\projects\app - - vendor\bin\phpunit From 92b4cba6a17c1f727e55ad967e430551c8f268a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Sat, 19 Dec 2020 12:48:11 +0100 Subject: [PATCH 11/16] Update pull_request.yml --- .github/workflows/pull_request.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index dee48fb..06931fd 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -21,7 +21,7 @@ jobs: uses: shivammathur/setup-php@2.9.0 with: php-version: ${{ matrix.php }} - extensions: zip, xdebug + extensions: zip, curl, xdebug coverage: xdebug - name: Update composer @@ -46,7 +46,7 @@ jobs: echo "sonar.projectKey=rogervila_array-diff-multidimensional" >> sonar-project.properties echo "sonar.organization=rogervila-github" >> sonar-project.properties echo "sonar.sources=." >> sonar-project.properties - echo "sonar.exclusions=tmp/**, vendor/**, tests/**" >> sonar-project.properties + echo "sonar.exclusions=vendor/**, tests/**" >> sonar-project.properties echo "sonar.php.tests.reportPath=junit-logfile.xml" >> sonar-project.properties echo "sonar.php.coverage.reportPaths=clover.xml" >> sonar-project.properties From dddf5a5b8a3d46a03b6f600d80e5d21ae9ad6c93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Sat, 19 Dec 2020 17:34:23 +0100 Subject: [PATCH 12/16] Update pull_request.yml --- .github/workflows/pull_request.yml | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 06931fd..ea185ce 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -32,24 +32,5 @@ jobs: - name: Execute tests run: vendor/bin/phpunit - - - name: Make sure Sonar Scanner is available - if: ${{ matrix.os == 'ubuntu-latest' && matrix.php == '8.0' }} - run: composer require rogervila/php-sonarqube-scanner --dev - - - name: Configure sonar-project.properties - if: ${{ matrix.os == 'ubuntu-latest' && matrix.php == '8.0' }} - run: | - echo "# SonarQube Properties" > sonar-project.properties - echo "sonar.host.url=https://sonarcloud.io" >> sonar-project.properties - echo "sonar.login=${{ secrets.SONAR_TOKEN }}" >> sonar-project.properties - echo "sonar.projectKey=rogervila_array-diff-multidimensional" >> sonar-project.properties - echo "sonar.organization=rogervila-github" >> sonar-project.properties - echo "sonar.sources=." >> sonar-project.properties - echo "sonar.exclusions=vendor/**, tests/**" >> sonar-project.properties - echo "sonar.php.tests.reportPath=junit-logfile.xml" >> sonar-project.properties - echo "sonar.php.coverage.reportPaths=clover.xml" >> sonar-project.properties - - - name: Run Sonar Scanner - if: ${{ matrix.os == 'ubuntu-latest' && matrix.php == '8.0' }} - run: vendor/bin/sonar-scanner + env: + XDEBUG_MODE: coverage From 547b8f27614eb692de1940954634efe0d0d6da4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Tue, 29 Dec 2020 15:00:40 +0100 Subject: [PATCH 13/16] Update pull_request.yml --- .github/workflows/pull_request.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ea185ce..e6bdf98 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -34,3 +34,18 @@ jobs: run: vendor/bin/phpunit env: XDEBUG_MODE: coverage + + - name: Run Sonar Scanner + if: ${{ matrix.php == '8.0' && matrix.os == 'ubuntu-latest' }} + run: | + composer require rogervila/php-sonarqube-scanner --dev + echo "# SonarQube Properties" > sonar-project.properties + echo "sonar.host.url=https://sonarcloud.io" >> sonar-project.properties + echo "sonar.login=${{ secrets.SONAR_TOKEN }}" >> sonar-project.properties + echo "sonar.projectKey=rogervila_array-diff-multidimensional" >> sonar-project.properties + echo "sonar.organization=rogervila-github" >> sonar-project.properties + echo "sonar.sources=." >> sonar-project.properties + echo "sonar.exclusions=tmp/**, vendor/**, tests/**" >> sonar-project.properties + echo "sonar.php.tests.reportPath=junit-logfile.xml" >> sonar-project.properties + echo "sonar.php.coverage.reportPaths=clover.xml" >> sonar-project.properties + vendor/bin/sonar-scanner From 8cfd3fc9fcd883eb2a4d0745bfd16fe35e909134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Tue, 29 Dec 2020 15:03:56 +0100 Subject: [PATCH 14/16] automatic analysis is already enabled --- .github/workflows/pull_request.yml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index e6bdf98..ea185ce 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -34,18 +34,3 @@ jobs: run: vendor/bin/phpunit env: XDEBUG_MODE: coverage - - - name: Run Sonar Scanner - if: ${{ matrix.php == '8.0' && matrix.os == 'ubuntu-latest' }} - run: | - composer require rogervila/php-sonarqube-scanner --dev - echo "# SonarQube Properties" > sonar-project.properties - echo "sonar.host.url=https://sonarcloud.io" >> sonar-project.properties - echo "sonar.login=${{ secrets.SONAR_TOKEN }}" >> sonar-project.properties - echo "sonar.projectKey=rogervila_array-diff-multidimensional" >> sonar-project.properties - echo "sonar.organization=rogervila-github" >> sonar-project.properties - echo "sonar.sources=." >> sonar-project.properties - echo "sonar.exclusions=tmp/**, vendor/**, tests/**" >> sonar-project.properties - echo "sonar.php.tests.reportPath=junit-logfile.xml" >> sonar-project.properties - echo "sonar.php.coverage.reportPaths=clover.xml" >> sonar-project.properties - vendor/bin/sonar-scanner From b7e8fea36800d8e7a588147060f339ced376ed89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Tue, 29 Dec 2020 15:25:28 +0100 Subject: [PATCH 15/16] fix empty arrays issue --- src/ArrayDiffMultidimensional.php | 2 +- tests/ArrayCompareTest.php | 37 ++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/ArrayDiffMultidimensional.php b/src/ArrayDiffMultidimensional.php index 61744a9..f65fa8d 100644 --- a/src/ArrayDiffMultidimensional.php +++ b/src/ArrayDiffMultidimensional.php @@ -32,7 +32,7 @@ public static function compare($array1, $array2, $strict = true) continue; } - if (is_array($value)) { + if (is_array($value) && count($value) > 0) { $recursiveArrayDiff = static::compare($value, $array2[$key], $strict); if (count($recursiveArrayDiff) > 0) { diff --git a/tests/ArrayCompareTest.php b/tests/ArrayCompareTest.php index e732dae..1bd474e 100644 --- a/tests/ArrayCompareTest.php +++ b/tests/ArrayCompareTest.php @@ -317,15 +317,36 @@ public function it_detects_empty_array_change_with_strict_mode() { $diff = new ArrayDiffMultidimensional(); - $new = [[]]; - $old = [1]; + $a = [[]]; + $b = [1]; - var_dump($diff->compare($new, $old)); - // $this->assertEquals(1, count($diff->compare($new, $old))); - //($this->assertTrue(isset($diff->compare($new, $old)[0])); - //($this->assertTrue(is_int($diff->compare($new, $old)[0])); - //($this->assertEquals(123, $diff->compare($new, $old)[0]); + $this->assertEquals($a, $diff->compare($a, $b)); + $this->assertTrue(isset($diff->compare($a, $b)[0])); + } + + /** @test */ + public function it_detects_empty_array_change_with_strict_mode_on_multiple_dimensions() + { + $diff = new ArrayDiffMultidimensional(); + + $new = [ + 'a' => 'b', + 'c' => [ + 'd' => [], + ] + ]; + + $old = [ + 'a' => 'b', + 'c' => [ + 'd' => 1, + ] + ]; - $this->assertTrue(true); + $this->assertEquals([ + 'c' => [ + 'd' => [], + ] + ], $diff->compare($new, $old)); } } From c8d4e0815a1a5bb32f93bf37ec2b476f12718055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Vil=C3=A0?= Date: Mon, 11 Jan 2021 12:15:29 +0100 Subject: [PATCH 16/16] Create build.yml --- .github/workflows/build.yml | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..b8a450d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,39 @@ +name: build + +on: + push: + branches: + - master + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + php: [8.0, 7.4, 7.3, 7.2, 7.1, 7.0, 5.6, 5.5] + + name: PHP ${{ matrix.php }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@2.9.0 + with: + php-version: ${{ matrix.php }} + extensions: zip, curl, xdebug + coverage: xdebug + + - name: Update composer + run: composer selfupdate + + - name: Install dependencies + run: composer update --prefer-dist --no-interaction + + - name: Execute tests + run: vendor/bin/phpunit + env: + XDEBUG_MODE: coverage