Skip to content

Commit c2628e5

Browse files
authored
Merge pull request #17 from codebar-ag/feature-fix-failing-test
Feature fix failing test
2 parents dc50697 + 43897e6 commit c2628e5

File tree

9 files changed

+77
-31
lines changed

9 files changed

+77
-31
lines changed

.github/workflows/dependabot-auto-merge.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ jobs:
1010
runs-on: ubuntu-latest
1111
if: ${{ github.actor == 'dependabot[bot]' }}
1212
steps:
13-
13+
1414
- name: Dependabot metadata
1515
id: metadata
1616
uses: dependabot/[email protected]
1717
with:
1818
github-token: "${{ secrets.GITHUB_TOKEN }}"
19-
19+
2020
- name: Auto-merge Dependabot PRs for semver-minor updates
2121
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}}
2222
run: gh pr merge --auto --merge "$PR_URL"
2323
env:
2424
PR_URL: ${{github.event.pull_request.html_url}}
2525
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
26-
26+
2727
- name: Auto-merge Dependabot PRs for semver-patch updates
2828
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
2929
run: gh pr merge --auto --merge "$PR_URL"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependency Review Action
2+
#
3+
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
4+
#
5+
# Source repository: https://github.com/actions/dependency-review-action
6+
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
7+
name: 'Dependency Review'
8+
on: [pull_request]
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
dependency-review:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: 'Checkout Repository'
18+
uses: actions/checkout@v3
19+
- name: 'Dependency Review'
20+
uses: actions/dependency-review-action@v3

.github/workflows/run-tests.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ name: run-tests
22

33
on:
44
push:
5-
branches: [main]
5+
branches: [ main ]
66
pull_request:
7-
branches: [main]
7+
branches: [ main ]
88

99
jobs:
1010
test:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
fail-fast: true
1414
matrix:
15-
os: [ubuntu-latest, windows-latest]
16-
php: [8.1]
17-
laravel: [9.*]
18-
stability: [prefer-lowest, prefer-stable]
15+
os: [ ubuntu-latest, windows-latest ]
16+
php: [ 8.1 ]
17+
laravel: [ 9.* ]
18+
stability: [ prefer-lowest, prefer-stable ]
1919
include:
2020
- laravel: 9.*
2121
testbench: 7.*

phpstan-baseline.neon

Whitespace-only changes.

phpstan.neon.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
4+
parameters:
5+
level: 4
6+
paths:
7+
- src
8+
- config
9+
tmpDir: build/phpstan
10+
checkOctaneCompatibility: true
11+
checkModelProperties: true
12+
checkMissingIterableValueType: false
13+

src/FlysystemCloudinaryAdapter.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727

2828
class FlysystemCloudinaryAdapter implements FilesystemAdapter
2929
{
30+
public array|false $meta;
31+
32+
public bool $copied;
33+
34+
public bool $deleted;
35+
3036
private const EXTRA_METADATA_FIELDS = [
3137
'version',
3238
'width',
@@ -338,7 +344,7 @@ public function read(string $path): string
338344
/**
339345
* {@inheritDoc}
340346
*/
341-
public function readStream($path): array|false
347+
public function readStream($path): array|false /** @phpstan-ignore-line */
342348
{
343349
$path = $this->ensureFolderIsPrefixed(trim($path, '/'));
344350

@@ -472,7 +478,7 @@ private function getMetadata(string $path, string $type): FileAttributes
472478
throw UnableToRetrieveMetadata::create($path, $type, '', $exception);
473479
}
474480

475-
$attributes = $this->mapToFileAttributes($result, $path);
481+
$attributes = $this->mapToFileAttributes($result);
476482

477483
if (! $attributes instanceof FileAttributes) {
478484
throw UnableToRetrieveMetadata::create($path, $type);
@@ -497,7 +503,7 @@ private function extractExtraMetadata(array $metadata): array
497503
{
498504
$extracted = [];
499505

500-
foreach (static::EXTRA_METADATA_FIELDS as $field) {
506+
foreach (self::EXTRA_METADATA_FIELDS as $field) {
501507
if (isset($metadata[$field]) && $metadata[$field] !== '') {
502508
$extracted[$field] = $metadata[$field];
503509
}
@@ -649,20 +655,19 @@ public function directoryExists(string $path): bool
649655
do {
650656
$response = (array) $this->cloudinary->adminApi()->subFolders($needle, [
651657
'max_results' => 4,
652-
'next_cursor' => isset($response['next_cursor']) ? $response['next_cursor'] : null,
658+
'next_cursor' => isset($response['next_cursor']) ? $response['next_cursor'] : null, /** @phpstan-ignore-line */
653659
]);
654660

655-
$folders = array_merge($folders, $response['folders']);
656-
} while (array_key_exists('next_cursor', $response) && ! is_null($response['next_cursor']));
657-
661+
$folders = array_merge($folders, $response['folders']); /** @phpstan-ignore-line */
662+
} while (array_key_exists('next_cursor', $response) && ! is_null($response['next_cursor'])); /** @phpstan-ignore-line */
658663
$folders_found = array_filter(
659664
$folders,
660665
function ($e) use ($path) {
661666
return $e['path'] == $path;
662667
}
663668
);
664669

665-
return count($folders_found);
670+
return count($folders_found) > 0;
666671
}
667672

668673
public function deleteDirectory(string $path): void
@@ -690,12 +695,12 @@ public function getVisibility($path): string
690695
return $this->visibility($path)->visibility();
691696
}
692697

693-
public function getTimestamp($path): string
698+
public function getTimestamp($path): int
694699
{
695700
return $this->lastModified($path)->lastModified();
696701
}
697702

698-
public function getSize($path): string
703+
public function getSize($path): int
699704
{
700705
return $this->fileSize($path)->fileSize();
701706
}

tests/Feature/AdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class AdapterTest extends TestCase
1616
{
17-
public FlysystemCloudinaryAdapter $adapter;
17+
// public FlysystemCloudinaryAdapter $adapter;
1818

1919
protected function setUp(): void
2020
{

tests/Integration/CloudinaryTest.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace CodebarAg\FlysystemCloudinary\Tests\Integration;
44

5-
use Cloudinary\Cloudinary;
65
use CodebarAg\FlysystemCloudinary\FlysystemCloudinaryAdapter;
76
use CodebarAg\FlysystemCloudinary\Tests\TestCase;
87
use Illuminate\Http\Testing\File;
@@ -19,16 +18,7 @@ protected function setUp(): void
1918
{
2019
parent::setUp();
2120

22-
$cloudinary = new Cloudinary([
23-
'cloud_name' => env('CLOUDINARY_CLOUD_NAME'),
24-
'api_key' => env('CLOUDINARY_API_KEY'),
25-
'api_secret' => env('CLOUDINARY_API_SECRET'),
26-
'url' => [
27-
'secure' => true,
28-
],
29-
]);
30-
31-
$this->adapter = new FlysystemCloudinaryAdapter($cloudinary);
21+
$this->adapter = self::$cloudinaryAdapter;
3222
}
3323

3424
/** @test */

tests/TestCase.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
namespace CodebarAg\FlysystemCloudinary\Tests;
44

5+
use Cloudinary\Cloudinary;
6+
use CodebarAg\FlysystemCloudinary\FlysystemCloudinaryAdapter;
57
use CodebarAg\FlysystemCloudinary\FlysystemCloudinaryServiceProvider;
68
use Orchestra\Testbench\TestCase as Orchestra;
79

810
class TestCase extends Orchestra
911
{
12+
public static FlysystemCloudinaryAdapter $cloudinaryAdapter;
13+
1014
protected function getPackageProviders($app): array
1115
{
1216
return [
@@ -18,4 +22,18 @@ public function getEnvironmentSetUp($app): void
1822
{
1923
config()->set('database.default', 'testing');
2024
}
25+
26+
public static function setUpBeforeClass(): void
27+
{
28+
$cloudinary = new Cloudinary([
29+
'cloud_name' => env('CLOUDINARY_CLOUD_NAME'),
30+
'api_key' => env('CLOUDINARY_API_KEY'),
31+
'api_secret' => env('CLOUDINARY_API_SECRET'),
32+
'url' => [
33+
'secure' => true,
34+
],
35+
]);
36+
37+
self::$cloudinaryAdapter = new FlysystemCloudinaryAdapter($cloudinary);
38+
}
2139
}

0 commit comments

Comments
 (0)