Skip to content

Commit a34687c

Browse files
Migrate tests from Pest PHP v2 to PHPUnit 11 (PHP8.5)
Migrate tests from Pest PHP v2 to PHPUnit 11
2 parents 53470bc + c5d944a commit a34687c

17 files changed

Lines changed: 1361 additions & 1290 deletions

.github/workflows/run-tests-coverage.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
strategy:
1414
matrix:
1515
operating-system: [ubuntu-latest]
16-
php-versions: [ '8.3' ]
17-
dependency-stability: [ 'prefer-none' ]
16+
php-versions: ["8.5"]
17+
dependency-stability: ["prefer-none"]
1818

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

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

38-
3939
- name: Show dir
4040
run: pwd
4141
- name: PHP Version
4242
run: php --version
4343

4444
# Code quality
4545

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

5252
- name: Generate test coverage badge
5353
uses: timkrase/phpunit-coverage-badge@v1.2.1
5454
with:
55-
coverage_badge_path: 'badge-coverage.svg'
55+
coverage_badge_path: "badge-coverage.svg"
5656
push_badge: true
5757
repo_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/run-tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ jobs:
99
fail-fast: true
1010
matrix:
1111
os: [ubuntu-latest, windows-latest]
12-
php: [8.1, 8.2, 8.3]
12+
php: [8.2, 8.3, 8.4, 8.5]
1313
exclude:
14-
- os: windows-latest
15-
php: 8.1
1614
- os: windows-latest
1715
php: 8.2
16+
- os: windows-latest
17+
php: 8.3
1818

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

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

3232
- name: Setup problem matchers
3333
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ vendor
1212
.php-cs-fixer.cache
1313
/.phpunit.cache
1414
.DS_Store
15+
.build/

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 2.0.0 - WIP
4+
- Update to PHP 8.5
5+
- Migrate tests from Pest PHP v2 to PHPUnit 11
6+
- Remove deprecated code
7+
38
## 1.1.0 - 2024-06-13
49
- 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")`
510
- 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).

composer.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^8.1|^8.2|^8.3"
18+
"php": "^8.2|^8.3|^8.4|^8.5"
1919
},
2020
"require-dev": {
2121
"laravel/pint": "^1.2",
22-
"pestphp/pest": "^2",
22+
"phpunit/phpunit": "^11.0",
2323
"phpstan/phpstan": "^1.6",
2424
"rector/rector": "^1"
2525
},
@@ -35,18 +35,17 @@
3535
},
3636
"scripts": {
3737
"all": [
38-
"@test", "@format", "@phpstan"
38+
"@test",
39+
"@format",
40+
"@phpstan"
3941
],
40-
"test": "vendor/bin/pest",
41-
"test-coverage": "vendor/bin/pest --coverage",
42+
"test": "vendor/bin/phpunit",
43+
"test-coverage": "vendor/bin/phpunit --coverage-html ./.build/tests",
4244
"phpstan": "vendor/bin/phpstan",
4345
"format": "vendor/bin/pint"
4446
},
4547
"config": {
46-
"sort-packages": true,
47-
"allow-plugins": {
48-
"pestphp/pest-plugin": true
49-
}
48+
"sort-packages": true
5049
},
5150
"minimum-stability": "dev",
5251
"prefer-stable": true

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<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">
33
<testsuites>
44
<testsuite name="HiFolks Test Suite">
55
<directory>tests</directory>

src/Arr.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public function join(string $separator = ','): string
432432
* @param int $start start index (array start from 0, start included)
433433
* @param int|null $end end index (array starts from 0, end not included)
434434
*/
435-
public function slice(int $start, int $end = null): Arr
435+
public function slice(int $start, ?int $end = null): Arr
436436
{
437437
if (is_null($end)) {
438438
$end = $this->length();
@@ -507,7 +507,7 @@ public function some(callable $callback): bool
507507
*
508508
* @param int|null $fromIndex
509509
*/
510-
public function includes(mixed $element, int $fromIndex = null): bool
510+
public function includes(mixed $element, ?int $fromIndex = null): bool
511511
{
512512
if (is_null($fromIndex)) {
513513
return in_array($element, $this->arr, true);
@@ -598,7 +598,7 @@ public function flatMap(callable $callback): self
598598
* @param int $start start index (from 0)
599599
* @param int|null $end end index (default, the end of array)
600600
*/
601-
public function fill(mixed $value, int $start = 0, int $end = null): void
601+
public function fill(mixed $value, int $start = 0, ?int $end = null): void
602602
{
603603
if (is_null($end)) {
604604
$end = $this->length() - 1;
@@ -665,7 +665,7 @@ public function sort(): Arr
665665
* @param int|null $deleteCount an integer indicating the number of elements in the array to remove from $start
666666
* @return Arr an array containing the deleted elements
667667
*/
668-
public function splice(int $start, int $deleteCount = null, mixed $newElements = []): Arr
668+
public function splice(int $start, ?int $deleteCount = null, mixed $newElements = []): Arr
669669
{
670670
return self::make(array_splice($this->arr, $start, $deleteCount, $newElements));
671671
}
@@ -770,7 +770,7 @@ public function find(callable $callback): mixed
770770
* @param int|null $end
771771
* @return array<int|string, mixed>
772772
*/
773-
public function copyWithin(int $target, int $start = 0, int $end = null): array
773+
public function copyWithin(int $target, int $start = 0, ?int $end = null): array
774774
{
775775
$arrayLength = $this->length();
776776
$chuck = $this->slice($start, $end);

tests/Arr/ArrFromTest.php

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
<?php
22

3-
use HiFolks\DataType\Arr;
3+
namespace HiFolks\Array\Tests\Arr;
44

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

11-
it('converts a generator to an array', function (): void {
12-
function generator(): Generator
8+
class ArrFromTest extends TestCase
9+
{
10+
public function test_converts_a_string_to_an_array(): void
1311
{
14-
yield 1;
15-
yield 8;
16-
yield 7;
12+
$result = Arr::from('foo')->arr();
13+
$this->assertIsArray($result);
14+
$this->assertSame(['f', 'o', 'o'], $result);
1715
}
1816

19-
expect(Arr::from(generator())->arr())
20-
->toBeArray()
21-
->toBe([1, 8, 7]);
22-
});
17+
public function test_converts_a_generator_to_an_array(): void
18+
{
19+
$generator = function (): \Generator {
20+
yield 1;
21+
yield 8;
22+
yield 7;
23+
};
2324

24-
it('takes a function to map over the given array', function (): void {
25-
expect(Arr::from([1, 2, 3], fn ($x): float|int|array => $x + $x)->arr())
26-
->toBeArray()
27-
->toBe([2, 4, 6]);
28-
});
25+
$result = Arr::from($generator())->arr();
26+
$this->assertIsArray($result);
27+
$this->assertSame([1, 8, 7], $result);
28+
}
29+
30+
public function test_takes_a_function_to_map_over_the_given_array(): void
31+
{
32+
$result = Arr::from([1, 2, 3], fn ($x): float|int|array => $x + $x)->arr();
33+
$this->assertIsArray($result);
34+
$this->assertSame([2, 4, 6], $result);
35+
}
36+
}

0 commit comments

Comments
 (0)