Skip to content
Merged
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
12 changes: 6 additions & 6 deletions .github/workflows/run-tests-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: [ '8.3' ]
dependency-stability: [ 'prefer-none' ]
php-versions: ["8.5"]
dependency-stability: ["prefer-none"]

name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}}

Expand All @@ -24,6 +24,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug
- name: Install Dependencies
if: steps.vendor-cache.outputs.cache-hit != 'true'
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
Expand All @@ -35,23 +36,22 @@ jobs:
if: matrix.dependency-stability == 'prefer-lowest'
run: composer update --prefer-stable --prefer-lowest


- name: Show dir
run: pwd
- name: PHP Version
run: php --version

# Code quality

- name: Execute tests (Unit and Feature tests) via PestPHP
- name: Execute tests (Unit and Feature tests) via PHPUnit
# Set environment
env:
SESSION_DRIVER: array
run: vendor/bin/pest --coverage-clover clover.xml
run: vendor/bin/phpunit --coverage-clover clover.xml

- name: Generate test coverage badge
uses: timkrase/phpunit-coverage-badge@v1.2.1
with:
coverage_badge_path: 'badge-coverage.svg'
coverage_badge_path: "badge-coverage.svg"
push_badge: true
repo_token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.1, 8.2, 8.3]
php: [8.2, 8.3, 8.4, 8.5]
exclude:
- os: windows-latest
php: 8.1
- os: windows-latest
php: 8.2
- os: windows-latest
php: 8.3

name: P${{ matrix.php }} - ${{ matrix.os }}

Expand All @@ -27,7 +27,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, bcmath, intl, iconv, fileinfo
coverage: none
coverage: xdebug

- name: Setup problem matchers
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ vendor
.php-cs-fixer.cache
/.phpunit.cache
.DS_Store
.build/
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.0.0 - WIP
- Update to PHP 8.5
- Migrate tests from Pest PHP v2 to PHPUnit 11
- Remove deprecated code

## 1.1.0 - 2024-06-13
- Add the Arr `set()` method supports 'dot' (or custom) notation for nested arrays for setting nested values, for example, `$arr`->set('first-level.second-level.third-level', "something")`
- Renamed the `$index` parameter, into `$key` for `set()` and `get()` method. Why: in my opinion "index" is more related to array integer keys . "key" is more generic and refers to generic keys (string for example).
Expand Down
17 changes: 8 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
}
],
"require": {
"php": "^8.1|^8.2|^8.3"
"php": "^8.2|^8.3|^8.4|^8.5"
},
"require-dev": {
"laravel/pint": "^1.2",
"pestphp/pest": "^2",
"phpunit/phpunit": "^11.0",
"phpstan/phpstan": "^1.6",
"rector/rector": "^1"
},
Expand All @@ -35,18 +35,17 @@
},
"scripts": {
"all": [
"@test", "@format", "@phpstan"
"@test",
"@format",
"@phpstan"
],
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html ./.build/tests",
"phpstan": "vendor/bin/phpstan",
"format": "vendor/bin/pint"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="HiFolks Test Suite">
<directory>tests</directory>
Expand Down
10 changes: 5 additions & 5 deletions src/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public function join(string $separator = ','): string
* @param int $start start index (array start from 0, start included)
* @param int|null $end end index (array starts from 0, end not included)
*/
public function slice(int $start, int $end = null): Arr
public function slice(int $start, ?int $end = null): Arr
{
if (is_null($end)) {
$end = $this->length();
Expand Down Expand Up @@ -507,7 +507,7 @@ public function some(callable $callback): bool
*
* @param int|null $fromIndex
*/
public function includes(mixed $element, int $fromIndex = null): bool
public function includes(mixed $element, ?int $fromIndex = null): bool
{
if (is_null($fromIndex)) {
return in_array($element, $this->arr, true);
Expand Down Expand Up @@ -598,7 +598,7 @@ public function flatMap(callable $callback): self
* @param int $start start index (from 0)
* @param int|null $end end index (default, the end of array)
*/
public function fill(mixed $value, int $start = 0, int $end = null): void
public function fill(mixed $value, int $start = 0, ?int $end = null): void
{
if (is_null($end)) {
$end = $this->length() - 1;
Expand Down Expand Up @@ -665,7 +665,7 @@ public function sort(): Arr
* @param int|null $deleteCount an integer indicating the number of elements in the array to remove from $start
* @return Arr an array containing the deleted elements
*/
public function splice(int $start, int $deleteCount = null, mixed $newElements = []): Arr
public function splice(int $start, ?int $deleteCount = null, mixed $newElements = []): Arr
{
return self::make(array_splice($this->arr, $start, $deleteCount, $newElements));
}
Expand Down Expand Up @@ -770,7 +770,7 @@ public function find(callable $callback): mixed
* @param int|null $end
* @return array<int|string, mixed>
*/
public function copyWithin(int $target, int $start = 0, int $end = null): array
public function copyWithin(int $target, int $start = 0, ?int $end = null): array
{
$arrayLength = $this->length();
$chuck = $this->slice($start, $end);
Expand Down
48 changes: 28 additions & 20 deletions tests/Arr/ArrFromTest.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
<?php

use HiFolks\DataType\Arr;
namespace HiFolks\Array\Tests\Arr;

it('converts a string to an array', function (): void {
expect(Arr::from('foo')->arr())
->toBeArray()
->toBe(['f','o','o']);
});
use HiFolks\DataType\Arr;
use PHPUnit\Framework\TestCase;

it('converts a generator to an array', function (): void {
function generator(): Generator
class ArrFromTest extends TestCase
{
public function test_converts_a_string_to_an_array(): void
{
yield 1;
yield 8;
yield 7;
$result = Arr::from('foo')->arr();
$this->assertIsArray($result);
$this->assertSame(['f', 'o', 'o'], $result);
}

expect(Arr::from(generator())->arr())
->toBeArray()
->toBe([1, 8, 7]);
});
public function test_converts_a_generator_to_an_array(): void
{
$generator = function (): \Generator {
yield 1;
yield 8;
yield 7;
};

it('takes a function to map over the given array', function (): void {
expect(Arr::from([1, 2, 3], fn ($x): float|int|array => $x + $x)->arr())
->toBeArray()
->toBe([2, 4, 6]);
});
$result = Arr::from($generator())->arr();
$this->assertIsArray($result);
$this->assertSame([1, 8, 7], $result);
}

public function test_takes_a_function_to_map_over_the_given_array(): void
{
$result = Arr::from([1, 2, 3], fn ($x): float|int|array => $x + $x)->arr();
$this->assertIsArray($result);
$this->assertSame([2, 4, 6], $result);
}
}
Loading