Skip to content

Commit

Permalink
PHPUnit 10 (#927)
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Apr 25, 2023
1 parent 456e015 commit e0341b6
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 61 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -36,7 +36,7 @@
},
"require-dev": {
"spiral/boot": "^3.8",
"phpunit/phpunit": "^9.5.20",
"phpunit/phpunit": "^10.1",
"mockery/mockery": "^1.5",
"vimeo/psalm": "^5.9"
},
Expand Down
2 changes: 1 addition & 1 deletion tests/AttributeTest.php
Expand Up @@ -11,7 +11,7 @@
use Spiral\Tests\Console\Fixtures\Attribute\WithNameCommand;
use Spiral\Tests\Console\Fixtures\Attribute\WithSymfonyAttributeCommand;

final class AttributeTest extends BaseTest
final class AttributeTest extends BaseTestCase
{
public function setUp(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/BaseTest.php → tests/BaseTestCase.php
Expand Up @@ -15,7 +15,7 @@
use Spiral\Core\Container;
use Spiral\Tokenizer\ScopedClassesInterface;

abstract class BaseTest extends TestCase
abstract class BaseTestCase extends TestCase
{
public const TOKENIZER_CONFIG = [
'directories' => [__DIR__ . '/Fixtures/'],
Expand Down
19 changes: 5 additions & 14 deletions tests/ConfigureTest.php
Expand Up @@ -11,10 +11,11 @@
use Spiral\Tests\Console\Fixtures\FailedCommand;
use Spiral\Tests\Console\Fixtures\HelperCommand;
use Spiral\Tests\Console\Fixtures\TestCommand;
use Spiral\Tests\Console\Fixtures\UpdateClass;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;

class ConfigureTest extends BaseTest
class ConfigureTest extends BaseTestCase
{
public const TOKENIZER_CONFIG = [
'directories' => [__DIR__.'/../src/Command', __DIR__.'/Fixtures/'],
Expand All @@ -27,10 +28,10 @@ class ConfigureTest extends BaseTest
'configure' => [
['command' => 'test', 'header' => 'Test Command'],
['command' => 'helper', 'options' => ['helper' => 'writeln'], 'footer' => 'Good!'],
['invoke' => [self::class, 'do']],
['invoke' => self::class.'::do'],
['invoke' => [UpdateClass::class, 'do']],
['invoke' => UpdateClass::class.'::do'],
'Spiral\Tests\Console\ok',
['invoke' => self::class.'::err'],
['invoke' => UpdateClass::class.'::err'],
],
],
];
Expand Down Expand Up @@ -124,16 +125,6 @@ public function testNoBreakFailure(): void
$this->assertEquals(1, $output->getCode());
}

public function do(OutputInterface $output): void
{
$output->write('OK');
}

public function err(OutputInterface $output): void
{
throw new ShortException('Failed configure command');
}

/**
* @return Console
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/CoreTest.php
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;

class CoreTest extends BaseTest
class CoreTest extends BaseTestCase
{
public function testWelcome(): void
{
Expand Down
33 changes: 13 additions & 20 deletions tests/EventsTest.php
Expand Up @@ -10,35 +10,28 @@
use Spiral\Core\Event\InterceptorCalling;
use Spiral\Tests\Console\Fixtures\TestCommand;

final class EventsTest extends BaseTest
final class EventsTest extends BaseTestCase
{
public function testEventsShouldBeDispatched(): void
{
$dispatcher = $this->createMock(EventDispatcherInterface::class);

$dispatcher->expects(self::exactly(3))
->method('dispatch')
->withConsecutive(
[
$this->callback(static fn(mixed $event): bool =>
$event instanceof CommandStarting && $event->command instanceof TestCommand
)
],
[
$this->callback(static fn(mixed $event): bool => $event instanceof InterceptorCalling)
],
[
$this->callback(static fn(mixed $event): bool =>
$event instanceof CommandFinished && $event->command instanceof TestCommand
)
],
);
$dispatcher = \Mockery::mock(EventDispatcherInterface::class);
$dispatcher
->shouldReceive('dispatch')
->with(\Mockery::type(CommandStarting::class));
$dispatcher
->shouldReceive('dispatch')
->with(\Mockery::type(InterceptorCalling::class));
$dispatcher
->shouldReceive('dispatch')
->with(\Mockery::type(CommandFinished::class));

$core = $this->getCore(
locator: $this->getStaticLocator([new TestCommand()]),
eventDispatcher: $dispatcher
);

$core->run('test');

$this->assertTrue(true);
}
}
21 changes: 21 additions & 0 deletions tests/Fixtures/UpdateClass.php
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Spiral\Tests\Console\Fixtures;

use Spiral\Tests\Console\ShortException;
use Symfony\Component\Console\Output\OutputInterface;

final class UpdateClass
{
public function do(OutputInterface $output): void
{
$output->write('OK');
}

public function err(OutputInterface $output): void
{
throw new ShortException('Failed configure command');
}
}
4 changes: 2 additions & 2 deletions tests/HelpersTest.php
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;

class HelpersTest extends BaseTest
class HelpersTest extends BaseTestCase
{
private \Spiral\Console\Console $core;

Expand All @@ -26,7 +26,7 @@ public function testVerbose(): void
$actual = $this->core->run('helper', ['helper' => 'verbose'])
->getOutput()
->fetch();

$this->assertSame('false', $actual);

$output = new BufferedOutput();
Expand Down
2 changes: 1 addition & 1 deletion tests/InterceptorTest.php
Expand Up @@ -11,7 +11,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class InterceptorTest extends BaseTest
final class InterceptorTest extends BaseTestCase
{
use MockeryPHPUnitIntegration;

Expand Down
3 changes: 1 addition & 2 deletions tests/LazyTest.php
Expand Up @@ -4,12 +4,11 @@

namespace Spiral\Tests\Console;

use Spiral\Console\CommandLocator;
use Spiral\Tests\Console\Fixtures\LazyLoadedCommand;
use Spiral\Tokenizer\ScopedClassesInterface;
use Symfony\Component\Console\Command\LazyCommand;

class LazyTest extends BaseTest
class LazyTest extends BaseTestCase
{
public function testLazyCommandCreationInCommandLocator(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/OptionsTest.php
Expand Up @@ -6,7 +6,7 @@

use Spiral\Tests\Console\Fixtures\OptionalCommand;

class OptionsTest extends BaseTest
class OptionsTest extends BaseTestCase
{
public function testOptions(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/PromptArgumentsTest.php
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class PromptArgumentsTest extends BaseTest
final class PromptArgumentsTest extends BaseTestCase
{
public function testCommandArgumentShouldBeSkipped(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/SignatureTest.php
Expand Up @@ -7,7 +7,7 @@
use Spiral\Console\Command;
use Symfony\Component\Console\Input\StringInput;

final class SignatureTest extends BaseTest
final class SignatureTest extends BaseTestCase
{
public function testOptions(): void
{
Expand Down
20 changes: 5 additions & 15 deletions tests/UpdateTest.php
Expand Up @@ -11,10 +11,10 @@
use Spiral\Tests\Console\Fixtures\FailedCommand;
use Spiral\Tests\Console\Fixtures\HelperCommand;
use Spiral\Tests\Console\Fixtures\TestCommand;
use Symfony\Component\Console\Output\OutputInterface;
use Spiral\Tests\Console\Fixtures\UpdateClass;
use Throwable;

class UpdateTest extends BaseTest
class UpdateTest extends BaseTestCase
{
public const TOKENIZER_CONFIG = [
'directories' => [__DIR__.'/../src/Command', __DIR__.'/Fixtures/'],
Expand All @@ -28,10 +28,10 @@ class UpdateTest extends BaseTest
'update' => [
['command' => 'test', 'header' => 'Test Command'],
['command' => 'helper', 'options' => ['helper' => 'writeln'], 'footer' => 'Good!'],
['invoke' => [self::class, 'do']],
['invoke' => self::class.'::do'],
['invoke' => [UpdateClass::class, 'do']],
['invoke' => UpdateClass::class.'::do'],
'Spiral\Tests\Console\ok',
['invoke' => self::class.'::err'],
['invoke' => UpdateClass::class.'::err'],
],
],
];
Expand Down Expand Up @@ -122,16 +122,6 @@ public function testNoBreakFailure(): void
$this->assertEquals(1, $output->getCode());
}

public function do(OutputInterface $output): void
{
$output->write('OK');
}

public function err(OutputInterface $output): void
{
throw new ShortException('Failed update command');
}

/**
* @return Console
*/
Expand Down

0 comments on commit e0341b6

Please sign in to comment.