Skip to content

Commit

Permalink
refactor(testing)!: Removed deprecated `CronableAssertions::assertCro…
Browse files Browse the repository at this point in the history
…nableRegistered()`, `CronableAssertions::setQueueableConfig()`, `CronableAssertions::isCronableRegistered()`.
  • Loading branch information
LastDragon-ru committed Jan 1, 2024
1 parent 5612367 commit 11fe0a0
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LastDragon_ru\LaraASP\Eloquent\Iterators;

use Closure;
use Illuminate\Container\Container;
use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
Expand Down Expand Up @@ -35,7 +36,7 @@ public function testGetIterator(): void {

$spyBefore = Mockery::spy(static fn () => null);
$spyAfter = Mockery::spy(static fn () => null);
$db = $this->app->make(ConnectionResolverInterface::class);
$db = Container::getInstance()->make(ConnectionResolverInterface::class);
$log = $this->getQueryLog($db);
$query = TestObject::query()->orderByDesc('value');
$count = count($log);
Expand Down
3 changes: 2 additions & 1 deletion packages/eloquent/src/Iterators/ChunkedIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LastDragon_ru\LaraASP\Eloquent\Iterators;

use Illuminate\Container\Container;
use Illuminate\Database\ConnectionResolverInterface;
use LastDragon_ru\LaraASP\Eloquent\Testing\Package\Models\TestObject;
use LastDragon_ru\LaraASP\Eloquent\Testing\Package\Models\WithTestObject;
Expand All @@ -28,7 +29,7 @@ public function testGetIterator(): void {

$spyBefore = Mockery::spy(static fn() => null);
$spyAfter = Mockery::spy(static fn() => null);
$db = $this->app->make(ConnectionResolverInterface::class);
$db = Container::getInstance()->make(ConnectionResolverInterface::class);
$log = $this->getQueryLog($db);
$query = TestObject::query()->orderByDesc('value');
$expected = (clone $query)->get()->all();
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/SearchBy/Directives/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ static function (self $test): GraphQLExpected {
));
},
'~custom-complex-operators.graphql',
static function (TestCase $test): void {
$locator = $test->app->make(DirectiveLocator::class);
static function (): void {
$locator = Container::getInstance()->make(DirectiveLocator::class);
$directive = new class() extends BaseOperator implements TypeDefinition {
#[Override]
public static function getName(): string {
Expand Down
2 changes: 2 additions & 0 deletions packages/migrator/src/Commands/RawSeederTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function testHandle(): void {
self::assertCount(0, $finder->files());

// Redefine path where files will be generated.
self::assertNotNull($this->app);

$this->app->useDatabasePath($path);

// Call
Expand Down
12 changes: 9 additions & 3 deletions packages/queue/src/CronableRegistratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use LastDragon_ru\LaraASP\Queue\Configs\CronableConfig;
use LastDragon_ru\LaraASP\Queue\Contracts\Cronable;
use LastDragon_ru\LaraASP\Queue\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\Queue\Testing\Package\WithQueueableConfig;
use LogicException;
use Mockery;
use Mockery\MockInterface;
Expand All @@ -21,6 +22,8 @@
*/
#[CoversClass(CronableRegistrator::class)]
class CronableRegistratorTest extends TestCase {
use WithQueueableConfig;

// <editor-fold desc="Tests">
// =========================================================================
/**
Expand Down Expand Up @@ -75,10 +78,11 @@ public function getQueueConfig(): array {

Queue::fake();

$app = Container::getInstance()->make(Application::class);
$schedule = Container::getInstance()->make(Schedule::class);
$registrator = Container::getInstance()->make(CronableRegistrator::class);

$registrator->register($this->app, $schedule, $cronable::class);
$registrator->register($app, $schedule, $cronable::class);

if ($enabled) {
Queue::assertPushed($cronable::class);
Expand Down Expand Up @@ -133,10 +137,11 @@ public function getQueueConfig(): array {
CronableConfig::Enabled => false,
]);

$app = Container::getInstance()->make(Application::class);
$schedule = Container::getInstance()->make(Schedule::class);
$registrator = Container::getInstance()->make(CronableRegistrator::class);

$registrator->register($this->app, $schedule, $cronable::class);
$registrator->register($app, $schedule, $cronable::class);
}

public function testRegisterCronIsNull(): void {
Expand All @@ -161,10 +166,11 @@ public function getQueueConfig(): array {
CronableConfig::Enabled => true,
]);

$app = Container::getInstance()->make(Application::class);
$schedule = Container::getInstance()->make(Schedule::class);
$registrator = Container::getInstance()->make(CronableRegistrator::class);

$registrator->register($this->app, $schedule, $cronable::class);
$registrator->register($app, $schedule, $cronable::class);
}
// </editor-fold>

Expand Down
3 changes: 3 additions & 0 deletions packages/queue/src/QueueableConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Container\Container;
use LastDragon_ru\LaraASP\Queue\Contracts\ConfigurableQueueable;
use LastDragon_ru\LaraASP\Queue\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\Queue\Testing\Package\WithQueueableConfig;
use Override;
use PHPUnit\Framework\Attributes\CoversClass;

Expand All @@ -16,6 +17,8 @@
*/
#[CoversClass(QueueableConfigurator::class)]
class QueueableConfiguratorTest extends TestCase {
use WithQueueableConfig;

public function testConfigure(): void {
$configurator = Container::getInstance()->make(QueueableConfigurator::class);
$queueable = new QueueableConfiguratorTest_ConfigurableQueueable();
Expand Down
26 changes: 26 additions & 0 deletions packages/queue/src/Testing/Package/WithQueueableConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare(strict_types = 1);

namespace LastDragon_ru\LaraASP\Queue\Testing\Package;

use LastDragon_ru\LaraASP\Core\Utils\ConfigMerger;
use LastDragon_ru\LaraASP\Queue\Contracts\ConfigurableQueueable;

use function config;
use function is_object;
use function sprintf;

trait WithQueueableConfig {
/**
* @param ConfigurableQueueable|class-string<ConfigurableQueueable> $queueable
* @param array<string, mixed> $settings
*/
private function setQueueableConfig(ConfigurableQueueable|string $queueable, array $settings): void {
$key = sprintf('queue.queueables.%s', is_object($queueable) ? $queueable::class : $queueable);
$target = [ConfigMerger::Strict => false] + (array) config($key);
$merger = new ConfigMerger();

config([
$key => $merger->merge($target, $settings),
]);
}
}
4 changes: 3 additions & 1 deletion packages/spa/src/Http/Controllers/SpaControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace LastDragon_ru\LaraASP\Spa\Http\Controllers;

use Illuminate\Container\Container;
use Illuminate\Contracts\Foundation\Application;
use LastDragon_ru\LaraASP\Spa\Package;
use LastDragon_ru\LaraASP\Spa\Provider;
use LastDragon_ru\LaraASP\Spa\Testing\Package\TestCase;
Expand Down Expand Up @@ -145,7 +147,7 @@ protected static function getAcceptDataProvider(): DataProvider {
// <editor-fold desc="Helpers">
// =========================================================================
protected function loadRoutes(): void {
(new class($this->app) extends Provider {
(new class(Container::getInstance()->make(Application::class)) extends Provider {
#[Override]
public function bootRoutes(): void {
parent::bootRoutes();
Expand Down
78 changes: 0 additions & 78 deletions packages/testing/src/Assertions/Application/CronableAssertions.php

This file was deleted.

2 changes: 0 additions & 2 deletions packages/testing/src/Assertions/Assertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

namespace LastDragon_ru\LaraASP\Testing\Assertions;

use LastDragon_ru\LaraASP\Testing\Assertions\Application\CronableAssertions;
use LastDragon_ru\LaraASP\Testing\Assertions\Application\ScheduleAssertions;

trait Assertions {
use XmlAssertions;
use JsonAssertions;
use ScoutAssertions;
use ScheduleAssertions;
use CronableAssertions;
use ResponseAssertions;
use DatabaseAssertions;
}

0 comments on commit 11fe0a0

Please sign in to comment.