Skip to content

Commit

Permalink
wip #41 remove filesystem dep
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed May 16, 2024
1 parent e11b7b1 commit 73835c1
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 42 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"chevere/regex": "^1.0.1"
},
"require-dev": {
"chevere/filesystem": "^1.0.0",
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^9.5",
"symplify/easy-coding-standard": "^11.1"
Expand Down
4 changes: 2 additions & 2 deletions tests/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use ArgumentCountError;
use BadMethodCallException;
use Chevere\Filesystem\Interfaces\PathInterface;
use Chevere\Tests\src\TestActionNoParams;
use Chevere\Tests\src\TestActionNoParamsIntResponse;
use Chevere\Tests\src\TestActionObjectConflict;
Expand All @@ -25,6 +24,7 @@
use InvalidArgumentException;
use OverflowException;
use PHPUnit\Framework\TestCase;
use stdClass;
use function Chevere\Workflow\response;
use function Chevere\Workflow\variable;

Expand Down Expand Up @@ -190,7 +190,7 @@ public function testWithMissingArgument(): void
$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage(
'Missing argument(s) [`'
. PathInterface::class
. stdClass::class
. ' path`] for `'
. TestActionObjectConflict::class
. '`'
Expand Down
37 changes: 20 additions & 17 deletions tests/RunnerParallelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,45 @@

namespace Chevere\Tests;

use Chevere\Filesystem\File;
use Chevere\Filesystem\Interfaces\DirectoryInterface;
use Chevere\Filesystem\Interfaces\FileInterface;
use Chevere\Tests\src\TestActionFileWrite;
use PHPUnit\Framework\TestCase;
use function Chevere\Filesystem\directoryForPath;
use function Chevere\Workflow\async;
use function Chevere\Workflow\run;
use function Chevere\Workflow\workflow;

final class RunnerParallelTest extends TestCase
{
private DirectoryInterface $directory;
private string $directory;

private FileInterface $file;
private string $file;

protected function setUp(): void
{
$this->directory = directoryForPath(__DIR__ . '/_resources');
$this->directory->createIfNotExists();
$this->file = new File(
$this->directory->path()->getChild('output-parallel')
);
$this->directory = __DIR__ . '/_resources/';
if (! is_dir($this->directory)) {
mkdir($this->directory);
}
$this->file = $this->directory . 'output-parallel';
if (file_exists($this->file)) {
unlink($this->file);
}
}

protected function tearDown(): void
{
$this->directory->removeIfExists();
if (file_exists($this->file)) {
unlink($this->file);
}
if (is_dir($this->directory)) {
rmdir($this->directory);
}
}

public function testParallelRunner(): void
{
$this->file->removeIfExists();
$this->file->create();
$this->file->put('');
if (file_put_contents($this->file, '') === false) {
$this->markTestIncomplete('Unable to write to file');
}
$workflow = workflow(
j1: async(
new TestActionFileWrite(),
Expand All @@ -60,9 +64,8 @@ public function testParallelRunner(): void
);
run($workflow);
$this->assertStringEqualsFile(
$this->file->path()->__toString(),
$this->file,
'^^$$'
);
$this->file->removeIfExists();
}
}
37 changes: 20 additions & 17 deletions tests/RunnerSequentialTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,45 @@

namespace Chevere\Tests;

use Chevere\Filesystem\File;
use Chevere\Filesystem\Interfaces\DirectoryInterface;
use Chevere\Filesystem\Interfaces\FileInterface;
use Chevere\Tests\src\TestActionFileWrite;
use PHPUnit\Framework\TestCase;
use function Chevere\Filesystem\directoryForPath;
use function Chevere\Workflow\async;
use function Chevere\Workflow\run;
use function Chevere\Workflow\workflow;

final class RunnerSequentialTest extends TestCase
{
private DirectoryInterface $directory;
private string $directory;

private FileInterface $file;
private string $file;

protected function setUp(): void
{
$this->directory = directoryForPath(__DIR__ . '/_resources');
$this->directory->createIfNotExists();
$this->file = new File(
$this->directory->path()->getChild('output-sequential')
);
$this->directory = __DIR__ . '/_resources/';
if (! is_dir($this->directory)) {
mkdir($this->directory);
}
$this->file = $this->directory . 'output-sequential';
if (file_exists($this->file)) {
unlink($this->file);
}
}

protected function tearDown(): void
{
$this->directory->removeIfExists();
if (file_exists($this->file)) {
unlink($this->file);
}
if (is_dir($this->directory)) {
rmdir($this->directory);
}
}

public function testSequentialRunner(): void
{
$this->file->removeIfExists();
$this->file->create();
$this->file->put('');
if (file_put_contents($this->file, '') === false) {
$this->markTestIncomplete('Unable to write to file');
}
$workflow = workflow(
j1: async(
new TestActionFileWrite(),
Expand All @@ -60,9 +64,8 @@ public function testSequentialRunner(): void
);
run($workflow);
$this->assertStringEqualsFile(
$this->file->path()->__toString(),
$this->file,
'^$^$'
);
$this->file->removeIfExists();
}
}
5 changes: 2 additions & 3 deletions tests/src/TestActionFileWrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Chevere\Tests\src;

use Chevere\Action\Action;
use Chevere\Filesystem\Interfaces\FileInterface;
use Chevere\Parameter\Interfaces\ParameterInterface;
use function Chevere\Parameter\null;

Expand All @@ -25,9 +24,9 @@ public static function return(): ParameterInterface
return null();
}

public function main(FileInterface $file): void
public function main(string $file): void
{
$fp = fopen($file->path()->__toString(), 'a+');
$fp = fopen($file, 'a+');
fwrite($fp, '^');
usleep(200000);
fwrite($fp, '$');
Expand Down
4 changes: 2 additions & 2 deletions tests/src/TestActionObjectConflict.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
namespace Chevere\Tests\src;

use Chevere\Action\Action;
use Chevere\Filesystem\Interfaces\PathInterface;
use stdClass;

class TestActionObjectConflict extends Action
{
public function main(PathInterface $path, string $bar): array
public function main(stdClass $path, string $bar): array
{
return [];
}
Expand Down

0 comments on commit 73835c1

Please sign in to comment.