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 authored Feb 20, 2024
1 parent e1bd657 commit 096913c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/Cases/ElasticsearchEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Hyperf\Database\Model\Model;
use Hyperf\Scout\Builder;
use Hyperf\Scout\Engine\ElasticsearchEngine;
use HyperfTest\Scout\Stub\ContainerStub;
use HyperfTest\Scout\Stub\ElasticsearchEngineTestModel;
use HyperfTest\Scout\Stub\SearchableModel;
use Mockery;
Expand All @@ -28,10 +29,16 @@
#[CoversNothing]
class ElasticsearchEngineTest extends TestCase
{
protected function setUp(): void
{
ContainerStub::mockContainer();
}

protected function tearDown(): void
{
Mockery::close();
$this->assertTrue(true);
ContainerStub::unsetContainer();
}

public function testUpdateAddsObjectsToIndex()
Expand Down
7 changes: 7 additions & 0 deletions tests/Cases/SearchableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
namespace HyperfTest\Scout\Cases;

use HyperfTest\Scout\Stub\ContainerStub;
use HyperfTest\Scout\Stub\ModelStubForMakeAllSearchable;
use HyperfTest\Scout\Stub\SearchableModel;
use Mockery as m;
Expand All @@ -24,10 +25,16 @@
#[CoversNothing]
class SearchableTest extends TestCase
{
protected function setUp(): void
{
ContainerStub::mockContainer();
}

protected function tearDown(): void
{
m::close();
$this->assertTrue(true);
ContainerStub::unsetContainer();
}

public function testSearchableUsingUpdateIsCalledOnCollection()
Expand Down
39 changes: 39 additions & 0 deletions tests/Stub/ContainerStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Scout\Stub;

use Hyperf\Context\ApplicationContext;
use Hyperf\Database\Model\Register;
use Hyperf\Scout\ModelObserver;
use Mockery;
use Psr\Container\ContainerInterface;
use ReflectionClass;

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

public static function mockContainer()
{
$container = Mockery::mock(ContainerInterface::class);
$container->shouldReceive('get')->with(ModelObserver::class)->andReturn(new ModelObserver());

ApplicationContext::setContainer($container);

Register::unsetEventDispatcher();
}
}

0 comments on commit 096913c

Please sign in to comment.