Skip to content

Commit

Permalink
deprecate(testing): TestCase::getContainer(). Please use `Container…
Browse files Browse the repository at this point in the history
…::getInstance()` instead.
  • Loading branch information
LastDragon-ru committed Nov 20, 2023
1 parent c30c27b commit 8ac44f7
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 27 deletions.
5 changes: 3 additions & 2 deletions packages/graphql/src/Printer/PrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Definition\UnionType;
use GraphQL\Type\Schema;
use Illuminate\Container\Container;
use LastDragon_ru\LaraASP\GraphQL\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\GraphQLPrinter\Contracts\Printer;
use LastDragon_ru\LaraASP\GraphQLPrinter\Contracts\Settings;
Expand Down Expand Up @@ -841,8 +842,8 @@ static function (): Node {
private static function getSchemaFactory(): Closure {
return static function (TestCase $test): SplFileInfo {
// Types
$directives = $test->getContainer()->make(DirectiveLocator::class);
$registry = $test->getContainer()->make(TypeRegistry::class);
$directives = Container::getInstance()->make(DirectiveLocator::class);
$registry = Container::getInstance()->make(TypeRegistry::class);
$directive = (new class() extends BaseDirective {
#[Override]
public static function definition(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders;

use Illuminate\Container\Container;
use Illuminate\Database\Query\Builder as QueryBuilder;
use LastDragon_ru\LaraASP\GraphQL\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\Testing\Providers\ArrayDataProvider;
use LastDragon_ru\LaraASP\Testing\Providers\UnknownValue;

Expand All @@ -15,8 +15,8 @@ public function __construct() {
parent::__construct([
'Builder' => [
new UnknownValue(),
static function (TestCase $test): QueryBuilder {
return $test->getContainer()->make('db')->table('test_objects');
static function (): QueryBuilder {
return Container::getInstance()->make('db')->table('test_objects');
},
],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders;

use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Builder as ScoutBuilder;
use LastDragon_ru\LaraASP\GraphQL\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\Testing\Providers\ArrayDataProvider;
use LastDragon_ru\LaraASP\Testing\Providers\UnknownValue;

Expand All @@ -16,8 +16,8 @@ public function __construct() {
parent::__construct([
'Builder' => [
new UnknownValue(),
static function (TestCase $test): ScoutBuilder {
return $test->getContainer()->make(ScoutBuilder::class, [
static function (): ScoutBuilder {
return Container::getInstance()->make(ScoutBuilder::class, [
'query' => '',
'model' => new class() extends Model {
// empty
Expand Down
6 changes: 0 additions & 6 deletions packages/graphql/src/Testing/Package/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LastDragon_ru\LaraASP\GraphQL\Testing\Package;

use GraphQL\Type\Schema;
use Illuminate\Contracts\Container\Container;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Model as EloquentModel;
use Illuminate\Database\Query\Builder as QueryBuilder;
Expand Down Expand Up @@ -69,11 +68,6 @@ protected function getEnvironmentSetUp($app): void {
]);
}

#[Override]
public function getContainer(): Container {
return parent::getContainer();
}

protected function getGraphQLPrinter(Settings $settings = null): Printer {
$settings ??= (new TestSettings())
->setDirectiveDefinitionFilter($this->app->make(LighthouseDirectiveFilter::class));
Expand Down
6 changes: 2 additions & 4 deletions packages/testing/src/Concerns/Override.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace LastDragon_ru\LaraASP\Testing\Concerns;

use Closure;
use Illuminate\Contracts\Container\Container;
use Illuminate\Container\Container;
use Illuminate\Foundation\Testing\TestCase;
use LogicException;
use Mockery;
Expand Down Expand Up @@ -89,14 +89,12 @@ protected function override(string $class, mixed $factory = null): mixed {
return $mock;
});

$this->getContainer()->bind(
Container::getInstance()->bind(
$class,
Closure::fromCallable($this->overrides[$class]),
);

// Return
return $mock;
}

abstract protected function getContainer(): Container;
}
7 changes: 0 additions & 7 deletions packages/testing/src/Package/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

namespace LastDragon_ru\LaraASP\Testing\Package;

use Illuminate\Contracts\Container\Container;
use LastDragon_ru\LaraASP\Testing\Assertions\Assertions;
use LastDragon_ru\LaraASP\Testing\Concerns\Concerns;
use LastDragon_ru\LaraASP\Testing\Utils\WithTempDirectory;
use LastDragon_ru\LaraASP\Testing\Utils\WithTempFile;
use LastDragon_ru\LaraASP\Testing\Utils\WithTestData;
use LastDragon_ru\LaraASP\Testing\Utils\WithTranslations;
use Orchestra\Testbench\TestCase as TestbenchTestCase;
use Override;

/**
* Special test case for packages with application.
Expand All @@ -26,9 +24,4 @@ abstract class TestCase extends TestbenchTestCase {
use WithTempFile;
use WithTempDirectory;
use WithTranslations;

#[Override]
protected function getContainer(): Container {
return $this->app;
}
}
5 changes: 3 additions & 2 deletions packages/testing/src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
use LastDragon_ru\LaraASP\Testing\Assertions\Assertions;
use LastDragon_ru\LaraASP\Testing\Concerns\Concerns;
use LastDragon_ru\LaraASP\Testing\Utils\WithTestData;
use Override;

abstract class TestCase extends BaseTestCase {
use Assertions;
use Concerns;
use WithTestData;

#[Override]
/**
* @deprecated 5.2.0 Please use {@see Container::getInstance()} instead.
*/
protected function getContainer(): Container {
return $this->app;
}
Expand Down

0 comments on commit 8ac44f7

Please sign in to comment.