Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  add roave bc check
  replace eris by blackbox
  split jobs between coverage and full tests run
  send activity for all loaded files (even inside directories)
  only run 10 scenarii on dev environment
  use blackbox printer
  fix test
  • Loading branch information
Baptouuuu committed Jun 14, 2020
2 parents ab39d8b + ab5f597 commit 8dbcd7c
Show file tree
Hide file tree
Showing 12 changed files with 594 additions and 44 deletions.
41 changes: 40 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -3,13 +3,52 @@ name: CI
on: [push]

jobs:
roave_bc_check:
name: Roave BC Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: fetch tags
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Roave BC Check
uses: docker://nyholm/roave-bc-check-ga
phpunit:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['7.4']
name: 'PHPUnit - PHP/${{ matrix.php-version }} - OS/${{ matrix.os }}'
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Dependencies
run: composer install --no-progress
- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.clover
env:
CI: 'github'
coverage:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
php-version: ['7.4']
name: 'Coverage - PHP/${{ matrix.php-version }} - OS/${{ matrix.os }}'
steps:
- name: Checkout
uses: actions/checkout@v1
Expand All @@ -19,7 +58,6 @@ jobs:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl
coverage: xdebug
ini-values: xdebug.max_nesting_level=2048
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
Expand All @@ -35,6 +73,7 @@ jobs:
run: vendor/bin/phpunit --coverage-clover=coverage.clover
env:
CI: 'github'
BLACKBOX_SET_SIZE: '1'
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
1 change: 0 additions & 1 deletion composer.json
Expand Up @@ -36,7 +36,6 @@
},
"require-dev": {
"phpunit/phpunit": "~8.0",
"giorgiosironi/eris": "^0.11.0",
"innmind/object-graph": "~2.0",
"vimeo/psalm": "^3.10",
"innmind/black-box": "^4.2"
Expand Down
5 changes: 4 additions & 1 deletion phpunit.xml.dist
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true" bootstrap="vendor/autoload.php">
<phpunit colors="true" bootstrap="vendor/autoload.php" printerClass="Innmind\BlackBox\PHPUnit\ResultPrinterV8">
<php>
<env name="BLACKBOX_SET_SIZE" value="10" />
</php>
<testsuites>
<testsuite name="Test suite">
<directory>./tests</directory>
Expand Down
39 changes: 24 additions & 15 deletions src/OperatingSystem/Filesystem/Adapter.php
Expand Up @@ -6,12 +6,12 @@
use Innmind\SilentCartographer\{
SendActivity,
Room\Program\Activity\Filesystem\FilePersisted,
Room\Program\Activity\Filesystem\FileLoaded,
Room\Program\Activity\Filesystem\FileRemoved,
};
use Innmind\Filesystem\{
Adapter as AdapterInterface,
File,
File as FileInterface,
Directory as DirectoryInterface,
Name,
};
use Innmind\Url\Path;
Expand All @@ -21,7 +21,7 @@ final class Adapter implements AdapterInterface
{
private AdapterInterface $adapter;
private SendActivity $send;
private string $path;
private Path $path;

public function __construct(
AdapterInterface $adapter,
Expand All @@ -30,10 +30,10 @@ public function __construct(
) {
$this->adapter = $adapter;
$this->send = $send;
$this->path = \rtrim($path->toString(), '/');
$this->path = $path;
}

public function add(File $file): void
public function add(FileInterface $file): void
{
($this->send)(new FilePersisted($this->path($file->name())));
$this->adapter->add($file);
Expand All @@ -42,11 +42,9 @@ public function add(File $file): void
/**
* {@inheritdoc}
*/
public function get(Name $file): File
public function get(Name $file): FileInterface
{
($this->send)(new FileLoaded($this->path($file)));

return $this->adapter->get($file);
return $this->wrap($this->adapter->get($file));
}

public function contains(Name $file): bool
Expand All @@ -68,16 +66,27 @@ public function remove(Name $file): void
*/
public function all(): Set
{
$all = $this->adapter->all();
$all->foreach(function(File $file): void {
($this->send)(new FileLoaded($this->path($file->name())));
});
return $this
->adapter
->all()
->map(fn(FileInterface $file): FileInterface => $this->wrap($file));
}

private function wrap(FileInterface $file): FileInterface
{
if ($file instanceof DirectoryInterface) {
return Directory::load(
$file,
$this->send,
$this->path->resolve(Path::of($file->name()->toString().'/')),
);
}

return $all;
return new File($file, $this->send, $this->path);
}

private function path(Name $file): Path
{
return Path::of($this->path.'/'.$file->toString());
return $this->path->resolve(Path::of($file->toString()));
}
}
151 changes: 151 additions & 0 deletions src/OperatingSystem/Filesystem/Directory.php
@@ -0,0 +1,151 @@
<?php
declare(strict_types = 1);

namespace Innmind\SilentCartographer\OperatingSystem\Filesystem;

use Innmind\SilentCartographer\{
SendActivity,
Room\Program\Activity\Filesystem\FileLoaded,
};
use Innmind\Filesystem\{
Directory as DirectoryInterface,
File as FileInterface,
Name,
};
use Innmind\Stream\Readable;
use Innmind\MediaType\MediaType;
use Innmind\Url\Path;
use Innmind\Immutable\{
Sequence,
Set,
};

final class Directory implements DirectoryInterface
{
private DirectoryInterface $directory;
private SendActivity $send;
private Path $path;

private function __construct(
DirectoryInterface $directory,
SendActivity $send,
Path $path
) {
$this->directory = $directory;
$this->send = $send;
$this->path = $path;
}

public static function load(
DirectoryInterface $directory,
SendActivity $send,
Path $path
): self {
$self = new self($directory, $send, $path);
$send(new FileLoaded($path));

return $self;
}

public function name(): Name
{
return $this->directory->name();
}

public function content(): Readable
{
return $this->directory->content();
}

public function mediaType(): MediaType
{
return $this->directory->mediaType();
}

public function add(FileInterface $file): DirectoryInterface
{
return new self(
$this->directory->add($file),
$this->send,
$this->path,
);
}

public function get(Name $name): FileInterface
{
return $this->wrap($this->directory->get($name));
}

public function contains(Name $name): bool
{
return $this->directory->contains($name);
}

public function remove(Name $name): DirectoryInterface
{
$directory = $this->directory->remove($name);

if ($directory === $this->directory) {
return $this;
}

return new self(
$this->directory->remove($name),
$this->send,
$this->path,
);
}

public function replaceAt(Path $path, FileInterface $file): DirectoryInterface
{
return new self(
$this->directory->replaceAt($path, $file),
$this->send,
$this->path,
);
}

public function foreach(callable $function): void
{
$this->directory->foreach(function(FileInterface $file) use ($function): void {
$function($this->wrap($file));
});
}

public function filter(callable $predicate): Set
{
return $this->directory->filter(function(FileInterface $file) use ($predicate): bool {
return $predicate($this->wrap($file));
});
}

public function reduce($carry, callable $reducer)
{
/** @psalm-suppress MissingClosureParamType */
return $this->directory->reduce(
$carry,
function($carry, FileInterface $file) use ($reducer) {
/** @psalm-suppress MixedArgument */
return $reducer($carry, $this->wrap($file));
},
);
}

public function modifications(): Sequence
{
return $this->directory->modifications();
}

private function wrap(FileInterface $file): FileInterface
{
if ($file instanceof DirectoryInterface) {
return new self(
$file,
$this->send,
$this->path->resolve(Path::of($file->name()->toString().'/')),
);
}

return new File($file, $this->send, $this->path);
}
}
45 changes: 45 additions & 0 deletions src/OperatingSystem/Filesystem/File.php
@@ -0,0 +1,45 @@
<?php
declare(strict_types = 1);

namespace Innmind\SilentCartographer\OperatingSystem\Filesystem;

use Innmind\SilentCartographer\{
SendActivity,
Room\Program\Activity\Filesystem\FileLoaded,
};
use Innmind\Filesystem\{
File as FileInterface,
Name,
};
use Innmind\Stream\Readable;
use Innmind\MediaType\MediaType;
use Innmind\Url\Path;

final class File implements FileInterface
{
private FileInterface $file;

public function __construct(
FileInterface $file,
SendActivity $send,
Path $folder
) {
$this->file = $file;
$send(new FileLoaded($folder->resolve(Path::of($file->name()->toString()))));
}

public function name(): Name
{
return $this->file->name();
}

public function content(): Readable
{
return $this->file->content();
}

public function mediaType(): MediaType
{
return $this->file->mediaType();
}
}

0 comments on commit 8dbcd7c

Please sign in to comment.