Skip to content

Commit 27f34eb

Browse files
committed
✅ Adds FTP tests
1 parent d598148 commit 27f34eb

File tree

5 files changed

+108
-2
lines changed

5 files changed

+108
-2
lines changed

.github/workflows/test.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Test
2+
3+
concurrency:
4+
group: testing-${{ github.head_ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
# push:
9+
# branches: [ "main", "staging" ]
10+
pull_request:
11+
branches: [ "main" ]
12+
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
17+
jobs:
18+
build:
19+
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
25+
- name: Setup PHP
26+
id: setup-php
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: '8.4'
30+
# ini-values: date.timezone=Europe/Paris
31+
32+
- name: Validate composer.json and composer.lock
33+
run: composer validate --strict
34+
35+
- name: Cache Composer packages
36+
id: composer-cache
37+
uses: actions/cache@v3
38+
with:
39+
path: .package
40+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
41+
restore-keys: |
42+
${{ runner.os }}-php-
43+
44+
- name: Install dependencies
45+
run: composer install --prefer-dist --no-progress
46+
47+
- name: Run linter suite
48+
run: PHP_CS_FIXER_IGNORE_ENV=1 .vendor/bin/php-cs-fixer fix --config=set/php-cs-fixer.php -v --dry-run
49+
50+
- name: Run analyse suite
51+
run: composer run analyse
52+
53+
- name: Start containers
54+
run: docker-compose -f "docker-compose.yml" up -d --build
55+
56+
- name: Run test suite
57+
env:
58+
XDEBUG_MODE: coverage
59+
run: .vendor/bin/phpunit --configuration=phpunit.xml

component/Service/Ftp.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public function __construct(
2222
password: $password,
2323
port: $port
2424
);
25+
26+
ftp_pasv($this->connection, true);
2527
}
2628

2729
private function connect(string $host, string $username, string $password, int $port): Connection

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"require": {
1313
"php": ">=8.1",
1414
"phant/error": "1.*",
15-
"aws/aws-sdk-php": "3.*"
15+
"aws/aws-sdk-php": "3.*",
16+
"phpunit/phpunit": "^12.4"
1617
},
1718
"require-dev": {
1819
"friendsofphp/php-cs-fixer": "^3.0",
@@ -24,7 +25,8 @@
2425
},
2526
"autoload": {
2627
"psr-4": {
27-
"Phant\\Client\\": "component/"
28+
"Phant\\Client\\": "component/",
29+
"Tests\\": "tests/"
2830
}
2931
}
3032
}

phpunit.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<phpunit bootstrap="vendor/autoload.php">
2+
<testsuites>
3+
<testsuite name="component">
4+
<directory>tests</directory>
5+
</testsuite>
6+
</testsuites>
7+
<coverage processUncoveredFiles="true">
8+
<include>
9+
<directory suffix=".php">component</directory>
10+
</include>
11+
</coverage>
12+
</phpunit>

tests/FtpTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests;
6+
7+
use Phant\Client\Service\Ftp;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class FtpTest extends TestCase
11+
{
12+
private Ftp $ftp;
13+
14+
protected function setUp(): void
15+
{
16+
$this->ftp = new Ftp(
17+
'localhost',
18+
'user',
19+
'pass',
20+
2121
21+
);
22+
}
23+
24+
public function testListFiles(): void
25+
{
26+
$files = $this->ftp->listFiles('/');
27+
$this->assertIsArray($files);
28+
$this->assertNotEmpty($files);
29+
$this->assertContains('testfile.json', $files);
30+
}
31+
}

0 commit comments

Comments
 (0)