Skip to content

Commit

Permalink
Added return type for model ast visitors. (#6544)
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed Feb 20, 2024
1 parent a3ff1e7 commit 3246aca
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Commands/Ast/GenerateModelIDEVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public function enterNode(Node $node)
new Node\Identifier(self::toIDEClass($this->nsp . '\\' . $this->originClassName))
);
}

return null;
}

public function afterTraverse(array $nodes)
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/Ast/ModelRewriteGetterSetterVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function beforeTraverse(array $nodes)
$methods = PhpParser::getInstance()->getAllMethodsFromStmts($nodes);

$this->collectMethods($methods);

return null;
}

public function afterTraverse(array $nodes)
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/Ast/ModelRewriteInheritanceVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,7 @@ public function leaveNode(Node $node)
}
return $node;
}

return null;
}
}
3 changes: 2 additions & 1 deletion src/Commands/Ast/ModelRewriteKeyInfoVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public function afterTraverse(array $nodes)
}
}
}

return null;
}

protected function rewrite(string $property, ?Node\Stmt\Property $node = null): ?Node\Stmt\Property
Expand Down Expand Up @@ -124,7 +126,6 @@ protected function rewrite(string $property, ?Node\Stmt\Property $node = null):

/**
* @param bool|string $value
* @return Node\Scalar
*/
protected function getExpr(string $property, $value): Node\Expr
{
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/Ast/ModelRewriteSoftDeletesVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public function afterTraverse(array $nodes)
}
}
}

return null;
}

protected function rewriteSoftDeletesUse(?Node\Stmt\Use_ $node = null): ?Node\Stmt\Use_
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/Ast/ModelRewriteTimestampsVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public function afterTraverse(array $nodes)
}
}
}

return null;
}

protected function rewriteTimestamps(?Node\Stmt\Property $node = null): ?Node\Stmt\Property
Expand Down
3 changes: 3 additions & 0 deletions tests/DatabaseGenMigrationCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Hyperf\Database\Commands\Migrations\GenMigrateCommand;
use Hyperf\Database\Migrations\MigrationCreator;
use HyperfTest\Database\Stubs\ContainerStub;
use Mockery;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
Expand All @@ -32,6 +33,8 @@ protected function setUp(): void
{
parent::setUp();
! defined('BASE_PATH') && define('BASE_PATH', __DIR__);

ContainerStub::unsetContainer();
}

protected function tearDown(): void
Expand Down
6 changes: 6 additions & 0 deletions tests/DatabaseMigrationCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Hyperf\Database\Migrations\MigrationCreator;
use Hyperf\Support\Filesystem\Filesystem;
use HyperfTest\Database\Stubs\ContainerStub;
use HyperfTest\Database\Stubs\MigrationCreatorFakeMigration;
use InvalidArgumentException;
use Mockery;
Expand All @@ -28,6 +29,11 @@ class DatabaseMigrationCreatorTest extends TestCase
{
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;

protected function setUp(): void
{
ContainerStub::unsetContainer();
}

protected function tearDown(): void
{
Mockery::close();
Expand Down
6 changes: 6 additions & 0 deletions tests/DatabaseMigrationInstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Hyperf\Database\Commands\Migrations\InstallCommand;
use Hyperf\Database\Migrations\MigrationRepositoryInterface;
use HyperfTest\Database\Stubs\ContainerStub;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use PHPUnit\Framework\Attributes\CoversNothing;
Expand All @@ -29,6 +30,11 @@ class DatabaseMigrationInstallCommandTest extends TestCase
{
use MockeryPHPUnitIntegration;

protected function setUp(): void
{
ContainerStub::unsetContainer();
}

protected function tearDown(): void
{
Mockery::close();
Expand Down
3 changes: 3 additions & 0 deletions tests/DatabaseMigrationMigrateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Hyperf\Database\Commands\Migrations\MigrateCommand;
use Hyperf\Database\Migrations\Migrator;
use HyperfTest\Database\Stubs\ContainerStub;
use Mockery;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
Expand All @@ -33,6 +34,8 @@ protected function setUp(): void
{
parent::setUp();
! defined('BASE_PATH') && define('BASE_PATH', __DIR__);

ContainerStub::unsetContainer();
}

protected function tearDown(): void
Expand Down
6 changes: 6 additions & 0 deletions tests/DatabaseMigrationRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Hyperf\Database\Migrations\DatabaseMigrationRepository;
use Hyperf\Database\Query\Builder;
use Hyperf\Database\Schema\Builder as SchemaBuilder;
use HyperfTest\Database\Stubs\ContainerStub;
use Mockery;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
Expand All @@ -31,6 +32,11 @@ class DatabaseMigrationRepositoryTest extends TestCase
{
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;

protected function setUp(): void
{
ContainerStub::unsetContainer();
}

protected function tearDown(): void
{
Mockery::close();
Expand Down
3 changes: 3 additions & 0 deletions tests/DatabaseMigrationResetCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Hyperf\Database\Commands\Migrations\ResetCommand;
use Hyperf\Database\Migrations\Migrator;
use HyperfTest\Database\Stubs\ContainerStub;
use Mockery;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
Expand All @@ -32,6 +33,8 @@ protected function setUp(): void
{
parent::setUp();
! defined('BASE_PATH') && define('BASE_PATH', __DIR__);

ContainerStub::unsetContainer();
}

protected function tearDown(): void
Expand Down
3 changes: 3 additions & 0 deletions tests/DatabaseMigrationRollbackCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Hyperf\Database\Commands\Migrations\RollbackCommand;
use Hyperf\Database\Migrations\Migrator;
use HyperfTest\Database\Stubs\ContainerStub;
use Mockery;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
Expand All @@ -32,6 +33,8 @@ protected function setUp(): void
{
parent::setUp();
! defined('BASE_PATH') && define('BASE_PATH', __DIR__);

ContainerStub::unsetContainer();
}

protected function tearDown(): void
Expand Down
10 changes: 6 additions & 4 deletions tests/DatabaseModelCustomCastingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Hyperf\Database\Exception\InvalidCastException;
use Hyperf\Database\Model\CastsValue;
use Hyperf\Database\Model\Model;
use HyperfTest\Database\Stubs\ContainerStub;
use Mockery;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
Expand All @@ -29,12 +30,13 @@
* @coversNothing
*/
#[CoversNothing]
/**
* @internal
* @coversNothing
*/
class DatabaseModelCustomCastingTest extends TestCase
{
protected function setUp(): void
{
ContainerStub::unsetContainer();
}

protected function tearDown(): void
{
Mockery::close();
Expand Down
6 changes: 6 additions & 0 deletions tests/DatabaseMySqlQueryGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Hyperf\Database\Connection;
use Hyperf\Database\Query\Grammars\MySqlGrammar;
use HyperfTest\Database\Stubs\ContainerStub;
use Mockery as m;
use PHPUnit\Framework\TestCase;

Expand All @@ -22,6 +23,11 @@
*/
class DatabaseMySqlQueryGrammarTest extends TestCase
{
protected function setUp(): void
{
ContainerStub::unsetContainer();
}

protected function tearDown(): void
{
m::close();
Expand Down
8 changes: 8 additions & 0 deletions tests/Stubs/ContainerStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Hyperf\Database\Connectors\MySqlConnector;
use Hyperf\Di\Container;
use Mockery;
use ReflectionClass;

class ContainerStub
{
Expand Down Expand Up @@ -67,4 +68,11 @@ public static function getModelOption()
->setWithIde(false);
return $option;
}

public static function unsetContainer()
{
$ref = new ReflectionClass(ApplicationContext::class);
$c = $ref->getProperty('container');
$c->setValue(null);
}
}

0 comments on commit 3246aca

Please sign in to comment.