Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Console/Commands/MakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ protected function outputDirectory(): string

protected function stub(): string
{
if ($this->input->getOption('unit')) {
return 'test.unit.stub';
}

return 'test.stub';
}

Expand Down
2 changes: 2 additions & 0 deletions src/Testing/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Phenix\Facades\Mail;
use Phenix\Facades\Queue;
use Phenix\Facades\View;
use Phenix\Testing\Concerns\InteractWithDatabase;
use Phenix\Testing\Concerns\InteractWithResponses;
use Phenix\Testing\Concerns\RefreshDatabase;
use Symfony\Component\Console\Tester\CommandTester;
Expand All @@ -22,6 +23,7 @@
abstract class TestCase extends AsyncTestCase
{
use InteractWithResponses;
use InteractWithDatabase;

protected ?AppProxy $app;
protected string $appDir;
Expand Down
2 changes: 2 additions & 0 deletions src/stubs/test.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

// uses(RefreshDatabase::class);

it('asserts truthy', function () {
expect(true)->toBeTruthy();
});
7 changes: 7 additions & 0 deletions src/stubs/test.unit.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

it('asserts truthy', function () {
expect(true)->toBeTruthy();
});
33 changes: 33 additions & 0 deletions tests/Internal/FakeCancellation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Tests\Internal;

use Amp\Cancellation;
use Closure;

class FakeCancellation implements Cancellation
{
public function subscribe(Closure $callback): string
{
return 'id';
}

public function unsubscribe(string $id): void
{
// This method is intentionally left empty because the cancellation logic is not required in this test context.
}

public function isRequested(): bool
{
return true;
}

public function throwIfRequested(): void
{
// This method is intentionally left empty in the test context.
// However, in a real implementation, this would throw an exception
// to indicate that the cancellation has been requested.
}
}
44 changes: 44 additions & 0 deletions tests/Internal/FakeChannel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Tests\Internal;

use Amp\Cancellation;
use Amp\Sync\Channel;
use Closure;

class FakeChannel implements Channel
{
public function receive(Cancellation|null $cancellation = null): mixed
{
return true;
}

public function send(mixed $data): void
{
// This method is intentionally left empty because the test context does not require
// sending data through the channel. In a production environment, this method should
// be implemented to handle the transmission of data to the intended recipient.
}

public function close(): void
{
// This method is intentionally left empty because the test context does not require
// any specific actions to be performed when the channel is closed. In a production
// environment, this method should be implemented to release resources or perform
// necessary cleanup operations.
}

public function isClosed(): bool
{
return false;
}

public function onClose(Closure $onClose): void
{
// This method is intentionally left empty because the test context does not require
// handling of the onClose callback. If used in production, this should be implemented
// to handle resource cleanup or other necessary actions when the channel is closed.
}
}
65 changes: 6 additions & 59 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

use Amp\Cancellation;
use Amp\Sync\Channel;
use Closure;
use Phenix\Testing\TestCase as TestingTestCase;
use Phenix\Testing\TestCase as BaseTestCase;
use Tests\Internal\FakeCancellation;
use Tests\Internal\FakeChannel;

class TestCase extends TestingTestCase
class TestCase extends BaseTestCase
{
protected function getAppDir(): string
{
Expand All @@ -18,65 +19,11 @@ protected function getAppDir(): string

protected function getFakeChannel(): Channel
{
return new class () implements Channel {
public function receive(Cancellation|null $cancellation = null): mixed
{
return true;
}

public function send(mixed $data): void
{
// This method is intentionally left empty because the test context does not require
// sending data through the channel. In a production environment, this method should
// be implemented to handle the transmission of data to the intended recipient.
}

public function close(): void
{
// This method is intentionally left empty because the test context does not require
// any specific actions to be performed when the channel is closed. In a production
// environment, this method should be implemented to release resources or perform
// necessary cleanup operations.
}

public function isClosed(): bool
{
return false;
}

public function onClose(Closure $onClose): void
{
// This method is intentionally left empty because the test context does not require
// handling of the onClose callback. If used in production, this should be implemented
// to handle resource cleanup or other necessary actions when the channel is closed.
}
};
return new FakeChannel();
}

protected function getFakeCancellation(): Cancellation
{
return new class () implements Cancellation {
public function subscribe(Closure $callback): string
{
return 'id';
}

public function unsubscribe(string $id): void
{
// This method is intentionally left empty because the cancellation logic is not required in this test context.
}

public function isRequested(): bool
{
return true;
}

public function throwIfRequested(): void
{
// This method is intentionally left empty in the test context.
// However, in a real implementation, this would throw an exception
// to indicate that the cancellation has been requested.
}
};
return new FakeCancellation();
}
}